Presentation is loading. Please wait.

Presentation is loading. Please wait.

Multivalued Dependencies By David Wortham. Problem Introduction Assume a relation R (from the book): (credit Ullman and Widom) Assume a relation R (from.

Similar presentations


Presentation on theme: "Multivalued Dependencies By David Wortham. Problem Introduction Assume a relation R (from the book): (credit Ullman and Widom) Assume a relation R (from."— Presentation transcript:

1 Multivalued Dependencies By David Wortham

2 Problem Introduction Assume a relation R (from the book): (credit Ullman and Widom) Assume a relation R (from the book): (credit Ullman and Widom) NameAddrStreetAddrCityFilmNameFilmYear C. Fisher 123 Maple Dr. Hollywood Star Wars 1977 C. Fisher 5 Locust Ln. Malibu Star Wars 1977 C. Fisher 123 Maple Dr. Hollywood The Empire Strikes Back 1980 C. Fisher 5 Locust Ln. Malibu The Empire Strikes Back 1980 C. Fisher 123 Maple Dr. Hollywood Return of the Jedi 1983 C. Fisher 5 Locust Ln. Malibu Return of the Jedi 1983 Carrie Fisher = Princess Leia Organa

3 Problem Introduction What is the highest Normal Form R complies with? What is the highest Normal Form R complies with? NameAddrStreetAddrCityFilmNameFilmYear C. Fisher 123 Maple Dr. Hollywood Star Wars 1977 C. Fisher 5 Locust Ln. Malibu Star Wars 1977 C. Fisher 123 Maple Dr. Hollywood The Empire Strikes Back 1980 C. Fisher 5 Locust Ln. Malibu The Empire Strikes Back 1980 C. Fisher 123 Maple Dr. Hollywood Return of the Jedi 1983 C. Fisher 5 Locust Ln. Malibu Return of the Jedi 1983

4 Recall 1NF 1NF eliminates wasted space due to duplicate attributes (columns) 1NF eliminates wasted space due to duplicate attributes (columns) Example (before 1NF normalization): Example (before 1NF normalization): Manager Subordinate 1 Subordinate 2 Subordinate 3 Subordinate 4 BobJimMaryBeth MaryMikeJasonCarolMark JimAlan

5 Recall 1NF (con’t) After 1NF normalization: After 1NF normalization: ManagerSubordinate BobJim BobMary BobBeth MaryMike MaryJason MaryCarol MaryMark JimAlan

6 Identify the FDs Functional Dependencies in R: Functional Dependencies in R: Since every tuple in R is unique, the Since every tuple in R is unique, the attrAattrBattrCattrDattrE 12367 14567 12389 14589 1231011 1451011

7 Identify the FDs Functional Dependencies in R: Functional Dependencies in R: The only FD is: {attrB, attrC, attrD, attrE }  attrA The only FD is: {attrB, attrC, attrD, attrE }  attrA attrAattrBattrCattrDattrE 12367 14567 12389 14589 1231011 1451011

8 Identify the FDs Functional Dependencies in R: Functional Dependencies in R: attrAattrBattrCattrDattrE 12367 14567 12389 14589 1231011 1451011

9 Identify the FDs Functional Dependencies in R: Functional Dependencies in R: attrAattrBattrCattrDattrE 12367 14567 12389 14589 1231011 1451011

10 Normal Form of R 1NF (no multivalues) [check] 1NF (no multivalues) [check] 2NF (no FDs where a subset of the key to the relation is on the left) [check] 2NF (no FDs where a subset of the key to the relation is on the left) [check] 3NF (no non-trivial FDs: either the determinant is a superkey or the RHS of the FD is a member of some key) [check] 3NF (no non-trivial FDs: either the determinant is a superkey or the RHS of the FD is a member of some key) [check] BCNF (the determnant of any non-trivial FD is a superkey for the relation) [check] BCNF (the determnant of any non-trivial FD is a superkey for the relation) [check]

11 Problem Intro. (con’t) Notice: Notice: NameAddrStreetAddrCityFilmNameFilmYear C. Fisher 123 Maple Dr. Hollywood Star Wars 1977 C. Fisher 5 Locust Ln. Malibu Star Wars 1977 C. Fisher 123 Maple Dr. Hollywood The Empire Strikes Back 1980 C. Fisher 5 Locust Ln. Malibu The Empire Strikes Back 1980 C. Fisher 123 Maple Dr. Hollywood Return of the Jedi 1983 C. Fisher 5 Locust Ln. Malibu Return of the Jedi 1983

12 Problem Intro. (con’t) Also Notice: Also Notice: NameAddrStreetAddrCityFilmNameFilmYear C. Fisher 123 Maple Dr. Hollywood Star Wars 1977 C. Fisher 5 Locust Ln. Malibu Star Wars 1977 C. Fisher 123 Maple Dr. Hollywood The Empire Strikes Back 1980 C. Fisher 5 Locust Ln. Malibu The Empire Strikes Back 1980 C. Fisher 123 Maple Dr. Hollywood Return of the Jedi 1983 C. Fisher 5 Locust Ln. Malibu Return of the Jedi 1983

13 Observe the Pattern R ~= TxUxV (R is similar to the Cartesian product of relations T, U, and V) R ~= TxUxV (R is similar to the Cartesian product of relations T, U, and V) AddrStreetAndCity 123 Maple Dr. | Hollywood 5 Locust Ln. | Malibu FilmNameAndYear Star Wars | 1977 The Empire Strikes Back | 1980 Return of the Jedi | 1983 Name C. Fisher Relation TRelation URelation V

14 Problem Definition The Relation R contains unnecessary duplication of data The Relation R contains unnecessary duplication of data R is valid 1NF, 2NF, 3NF, and BCNF (and there are no exact duplicate tuples) R is valid 1NF, 2NF, 3NF, and BCNF (and there are no exact duplicate tuples) R has common data on AddrStreet and AddrCity of all tuples R has common data on AddrStreet and AddrCity of all tuples R has common data on FilmName and FilmLocat of all tuples R has common data on FilmName and FilmLocat of all tuples

15 Solution Introduction of a 4NF Introduction of a 4NF Eliminate “non-trivial” MDs Eliminate “non-trivial” MDs Eliminate additional FDs that violate BCNF Eliminate additional FDs that violate BCNF

16 Definitions Fourth Normal Form - if R is valid BCNF and… - given the “non-trivial” MVD: A 1 A 2 …A n  B 1 B 2 …B n {A 1 A 2 …A n } is a superkey Fourth Normal Form - if R is valid BCNF and… - given the “non-trivial” MVD: A 1 A 2 …A n  B 1 B 2 …B n {A 1 A 2 …A n } is a superkey A MVD: A 1 A 2 …A n  B 1 B 2 …B n for a Relation R is “non-trivial” if: 1.none of the Bs are among the As 2.Not all of the attributes of R are among the As and Bs A MVD: A 1 A 2 …A n  B 1 B 2 …B n for a Relation R is “non-trivial” if: 1.none of the Bs are among the As 2.Not all of the attributes of R are among the As and Bs A MVD is “trivial” if it contains all the variations of A 1 A 2 …A n x B 1 B 2 …B n. A MVD is “trivial” if it contains all the variations of A 1 A 2 …A n x B 1 B 2 …B n. A relation cannot be decomposed any further (under 4NF rules) if it has a trivial MVD A relation cannot be decomposed any further (under 4NF rules) if it has a trivial MVD

17 Recall our Problem Relation Recall our BCNF Relation R: Recall our BCNF Relation R: NameAddrStreetAddrCityFilmNameFilmYear C. Fisher 123 Maple Dr. Hollywood Star Wars 1977 C. Fisher 5 Locust Ln. Malibu Star Wars 1977 C. Fisher 123 Maple Dr. Hollywood The Empire Strikes Back 1980 C. Fisher 5 Locust Ln. Malibu The Empire Strikes Back 1980 C. Fisher 123 Maple Dr. Hollywood Return of the Jedi 1983 C. Fisher 5 Locust Ln. Malibu Return of the Jedi 1983

18 Note about FDs and MVDs Every FD is a MVD Every FD is a MVD (if A 1 A 2 …A n  B 1 B 2 …B n, then A 1 A 2 …A n  B 1 B 2 …B n ) The converse is not always true The converse is not always true FDs rule out certain tuples (i.e. if A  B then two tuples will not have the same value for A and different values for B) FDs rule out certain tuples (i.e. if A  B then two tuples will not have the same value for A and different values for B) MVDs do not rule out tuples. They guarantee that certain tuples must exist. (we will see this later) MVDs do not rule out tuples. They guarantee that certain tuples must exist. (we will see this later)

19 Another Example Another MVD example (credit www.cs.jcu.edu.au) Another MVD example (credit www.cs.jcu.edu.au) emp_namequalificationslanguages SMITH B. Sc NULL SMITH Dip. CS NULL SMITHNULLFORTRAN SMITHNULLCOBOL SMITHNULLPASCAL

20 Another Example (con’t) Our second example 4NF decomposed: Our second example 4NF decomposed: emp_namequalificationslanguages SMITH B. Sc NULL SMITH Dip. CS NULL SMITHNULLFORTRAN SMITHNULLCOBOL SMITHNULLPASCAL emp_namequalificationsSMITH B. Sc SMITH Dip. CS emp_namelanguagesSMITHFORTRAN SMITHCOBOL SMITHPASCAL Relation L Relation M Relation O

21 Explanation of second example Unnecessary tuples are eliminated (those with NULL values)… saving space Unnecessary tuples are eliminated (those with NULL values)… saving space Note: for this example, MxO is not similar to L: this is because the MVD in L is non- trivial Note: for this example, MxO is not similar to L: this is because the MVD in L is non- trivial

22 Second example (modified) If we were to modify the second example L to be 4NF, we would need to combine every possible value of M with every one of O, changing the MVD from non-trivial to trivial If we were to modify the second example L to be 4NF, we would need to combine every possible value of M with every one of O, changing the MVD from non-trivial to trivial This relation would look similar to the product of M and O This relation would look similar to the product of M and O

23 Second example (modified) If we were to modify the second example L, we would need to combine every possible value of M with every one of O If we were to modify the second example L, we would need to combine every possible value of M with every one of O emp_namequalificationslanguages SMITH B. Sc NULL SMITH Dip. CS NULL SMITHNULLFORTRAN SMITHNULLCOBOL SMITHNULLPASCAL Relation L

24 Second example (modified) If we were to modify the second example L, we would need to combine every possible value of M with every one of O If we were to modify the second example L, we would need to combine every possible value of M with every one of O This relation is 4NF b/c the only MVD is trivial (the original L was not 4NF) This relation is 4NF b/c the only MVD is trivial (the original L was not 4NF) emp_namequalificationslanguages SMITH B. Sc FORTRAN SMITH Dip. CS FORTRAN SMITH B. Sc COBOL SMITH Dip. CS COBOL SMITH B. Sc PASCAL SMITH Dip. CS PASCAL Relation L w/ Trivial MVD

25 Formal Definition of a MVD Using the following relation, (credit Ullman & Widom) Using the following relation, (credit Ullman & Widom) Note that A, B, and “others” are not actual attributes, but rather sets of attributes Note that A, B, and “others” are not actual attributes, but rather sets of attributes AsBsothers tuple t a1a1a1a1 b1b1b1b1 c1c1c1c1 == tuple u a1a1a1a1 b1b1b1b1 c2c2c2c2 == tuple v a1a1a1a1 b2b2b2b2 c2c2c2c2

26 Formal Definition of a MVD (con’t) Suppose A  B holds, then: Suppose A  B holds, then: t[A] = u[A] = v[A] t[A] = u[A] = v[A] t[B] = u[B] t[B] = u[B] u[C] = v[C] u[C] = v[C] If a MVD is to exist, u must exist. If a MVD is to exist, u must exist. For the MVD to be non-trivial, every tuple must be in the form of a u tuple For the MVD to be non-trivial, every tuple must be in the form of a u tuple AsBsothers tuple t a1a1a1a1 b1b1b1b1 c1c1c1c1 == tuple u a1a1a1a1 b1b1b1b1 c2c2c2c2 == tuple v a1a1a1a1 b2b2b2b2 c2c2c2c2

27 Formal Definition of a MVD (con’t) For the MVD A  B to be trivial, either: For the MVD A  B to be trivial, either: B  A or B  A or B  A = R B  A = R Must be true AsBsothers tuple t a1a1a1a1 b1b1b1b1 c1c1c1c1 == tuple u a1a1a1a1 b1b1b1b1 c2c2c2c2 == tuple v a1a1a1a1 b2b2b2b2 c2c2c2c2

28 Armstrong’s Axioms WRT MVDs Many of Armstrong’s Axioms work with MVDs including: Many of Armstrong’s Axioms work with MVDs including: Reflexivity rule Reflexivity rule Augmentation rule Augmentation rule Transitivity rule Transitivity rule Complementation rule Complementation rule Multivalued augmentation rule Multivalued augmentation rule Multivalued transitivity rule Multivalued transitivity rule Replication rule Replication rule Coalescence rule Coalescence rule Multivalued union rule Multivalued union rule Intersection rule Intersection rule Difference rule Difference rule See below for specifics on these rules http://www.cs.sfu.ca/CC/354/zaiane/material/notes/Chapter7/node15.html See below for specifics on these rules http://www.cs.sfu.ca/CC/354/zaiane/material/notes/Chapter7/node15.html http://www.cs.sfu.ca/CC/354/zaiane/material/notes/Chapter7/node15.html

29 References Course textbook: a First Course in Database Systems (Jeffrey D. Ullman and Jennifer Widom) Course textbook: a First Course in Database Systems (Jeffrey D. Ullman and Jennifer Widom) Normalizing your database: First Normal Form (1NF): http://webc.nicc.edu/~weedd/sysanaly/Chapter%206%20Database%20normalization/1NF.html Normalizing your database: First Normal Form (1NF): http://webc.nicc.edu/~weedd/sysanaly/Chapter%206%20Database%20normalization/1NF.html http://webc.nicc.edu/~weedd/sysanaly/Chapter%206%20Database%20normalization/1NF.html Multivalued Dependencies (Ozmar Zaine): http://www.cs.sfu.ca/CC/354/zaiane/material/notes/Chapter7/node13.html Multivalued Dependencies (Ozmar Zaine): http://www.cs.sfu.ca/CC/354/zaiane/material/notes/Chapter7/node13.html http://www.cs.sfu.ca/CC/354/zaiane/material/notes/Chapter7/node13.html Multivalued Dependencies: http://www.cs.jcu.edu.au/Subjects/cp1500/1998/Lecture_Notes/normalisation/mvd.html Multivalued Dependencies: http://www.cs.jcu.edu.au/Subjects/cp1500/1998/Lecture_Notes/normalisation/mvd.html http://www.cs.jcu.edu.au/Subjects/cp1500/1998/Lecture_Notes/normalisation/mvd.html


Download ppt "Multivalued Dependencies By David Wortham. Problem Introduction Assume a relation R (from the book): (credit Ullman and Widom) Assume a relation R (from."

Similar presentations


Ads by Google