Background: Functional Dependencies. æ We are always talking about a relation R, with a æxed schema èset of attributesè and a

Similar documents
Schema Refinement: Other Dependencies and Higher Normal Forms

Relational Database Design

UVA UVA UVA UVA. Database Design. Relational Database Design. Functional Dependency. Loss of Information

CS54100: Database Systems

Schema Refinement and Normal Forms

Schema Refinement and Normal Forms. Why schema refinement?

Constraints: Functional Dependencies

Design theory for relational databases

INF1383 -Bancos de Dados

Relational-Database Design

Information Systems for Engineers. Exercise 8. ETH Zurich, Fall Semester Hand-out Due

Design Theory for Relational Databases

Chapter 3 Design Theory for Relational Databases

SCHEMA NORMALIZATION. CS 564- Fall 2015

Introduction. Normalization. Example. Redundancy. What problems are caused by redundancy? What are functional dependencies?

Functional Dependency and Algorithmic Decomposition

COSC 430 Advanced Database Topics. Lecture 2: Relational Theory Haibo Zhang Computer Science, University of Otago

Review: Keys. What is a Functional Dependency? Why use Functional Dependencies? Functional Dependency Properties

Schema Refinement & Normalization Theory

Schema Refinement and Normal Forms Chapter 19

Functional Dependencies & Normalization. Dr. Bassam Hammo

Schema Refinement and Normal Forms. The Evils of Redundancy. Schema Refinement. Yanlei Diao UMass Amherst April 10, 2007

Functional Dependencies. Applied Databases. Not all designs are equally good! An example of the bad design

Constraints: Functional Dependencies

Chapter 3 Design Theory for Relational Databases

Problem about anomalies

Schema Refinement. Feb 4, 2010

Schema Refinement and Normal Forms

Relational Design: Characteristics of Well-designed DB

The Evils of Redundancy. Schema Refinement and Normalization. Functional Dependencies (FDs) Example: Constraints on Entity Set. Refining an ER Diagram

Schema Refinement and Normal Forms. Chapter 19

Plan of the lecture. G53RDB: Theory of Relational Databases Lecture 10. Logical consequence (implication) Implication problem for fds

Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) [R&G] Chapter 19

The Evils of Redundancy. Schema Refinement and Normal Forms. Functional Dependencies (FDs) Example: Constraints on Entity Set. Example (Contd.

CSE 132B Database Systems Applications

Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) CIS 330, Spring 2004 Lecture 11 March 2, 2004

The Evils of Redundancy. Schema Refinement and Normal Forms. Example: Constraints on Entity Set. Functional Dependencies (FDs) Example (Contd.

The Evils of Redundancy. Schema Refinement and Normal Forms. Example: Constraints on Entity Set. Functional Dependencies (FDs) Refining an ER Diagram

FUNCTIONAL DEPENDENCY THEORY. CS121: Relational Databases Fall 2017 Lecture 19

Normalization. October 5, Chapter 19. CS445 Pacific University 1 10/05/17

Design Theory for Relational Databases

Normaliza)on and Func)onal Dependencies

Schema Refinement and Normal Forms

Lossless Joins, Third Normal Form

Schema Refinement and Normalization

Normal Forms. Dr Paolo Guagliardo. University of Edinburgh. Fall 2016

Schema Refinement and Normal Forms. Case Study: The Internet Shop. Redundant Storage! Yanlei Diao UMass Amherst November 1 & 6, 2007

CSC 261/461 Database Systems Lecture 13. Spring 2018

CSIT5300: Advanced Database Systems

CSC 261/461 Database Systems Lecture 11

Normal Forms (ii) ICS 321 Fall Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

Relational Design Theory

Functional Dependencies. Getting a good DB design Lisa Ball November 2012

Chapter 11, Relational Database Design Algorithms and Further Dependencies

Schema Refinement and Normal Forms

Schema Refinement & Normalization Theory: Functional Dependencies INFS-614 INFS614, GMU 1

Information Systems (Informationssysteme)

DESIGN THEORY FOR RELATIONAL DATABASES. csc343, Introduction to Databases Renée J. Miller and Fatemeh Nargesian and Sina Meraji Winter 2018

Lectures 6. Lecture 6: Design Theory

CAS CS 460/660 Introduction to Database Systems. Functional Dependencies and Normal Forms 1.1

10/12/10. Outline. Schema Refinements = Normal Forms. First Normal Form (1NF) Data Anomalies. Relational Schema Design

Database Design and Implementation

CSC 261/461 Database Systems Lecture 10 (part 2) Spring 2018

LOGICAL DATABASE DESIGN Part #1/2

CS 186, Fall 2002, Lecture 6 R&G Chapter 15

CSC 261/461 Database Systems Lecture 12. Spring 2018

Normal Forms Lossless Join.

Data Bases Data Mining Foundations of databases: from functional dependencies to normal forms

Design Theory: Functional Dependencies and Normal Forms, Part I Instructor: Shel Finkelstein

