Presentation is loading. Please wait.

Presentation is loading. Please wait.

Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.

Similar presentations


Presentation on theme: "Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006."— Presentation transcript:

1 Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006

2 Lecture 8© CIS 4301 - Spring 20062 Definition Functional Dependency (FD) Formally: A 1, A 2, …, A n  B (commas usually omitted) Read: “A 1, A 2, …, A n functionally determine B” If two tuples of r(R) agree on attributes A 1, A 2, …, A n of R, then they must also agree in another attribute B i.e., the tuples have the same values in their respective components for each of these attributes Also, if A 1 A 2 … A n  B 1 A 1 A 2 … A n  B 2 …… A 1 A 2 … A n  B m then A 1 A 2 … A n  B 1 B 2 … B m

3 Lecture 8© CIS 4301 - Spring 20063 Rules About Functional Dependencies Let F be set of FDs specified on R Must be able to reason about FD’s in F Designer usually explicitly states only FD’s which are obvious Without knowing exactly what all tuples are, must be able to deduce other/all FD’s that hold on R Essential when we discuss design of “good” relational schemas

4 Lecture 8© CIS 4301 - Spring 20064 Example Relation R with attributes A, B, C Assume R satisfies FD’s A  B and B  C How can we deduce that A  C? Use definition, namely show that if two random tuples agree on A they must also agree on C

5 Lecture 8© CIS 4301 - Spring 20065 More Definitions Two sets of FD’s S and T are equivalent if the set of relation instances satisfying S is exactly the same as the set satisfying T More general: set of FD’s S follows from set of FD’s T if every relation instance satisfying all FD’s in T also satisfies all the FD’s in S S equivalent to T iff S follows from T and T follows from S

6 Lecture 8© CIS 4301 - Spring 20066 Trivial Dependencies A functional dependency A 1 A 2 …A n  B is said to be trivial if B is one of the A’s Ex.: title year  title Every trivial dependency holds in every relation i.e., tuples that agree in all of A 1,A 2, …, A n agree in one of them We may assume trivial dependencies without having to justify them trivial: B’s subset of A’s nontrivial: at least one of the B’s not among A’s completely nontrivial: none of the B’s part of A’s

7 Lecture 8© CIS 4301 - Spring 20067 Rules About Functional Dependencies SPLITTING RULE: If AA  B 1, B 2,..., B n then AA  B 1, AA  B 2,..., AA  B n Q: Can we also split the left-hand side? COMBINING RULE: If AA  B 1, AA  B 2,..., AA  B n then AA  B 1, B 2,..., B n TRIVIAL DEPENDENCY RULES: If AA  BB then AA  (BB - AA) If AA  BB then AA  (BB  AA) TRANSITIVE RULE: If AA  BB and BB  CC then AA  CC

8 Lecture 8© CIS 4301 - Spring 20068 Example: Transitivity Rule R(A,B,C) F: A  B, B  C Show A  C holds? Show that two tuples in r(R) that agree on A also agree on C Step 1: t=(a,b 1,c 1 ), u=(a,b 2,c 2 ) Step 2: Since A  B, and tuples agree on A, they must also agree on B  b 1 = b 2  t = (a,b,c 1 ), u = (a,b,c 2 )

9 Lecture 8© CIS 4301 - Spring 20069 Example Cont’d Step 3: Since B  C and tuples agree on B, must also agree on C  c 1 = c 2  t = (a,b,c), u = (a,b,c) Step 4:  tuples that agree on A also agree on C  A  C

10 Lecture 8© CIS 4301 - Spring 200610 Closure of Attributes General principle from which all rules follow Given a relation R, a set of FD's for R, and a set of attributes {A 1, A 2,..., A m } of R: Find all attributes B such that A 1, A 2,..., A m  B follows from the FD’s of R This set of attributes is called the "closure" and is denoted {A 1, A 2,..., A m } +

11 Lecture 8© CIS 4301 - Spring 200611 Algorithm for Computing Closure Start with {A1, A2,..., Am} repeat until no change: if current set of attributes includes LHS of a dependency, add RHS attributes to the set ** Effectively applies combining and transitive rules until there's no more change

12 Lecture 8© CIS 4301 - Spring 200612 Calculating the Closure R=(A,B,C,D,E,F) F: AB  C, BC  AD, D  E, CE  B How to compute closure of {A,B}, i.e., {A,B} + ? 1. Start with X={A,B} 2. Add C to X due to AB  C; X={A,B,C} 3. Add A,D to X due to BC  AD; X={A,B,C,D} 4. Add E to X due to D  E; X={A,B,C,D,E} 5. No more attributes can be added to X 6. {A,B} + = {A,B,C,D,E}

13 Lecture 8© CIS 4301 - Spring 200613 So What! If we can compute closure of any set of attributes, we can test whether any given functional dependency A 1 A 2 …A n  B follows from set of dependencies F Compute closure of {A 1, A 2, …, A n } + using F If B is in {A 1, A 2, …, A n } +, then A 1 A 2 …A n  B does follow from F ALSO: We can test if K={A 1,A 2,…,A n } is a key for relation R if {A 1,A 2,…,A n } + is the set of all attributes in R and if K is minimal

14 Lecture 8© CIS 4301 - Spring 200614 Closing Sets of FD's Let F be set of FDs specified on R Must be able to reason about FD’s in F Designer usually explicitly states only FD’s which are obvious (given FD’s) Without knowing exactly what all tuples are, must be able to deduce other FD’s that hold on R (derived FD’s) Essential when we discuss design of “good” relational schemas Any set of FD’s from which we can infer full set of FD’s for relation is called basis for that relation Minimal basis

15 Lecture 8© CIS 4301 - Spring 200615 Exercise Consider a relation with schema R(A, B,C, D) and functional dependencies F: AB  C, C  D, and D  A. a) What are all the non-trivial FD’s that follow from the given dependencies? b) What are the keys of R? c) What are all the superkeys for R that are not keys?

16 Lecture 8© CIS 4301 - Spring 200616 Projecting Functional Dependencies Given relation R and set of FD’s F that hold on R Suppose we have new relation S that has subset of attributes of relation R What FD’s hold on S? Compute all FD’s that follow from F AND involve only attributes of S Use closure of all subsets of attributes in S Can use some observations: Closing empty set and complete set will no yield a nontrivial FD If we know the closure of some set X is all attributes, then closing supersets of X will not yield any new FD’s

17 Lecture 8© CIS 4301 - Spring 200617 Set of Inference Rules Reflexive rule Augmentation rule Transitivity rule Decomposition rule Union rule Pseudotransitive rule Armstrong’s axioms: sound and complete

18 Lecture 8© CIS 4301 - Spring 200618 Final Thought How can we tell if one FD follows from others? Use Armstrong’s axioms and reason it out, OR Attribute closure algorithm always works


Download ppt "Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006."

Similar presentations


Ads by Google