Presentation is loading. Please wait.

Presentation is loading. Please wait.

Multivalued Dependencies and 4th NF CIS 4301 Lecture Notes Lecture 12 - 2/21/2006.

Similar presentations


Presentation on theme: "Multivalued Dependencies and 4th NF CIS 4301 Lecture Notes Lecture 12 - 2/21/2006."— Presentation transcript:

1 Multivalued Dependencies and 4th NF CIS 4301 Lecture Notes Lecture 12 - 2/21/2006

2 Lecture 11© CIS 4301 - Spring 20062 Multivalued Dependencies There are schemas that are in BCNF that do not seem to be sufficiently normalized namestreet Stars citytitleyear C. Fisher 123 Maple Str. 5 Locust Ln. 123 Maple Str. 5 Locust Ln. 123 Maple Str. 5 Locust Ln.C. Fisher Hollywood Malibu Hollywood Malibu Hollywood Malibu Star Wars1977 Star Wars1977 Empire Strikes Back1980 Empire Strikes Back1980 Return of the Jedi1983 Return of the Jedi1983

3 Lecture 11© CIS 4301 - Spring 20063 Attribute Independence No reason to associate address with one movie and not another When we repeat address and movie facts in all combinations, there is obvious redundancy However, NO BCNF violation in Stars relation There are no non-trivial FD’s at all, all five attributes form the only superkey Why?

4 Lecture 11© CIS 4301 - Spring 20064 Definition Definition: Multivalued dependency (MVD): A 1 A 2 …A n  B 1 B 2 …B m holds for relation R if: For all tuples t, u in R If t[A 1 A 2...A n ] = u[A 1 A 2...A n ], then there exists a v in R such that: (1) v[A 1 A 2...A n ] = t[A 1 A 2...A n ] = u[A 1 A 2...A n ] (2) v[B 1 B 2 …B m ] = t[B 1 B 2 …B m ] (3) v[C 1 C 2 …C k ] = u[C 1 C 2 …C k ], where C 1 C 2 …C k is all attributes in R except (A 1 A 2...A n  B 1 B 2 …B m )

5 Lecture 11© CIS 4301 - Spring 20065 Pictorially Speaking... An MVD guarantees v exists The existence of a fourth tuple w is implied by interchanging t and u t u A’sB’sOthers v w

6 Lecture 11© CIS 4301 - Spring 20066 Example: name  street city namestreet Stars citytitleyear C. Fisher 123 Maple Str. 5 Locust Ln. Hollywood Malibu Star Wars1977 Empire Strikes Back1980 Empire Strikes Back1980 C. Fisher 5 Locust Ln. 123 Maple Str. 5 Locust Ln.C. Fisher Malibu Hollywood Malibu Star Wars1977 Return of the Jedi1983 Return of the Jedi1983 t u v

7 Lecture 11© CIS 4301 - Spring 20067 Example: name  street city namestreet Stars citytitleyear C. Fisher 123 Maple Str. 5 Locust Ln. 123 Maple Str. 5 Locust Ln. Hollywood Malibu Hollywood Malibu Star Wars1977 Star Wars1977 Empire Strikes Back1980 Empire Strikes Back1980 C. Fisher123 Maple Str. 5 Locust Ln.C. Fisher Hollywood Malibu Return of the Jedi1983 Return of the Jedi1983 u t w v

8 Lecture 11© CIS 4301 - Spring 20068 More on MVDs Intuitively, A 1 A 2 …A n  B 1 B 2 …B m says that the relationship between A 1 A 2 …A n and B 1 B 2 …B m is independent of the relationship between A 1 A 2 …A n and R -{B 1 B 2 …B m } MVD's uncover situations where independent facts related to a certain object are being squished together in one relation Functional dependencies rule out certain tuples from being in a relation How? Multivalued dependencies require that other tuples of a certain form be present in the relation a.k.a. tuple-generating dependencies

9 Lecture 11© CIS 4301 - Spring 20069 Let’s Illustrate In Stars, we must repeat the movie (title, year) once for each address (street, city) a movie star has Alternatively, we must repeat the address for each movie a star has made Example: Stars with name  street city namestreetcitytitleyear C. Fisher 123 Maple Str. 5 Locust Ln. 123 Maple Str. Hollywood Malibu Hollywood Star Wars1977 Empire Strikes Back1980 Return of the Jedi1983 Is an incomplete extent of Stars Infer the existence of a fourth tuple under the given MVD

10 Lecture 11© CIS 4301 - Spring 200610 Trivial MVDs Trivial MVD A 1 A 2 …A n  B 1 B 2 …B m where B 1 B 2 …B m is a subset of A 1 A 2 …A n or (A 1 A 2 …A n  B 1 B 2 …B m ) contains all attributes of R