Introduction to Data Management. Lecture #6 (Relational DB Design Theory)

Functional Dependencies and Normalization

Consider a relation R with attributes ABCDEF GH and functional dependencies S:

Functional Dependencies

Introduction to Data Management. Lecture #6 (Relational Design Theory)

Functional Dependencies

Schema Refinement. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

Chapter 10. Normalization Ext (from E&N and my editing)

Databases 2012 Normalization

Relational Database Design Theory Part II. Announcements (October 12) Review. CPS 116 Introduction to Database Systems

Design Theory for Relational Databases. Spring 2011 Instructor: Hassan Khosravi

Chapter 8: Relational Database Design

Database Design and Normalization

DECOMPOSITION & SCHEMA NORMALIZATION

12/3/2010 REVIEW ALGEBRA. Exam Su 3:30PM - 6:30PM 2010/12/12 Room C9000

Relational Database Design

CS322: Database Systems Normalization

Lecture 6 Relational Database Design

Chapter 7: Relational Database Design

A few details using Armstrong s axioms. Supplement to Normalization Lecture Lois Delcambre

Consider a relation R with attributes ABCDEF GH and functional dependencies S:

Chapter 7: Relational Database Design. Chapter 7: Relational Database Design

Functional Dependencies

Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

11/1/12. Relational Schema Design. Relational Schema Design. Relational Schema Design. Relational Schema Design (or Logical Design)

Kapitel 3: Formal Design

CSC 261/461 Database Systems Lecture 8. Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101

CSE 344 AUGUST 6 TH LOSS AND VIEWS

CS122A: Introduction to Data Management. Lecture #13: Relational DB Design Theory (II) Instructor: Chen Li

Functional Dependencies and Normalization. Instructor: Mohamed Eltabakh

Shuigeng Zhou. April 6/13, 2016 School of Computer Science Fudan University

Transcription:

Background: Functional Dependencies We are always talking about a relation R, with a xed schema èset of attributesè and a varying instance èset of tuplesè. Conventions: A;B;:::are attributes; :::;Y;Z are sets of attributes. Concatenation means union. FD is X! Y, where X and Y are sets of attributes. Two tuples that agree in all attributes of X must agree in all attributes of Y. Implication: FD X! Y follows from F i all relation instances that satisfy F also satisfy X! Y. Three Ways to Reason About FD's 1. Semantic: FD X! Y is the set of relation instances that satisfy it. Say F j= X! Y if every instance that satises all FD's in F also satisfy X! Y. All approaches assume there is a xed relation scheme R to which the FD's pertain. 2. Algorithmic: Give an algorithm that tells us, given F and X! Y, whether Fj= X! Y. 3. Logical: Give a reasoning system that lets us deduce an FD like X! Y exactly when Fj= X! Y. Deduction indicated by F`X! Y. Closure Test for Implication èalgorithmic Approachè Start with X + = X. Adjoin V to X + if U! V is in F, and U ç X +.At end, test if Y ç X +. Proof that if Y ç X +, then F j= X! Y : Easy induction on the number of additions to X + that X! A for all A in X +. Proof that if F implies X! Y, then Y ç X + : Prove the contrapositive; assume Y is not a subset of X + and prove F does not imply X! Y. Construct relation R with two tuples that agree on X + and disagree elsewhere. 1

Armstrong's Axioms èlogical Approachè A sound èwhat may be deduced is correct in the j= senseè and complete èwhat is true in the j= sense can be deducedè axiomatization of FD's. A1: Trivial FD's or Reexivity. X! Y always holds if Y ç X. A2: Augmentation. If X! Y, then XZ! YZ for any set of attributes Z. A3: Transitivity. If X! Y and Y! Z, then X! Z. Deductive Proofs A series of ëlines." Each line is either: 1. A given statement èfd in the given set F for deductions about FD'sè, or 2. A statement that follows from previous lines by applying an axiom. Example Given fab! C; CD! Eg, deduce ABD! E. AB! C ègivenè ABD! CD èa2è CD! E ègivenè ABD! E èa3è Proof of Soundness Easy observations about relations. Proof of Completeness 1. Given F, show that if A is in X +, then X! A follows from F by AA's. 2. Show that if X! A 1 ;:::;X! A n follow from AA's, then so does X! A 1 A n. 3. Complete the proof by observing that X! A 1 A n follows from F i all of A 1 ;:::;A n are in X +, and therefore i X! A 1 A n follows by AA's. Proof è2è Induction on i that X! A 1 A i follows. Basis: i = 1, given. 2

Induction: Assume X! A 1 A i,1. X! XA 1 A i,1 èa2 by X applied to X! A 1 A i,1 è. XA 1 A i,1! A i èa2 by A 1 A i,1 applied to X! A i è. X! A 1 A i èa3 applied to previous two FD'sè. Proof è1è Induction on the number of steps used to add A to X +. Basis: 0 steps. Then A is in X, and X! A by A1. Induction: Assume B 1 B k! A in F used to add A to X +. By the inductive hypothesis, X! B j follows from F for all 1 ç j ç k. By part è2è of the theorem, X! B 1 B k follows from F. By A3, X! A follows. Background: Normal Forms A key for R is a minimal set of attributes such that X! R ènote: I use R as both the instance and schema of a relation shame on meè. A superkey is any superset of a key. BCNF: If X! Y holds for R and is nontrivial, then X is a superkey. 3NF: If X! Y holds for R and is nontrivial, then either X is a superkey or Y contains a prime attribute èmember of some keyè. Decomposition: We can decompose R into schemas S 1 ;:::;S n if S 1 ë ë S n = R. The instance for S i is ç Si èrè. The FD's that hold for S i are those X! Y such that XY ç S i and X! Y follows from the given FD's for R. Covers of Sets of FD's Sets F 1 and F 2 of FD's are equivalent if each implies the other. I.e., exactly the same relation instances satisfy each. 3

Any set of FD's equivalent tof is a cover for F. A cover is minimal if: 1. No right side has more than one attribute. 2. We cannot delete any FD from the cover and have an equivalent set of FD's. 3. We cannot delete any attribute from any left side and have an equivalent set of FD's. Example Relation CTHRSG represents courses, teachers, hours, rooms, students, and grades. The FD's: C! T ; HR! C; HT! R; HS! R; CS! G; CH! R. We can eliminate CH! R. Proof: Using the other 5 FD's, CH + = CHTR. Having done so, we cannot eliminate any attribute from any left side. Sample proof: Suppose we tried to eliminate T from HT! R. We would need that C! T, HT! R, HR! C, HS! R, and CS! G imply H! R. But H + = H with respect to these 5 FD's. Thus the remaining ve are a minimal cover of the original six. Note: minimal cover need not be unique, or even have the same number of FD's. Lossless Join The decomposition of R into S 1 ;:::;S n has a lossless join èwith respect to some constraints on Rè if for any instance r of R that satises the constraints: ç S1 èrè.è.è ç Sn èrè =r Motivation: We can replace R by S and T, knowing that the instance of R can be recovered from the instances of S and T. Theorem A decomposition of R into S and T has a lossless join wrt FD's F if and only if S ë T! S or S ë T! T. 4

Proof First note that r ç ç S èrè.è ç T èrè always. Assume S ë T! S and show that ç S èrè.è ç T èrè ç r Suppose s is in ç S èrè and t is in ç T èrè, and s and t join èi.e., they agree in S ë T è. Then t is the projection of a tuple t 0 of r that agrees with s on S. So t 0 agrees with t on T and with s on S, so t 0 is s.èt; i.e., s.ètis in r. Similarly if S ë T! T. Now assume neither FD follows from F. Then there is an instance r consisting of two tuples that agree on ès ë T è + and disagree elsewhere. This instance satises F. Neither S nor T is contained in ès ë T è + èor else one of the FD's in question would followè. Thus, r projected and rejoined yields four distinct tuples, and cannot be r. Theorem We can always decompose a relation R with FD's F into BCNF relations with a lossless join. Proof We decompose when we nd a BCNF violation X! Y,into X ë Y and èr, Y è ë X. But, èr, Y è ë X ë èx ë Y è= X. Thus the intersection of the schemas functionally determines one of them, X ë Y. To complete the proof, we need to show that when we decompose further, the resulting n relations have a lossless join, but that is an easy induction on n. 5

Dependency Preservation When we decompose R with FD's F, will F be equivalent to the union of its projections onto the decomposed relations? One way to guarantee dependency preservation is to use a minimal cover, and convert each FD in the cover X! A into the schema XA. Theorem But if there are some attributes not mentioned in any FD, make them a schema by themselves. A minimal cover F yields 3NF relations. Proof Suppose XA èthe relation from X! Aè is not in 3NF, because Y! B is a 3NF violation. We know Y is not a superkey, and B is not prime. Case 1: A = B. Then Y ç X. Since Y! B follows from F, and X! A surely follows from Y! B, we know F is equivalent to F,fX! Ag ëfy! Bg. Then F was not a minimal cover. Case 2: A 6= B. Then B is in X. X is surely a superkey for XA, and since B is not prime, B must not be in any key Z ç X. Then èx, Bè! A can replace X! A in F, showing F is again not minimal. Decomposition With 3NF, Dependency Preservation and Lossless Join To the schema from a minimal cover, add a key for the original relation if there is not already some relation schema that is a superkey. Example R = ABCD; F = fa! B; C! Dg. Start with AB and CD from the FD's. Only key for R is AC. Thus, DP, LJ, 3NF decomposition is fab; AC; CDg. 6

Proof that the decomposition is always LJ will have to wait for the theory of ëgeneralized dependencies." This decomposition is obviously LJ, since AB.è ACis lossless because A! B, and then ABC.è CDis lossless because of C! D. 7