11 Lecture 11© CIS 4301 - Spring 200611 Reasoning About MVDs FD-IS-AN-MVD Rule If A 1 A 2 …A n  B 1 B 2 …B m then A 1 A 2 …A n  B 1 B 2 …B m holds Prove by showing (1), (2), (3) in MVD definition Let A 1 A 2 …A n  B 1 B 2 …B m hold on R. Suppose t, u are tuples of R that agree on A 1 A 2 …A n. Need to show that R also contains tuple v that agrees with t and u on A’s, with t on B’s, and with u on all other attributes. Let v be u. 

12 Lecture 11© CIS 4301 - Spring 200612 Reasoning About MVDs TRANSITIVE Rule If A 1 A 2 …A n  B 1 B 2 …B m and B 1 B 2 …B m  C 1 C 2 …C k then A 1 A 2 …A n  C 1 C 2 …C k COMPLEMENTATION Rule If A 1 A 2 …A n  B 1 B 2 …B m then A 1 A 2 …A n  C 1 C 2 …C k where C 1 C 2 …C k is all attributes in R except (A 1 A 2 …A n  B 1 B 2 …B m ) UNION Rule If X 1 X 2 …X n  Y 1 Y 2 …Y m and X 1 X 2 …X n  Z 1 Z 2 …Z k then X 1 X 2 …X n  (Y 1 Y 2 …Y m  Z 1 Z 2 …Z k )

13 Lecture 11© CIS 4301 - Spring 200613 Definition 4NF Given: relation R and set of MVD's for R Definition: R is in 4NF with respect to its MVD's if for every non-trivial MVD A 1 A 2 …A n  B 1 B 2 …B m, A 1 A 2 …A n is a superkey Note: Since every FD is also an MVD, 4NF implies BCNF Example: Stars is not in 4NF

14 Lecture 11© CIS 4301 - Spring 200614 Decomposition Algorithm (1) apply closure to the user-specified FD's and MVD's**: (2) repeat until no more 4NF violations: if R with AA ->> BB violates 4NF then: (2a) decompose R into R1(AA,BB) and R2(AA,CC), where CC is all attributes in R except (AA  BB) (2b) assign FD's and MVD's to the new relations** ** MVD's: hard problem! No simple test analogous to computing closure for FD’s Fortunately, can get by using transitive rule, complementation rule, intersection rule, and union rule

15 Lecture 11© CIS 4301 - Spring 200615 Exercise Decompose Stars into a set of relations that are in 4NF. name  street city is a 4NF violation Apply decomposition: R(name, street, city) S( name, title, year) What about name  street city in R and name  title year in S ?

16 Lecture 11© CIS 4301 - Spring 200616 Exercise For the relation R(A,B,C,D) with only MVD’s A  B and A  C find all 4NF violations and decompose R into a collection of relation schemas in 4NF.

17 Lecture 11© CIS 4301 - Spring 200617 Solution Since there are no functional dependencies, the only key is all four attributes, ABCD. Thus, each of the nontrivial multivalued dependencies A->->B and A->->C violate 4NF. Separate out the attributes of these dependencies, first decomposing into AB and ACD Then decompose the latter into AC and AD because A->->C is still a 4NF violation for ACD. The final set of relations are AB, AC, and AD.

18 Lecture 11© CIS 4301 - Spring 200618 Exercise Suppose we have relation R(A,B,C) with MVD A  B. If we know that the tuples (a,b 1,c 1 ), (a,b 2,c 2 ), and (a,b 3,c 3 ) are in the current instance of R, what other tuples do we know must also be in R?

19 Lecture 11© CIS 4301 - Spring 200619 Solution Since A->->B, and all the tuples have the same value for attribute A, we can pair the B-value from any tuple with the value of the remaining attribute C from any other tuple. Thus, we know that R must have at least the nine tuples of the form (a,b,c), where b is any of b1, b2, or b3, and c is any of c1, c2, or c3. That is, we can derive, using the definition of a multivalued dependency, that each of the tuples (a,b1,c2), (a,b1,c3), (a,b2,c1), (a,b2,c3), (a,b3,c1), and (a,b3,c2) are also in R.

20 Lecture 11© CIS 4301 - Spring 200620 Relationships Among Normal Forms Relations in BCNF Relations in 3NF Relations in 4NF


Download ppt "Multivalued Dependencies and 4th NF CIS 4301 Lecture Notes Lecture 12 - 2/21/2006."

Similar presentations


Ads by Google