CPSC-310 Database Systems

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
Advertisements

4NF and 5NF Prof. Sin-Min Lee Department of Computer Science.
1 Loss-Less Joins. 2 Decompositions uDependency-preservation property: enforce constraints on original relation by enforcing some constraints on resulting.
Chapter 3 Notes. 3.1 Functional Dependencies A functional dependency is a statement that – two tuples of a relation that agree on some particular set.
4NF. PTypes Planes HasType Employees MServices Auth. MWorks Assignment AppliedOn States Dates PTypes(model, capacity,…) Planes(regno, model) Employees(sin,…)
Multivalued Dependency Prof. Sin-Min Lee Department of Computer Science.
1 Multi-valued Dependencies Salman Azhar Multi-valued Dependencies Fourth Normal Form These slides use some figures, definitions, and explanations from.
1 Multivalued Dependencies Fourth Normal Form Source: Slides by Jeffrey Ullman.
1 Multivalued Dependencies Fourth Normal Form. 2 Definition of MVD uA multivalued dependency (MVD) on R, X ->->Y, says that if two tuples of R agree on.
1 Multivalued Dependencies Fourth Normal Form Sources: Slides by Jeffrey Ullman book by Ramakrishnan & Gehrke.
Multivalued Dependency Prof. Sin-Min Lee Department of Computer Science.
Winter 2002Arthur Keller – CS 1804–1 Schedule Today: Jan. 15 (T) u Normal Forms, Multivalued Dependencies. u Read Sections Assignment 1 due. Jan.
1 Multivalued Dependencies Fourth Normal Form. 2 A New Form of Redundancy uMultivalued dependencies (MVD’s) express a condition among tuples of a relation.
Fall 2001Arthur Keller – CS 1805–1 Schedule Today Oct. 9 (T) Multivalued Dependencies, Relational Algebra u Read Sections 3.7, Assignment 2 due.
Fall 2001Arthur Keller – CS 1804–1 Schedule Today Oct. 4 (TH) Functional Dependencies and Normalization. u Read Sections Project Part 1 due. Oct.
Chapter 14 Advanced Normalization Transparencies © Pearson Education Limited 1995, 2005.
Database Systems Normal Forms. Decomposition Suppose we have a relation R[U] with a schema U={A 1,…,A n } – A decomposition of U is a set of schemas.
1 Normalization Anomalies Boyce-Codd Normal Form 3 rd Normal Form.
Databases 1 8th lecture. Topics of the lecture Multivalued Dependencies Fourth Normal Form Datalog 2.
Normalization Goal = BCNF = Boyce-Codd Normal Form = all FD’s follow from the fact “key  everything.” Formally, R is in BCNF if for every nontrivial FD.
CS143 Review: Normalization Theory Q: Is it a good table design? We can start with an ER diagram or with a large relation that contain a sample of the.
SCUJ. Holliday - coen 1784–1 Schedule Today: u Normal Forms. u Section 3.6. Next u Relational Algebra. Read chapter 5 to page 199 After that u SQL Queries.
BCNF & Lossless Decomposition Prof. Sin-Min Lee Department of Computer Science.
4NF (Multivalued Dependency), and 5NF (Join Dependency)
IST 210 Normalization 2 Todd Bacastow IST 210. Normalization Methods Inspection Closure Functional dependencies are key.
1 Multivalued Dependencies Fourth Normal Form Reasoning About FD’s + MVD’s.
1 Multivalued Dependencies Fourth Normal Form Reasoning About FD’s + MVD’s.
Design Theory for RDB Normal Forms. Lu Chaojun, SJTU 2 Redundant because these info may be figured out by using FD s1  … What’s Bad Design? Redundancy.
3 Spring Chapter Normalization of Database Tables.
Multivalued Dependencies and 4th NF CIS 4301 Lecture Notes Lecture /21/2006.
Databases 1 Sixth lecture. 2 Functional Dependencies X -> A is an assertion about a relation R that whenever two tuples of R agree on all the attributes.
Final Review Zaki Malik November 20, Basic Operators Covered.
Chapter 8 Relational Database Design. 2 Relational Database Design: Goals n Reduce data redundancy (undesirable replication of data values) n Minimize.
1 CS 430 Database Theory Winter 2005 Lecture 8: Functional Dependencies Second, Third, and Boyce-Codd Normal Forms.
Design Theory for Relational Databases Functional Dependencies Decompositions Normal Forms: BCNF, Third Normal Form Introduction to Multivalued Dependencies.
4NF & MULTIVALUED DEPENDENCY By Kristina Miguel. Review  Superkey – a set of attributes which will uniquely identify each tuple in a relation  Candidate.
1 Database Design: DBS CB, 2 nd Edition Physical RDBMS Model: Schema Design and Normalization Ch. 3.
Lecture 11: Functional Dependencies
Advanced Normalization
Design Theory for Relational Databases
Chapter 15 Relational Design Algorithms and Further Dependencies
Design Theory for RDB Normal Forms.
Schedule Today: Next After that Normal Forms. Section 3.6.
Higher Forms of Normalization
CPSC-310 Database Systems
Normal Forms.
Schedule Today: Jan. 23 (wed) Week of Jan 28
Chapter 8: Relational Database Design
3.1 Functional Dependencies
Handout 4 Functional Dependencies
Advanced Normalization
Normal forms First Normal Form (1NF) Second Normal Form (2NF)
BCNF and Normalization
Module 5: Overview of Normalization
Chapter 7: Relational Database Design
Multivalued Dependencies & Fourth Normal Form (4NF)
Mulitvalued Dependencies
Functional Dependencies and Relational Schema Design
Multivalued Dependencies & Fourth Normal Form
Multivalued Dependencies & Fourth Normal Form
CPSC-310 Database Systems
Functional Dependencies
Third Normal Form.
Multivalued Dependencies
Anomalies Boyce-Codd Normal Form 3rd Normal Form
Lecture 6: Functional Dependencies
Chapter 3: Multivalued Dependencies
Chapter 7a: Overview of Database Design -- Normalization
Lecture 09: Functional Dependencies
CS4222 Principles of Database System
Presentation transcript:

CPSC-310 Database Systems Professor Jianer Chen Room 315C HRBB Lecture #8

BCNF and 3NF

BCNF and 3NF BCNF  3NF 3NF BCNF

eliminating FD redundancies BCNF and 3NF BCNF  3NF 3NF BCNF Property 3NF BCNF eliminating FD redundancies no (but most) yes recoverable preserving FDs

eliminating FD redundancies BCNF and 3NF BCNF  3NF 3NF BCNF Property 3NF BCNF ?? eliminating FD redundancies no (but most) yes recoverable preserving FDs

eliminating FD redundancies BCNF and 3NF BCNF  3NF 3NF BCNF Property 3NF BCNF Not Exist! eliminating FD redundancies no (but most) yes recoverable preserving FDs

eliminating FD redundancies BCNF and 3NF BCNF  3NF 3NF BCNF Property 3NF BCNF Not Exist! eliminating FD redundancies no (but most) yes recoverable preserving FDs

eliminating FD redundancies BCNF and 3NF BCNF  3NF 3NF BCNF Property 3NF BCNF Not Exist! eliminating FD redundancies no (but most) yes recoverable preserving FDs Would BCNF be sufficient to eliminate other kind of redundancies?

Example of a bad relation in BCNF

Example of a bad relation in BCNF Suppose that we have a relation that lists the teacher- student relationship for each person. That is, for a person p, the relation gives all teachers who ever taught p and all students who were ever taught by p. For example, suppose that David and Jeff taught Kevin, while Kevin taught Michael, Jason, and Tom. Then the relation should contain tuples:

Example of a bad relation in BCNF Suppose that we have a relation that lists the teacher- student relationship for each person. That is, for a person p, the relation gives all teachers who ever taught p and all students who were ever taught by p. For example, suppose that David and Jeff taught Kevin, while Kevin taught Michael, Jason, and Tom. Then the relation should contain tuples: person teacher student Kevin David Michael Jason Tom Jeff ……

Example of a bad relation in BCNF Suppose that we have a relation that lists the teacher- student relationship for each person. That is, for a person p, the relation gives all teachers who ever taught p and all students who were ever taught by p. For example, suppose that David and Jeff taught Kevin, while Kevin taught Michael, Jason, and Tom. Then the relation should contain tuples: There are some obvious redundancies: suppose Kevin has n teachers and m students, then there will be n*m tuples for Kevin! On the other hand, it indeed needs no more than n+m (smaller) tuples to record all information about Kevin’s teachers and students. person teacher student Kevin David Michael Jason Tom Jeff ……

Example of a bad relation in BCNF Suppose that we have a relation that lists the teacher- student relationship for each person. That is, for a person p, the relation gives all teachers who ever taught p and all students who were ever taught by p. For example, suppose that David and Jeff taught Kevin, while Kevin taught Michael, Jason, and Tom. Then the relation should contain tuples: There are some obvious redundancies: suppose Kevin has n teachers and m students, then there will be n*m tuples for Kevin! On the other hand, it indeed needs no more than n+m (smaller) tuples to record all information about Kevin’s teachers and students. On the other hand, the relation is in BCNF: the only key is {person, teacher, student} so there is no BCNF violators. person teacher student Kevin David Michael Jason Tom Jeff ……

Definition of MVD MVD captures redundancy that FD’s can’t

Definition of MVD MVD captures redundancy that FD’s can’t A multivalued dependency (MVD) X↠Y on a relation R says that if two tuples of R agree on all the attributes of X, then by swapping their components in Y, we still get tuples in R, i.e., for each value of X, the values of Y are independent of the values of R\(X∪Y).

Definition of MVD MVD captures redundancy that FD’s can’t A multivalued dependency (MVD) X↠Y on a relation R says that if two tuples of R agree on all the attributes of X, then by swapping their components in Y, we still get tuples in R, i.e., for each value of X, the values of Y are independent of the values of R\(X∪Y). person teacher student Kevin David Michael Jason Tom Jeff ……

Definition of MVD MVD captures redundancy that FD’s can’t A multivalued dependency (MVD) X↠Y on a relation R says that if two tuples of R agree on all the attributes of X, then by swapping their components in Y, we still get tuples in R, i.e., for each value of X, the values of Y are independent of the values of R\(X∪Y). person teacher student Kevin David Michael Jason Tom Jeff ……

Definition of MVD MVD captures redundancy that FD’s can’t A multivalued dependency (MVD) X↠Y on a relation R says that if two tuples of R agree on all the attributes of X, then by swapping their components in Y, we still get tuples in R, i.e., for each value of X, the values of Y are independent of the values of R\(X∪Y). person teacher student Kevin David Michael Jason Tom Jeff ……

Definition of MVD MVD captures redundancy that FD’s can’t A multivalued dependency (MVD) X↠Y on a relation R says that if two tuples of R agree on all the attributes of X, then by swapping their components in Y, we still get tuples in R, i.e., for each value of X, the values of Y are independent of the values of R\(X∪Y). person teacher student Kevin David Michael Jason Tom Jeff ……

Definition of MVD MVD captures redundancy that FD’s can’t A multivalued dependency (MVD) X↠Y on a relation R says that if two tuples of R agree on all the attributes of X, then by swapping their components in Y, we still get tuples in R, i.e., for each value of X, the values of Y are independent of the values of R\(X∪Y). person teacher student Kevin David Michael Jason Tom Jeff …… Thus, person ↠ teacher

Another Definition of MVDs

Another Definition of MVDs Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW.

Another Definition of MVDs Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. x

Another Definition of MVDs Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. VY VW x y1 ⁞ yp w1 ⁞ wq

Another Definition of MVDs Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. VY VW x R y1 ⁞ yp w1 ⁞ wq . x y1 w1 yi wk yp wq

Another Definition of MVDs Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. VY VW x R Look at the example we discussed.

Another Definition of MVDs Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. VY VW Kevin R Look at the example we discussed.

Another Definition of MVDs Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. VY VW Kevin R David Jeff Michael Jason Tom Look at the example we discussed.

Another Definition of MVDs Suppose X↠Y is a MVD in a relation R. Let W be the set of attributes of R that are not in X∪Y. Then for each value x of X, there is a set VY of values of Y and a set VW of values of W such that R contains exactly the tuples of the form (x, yi, wk), where yi and wk run over all combinations of the values in VY and VW. VY VW Kevin R David Jeff Michael Jason Tom person teacher student Kevin David Michael Jason Tom Jeff …… Look at the example we discussed.

Another Example Consumers(name, addr, phones, beersLiked)

Another Example Consumers(name, addr, phones, beersLiked) A consumer’s phones are independent of the beers they like.

Another Example Consumers(name, addr, phones, beersLiked) A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked.

Another Example Consumers(name, addr, phones, beersLiked) A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations.

Another Example Consumers(name, addr, phones, beersLiked) A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy.

Another Example Consumers(name, addr, phones, beersLiked) A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy. name → addr is the only FD.

Another Example Consumers(name, addr, phones, beersLiked) A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy. name → addr is the only FD. name addr phones beersLiked Sue a p1 b1 p2 b2

Another Example Consumers(name, addr, phones, beersLiked) A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy. name → addr is the only FD. name addr phones beersLiked Sue a p1 b1 p2 b2 Then these tuples must also be in the relation.

Another Example Consumers(name, addr, phones, beersLiked) A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy. name → addr is the only FD. name addr phones beersLiked Sue a p1 b1 p2 b2 If X ↠ Y X Y others Then these tuples must also be in the relation.

Another Example Consumers(name, addr, phones, beersLiked) A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy. name → addr is the only FD. name addr phones beersLiked Sue a p1 b1 p2 b2 If X ↠ Y X Y others equal Then these tuples must also be in the relation.

Another Example Consumers(name, addr, phones, beersLiked) A consumer’s phones are independent of the beers they like. name ↠ phones and name ↠ beersLiked. Thus, each of a consumer’s phones appears with each of the beer they like in all combinations. This repetition is unlike FD redundancy. name → addr is the only FD. name addr phones beersLiked Sue a p1 b1 p2 b2 If X ↠ Y X Y others equal exchange Then these tuples must also be in the relation.

MVD Rules Every FD is an MVD (promotion).

MVD Rules Every FD is an MVD (promotion). * If X→Y, then swapping Y’s between two tuples that agree on X doesn’t change the tuples.

MVD Rules Every FD is an MVD (promotion). * If X→Y, then swapping Y’s between two tuples that agree on X doesn’t change the tuples. * Therefore, the “new” tuples are surely in the relation, and we know X ↠ Y.

MVD Rules Every FD is an MVD (promotion). * If X→Y, then swapping Y’s between two tuples that agree on X doesn’t change the tuples. * Therefore, the “new” tuples are surely in the relation, and we know X ↠ Y. Transitiveness: If X↠Y, and Y↠Z, then X↠Z.

MVD Rules Every FD is an MVD (promotion). * If X→Y, then swapping Y’s between two tuples that agree on X doesn’t change the tuples. * Therefore, the “new” tuples are surely in the relation, and we know X ↠ Y. Transitiveness: If X↠Y, and Y↠Z, then X↠Z. Complementation: If X↠Y, and Z is all the other attributes, then X↠Z.

However, Splitting Doesn’t Hold Like FD’s, we cannot generally split the left side of an MVD.

However, Splitting Doesn’t Hold Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side.

However, Splitting Doesn’t Hold Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf)

However, Splitting Doesn’t Hold Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf) * A drinker can have several phones, with the number divided between areaCode and phone (last 7 digits).

However, Splitting Doesn’t Hold Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf) * A drinker can have several phones, with the number divided between areaCode and phone (last 7 digits). * A drinker can like several beers, each with its own manufacturer.

However, Splitting Doesn’t Hold Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf) Since the areaCode-phone combinations for a drinker are independent of the beersLiked-manf combinations, we expect that the following MVD’s hold:

However, Splitting Doesn’t Hold Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf) Since the areaCode-phone combinations for a drinker are independent of the beersLiked-manf combinations, we expect that the following MVD’s hold: name ↠ areaCode phone name ↠ beersLiked manf

However, Splitting Doesn’t Hold Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf) Since the areaCode-phone combinations for a drinker are independent of the beersLiked-manf combinations, we expect that the following MVD’s hold: name ↠ areaCode phone name ↠ beersLiked manf name areaCode phone beersLiked manf Sue 650 555-1111 Bud A.B. WickedAle Peter’s 415 555-9999

However, Splitting Doesn’t Hold Like FD’s, we cannot generally split the left side of an MVD. But unlike FD’s, we cannot split the right side either --- sometimes you have to leave several attributes on the right side. Example Consumers(name, areaCode, phone, beersLiked, manf) Since the areaCode-phone combinations for a drinker are independent of the beersLiked-manf combinations, we expect that the following MVD’s hold: name ↠ areaCode phone name ↠ beersLiked manf name areaCode phone beersLiked manf Sue 650 555-1111 Bud A.B. WickedAle Peter’s 415 555-9999 However, we cannot swap area codes or phones by themselves. That is, neither name↠areaCode nor name↠phone holds for this relation.

Fourth Normal Form

Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF.

Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation.

Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey.

Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey. Nontrivial MVD X ↠Y means that: * Y is not a subset of X, and * X and Y are not, together, all the attributes.

Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey. Nontrivial MVD X ↠Y means that: * Y is not a subset of X, and * X and Y are not, together, all the attributes. Note that the definition of “superkey” still depends on FD’s only.

Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey. BCNF versus 4NF:

Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey. BCNF versus 4NF: * FD X→Y implies MVD X ↠Y. Thus, if R is in 4NF, it is in BCNF. a BCNF violation is a 4NF violation

Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey. BCNF versus 4NF: * FD X→Y implies MVD X ↠Y. Thus, if R is in 4NF, it is in BCNF. a BCNF violation is a 4NF violation * But R could be in BCNF and not 4NF.

Fourth Normal Form The redundancy that comes from MVD’s is not removable by putting the database schema in BCNF. A stronger normal form 4NF, that (intuitively) treats MVD’s as FD’s when it comes to decomposition, but not when determining keys of the relation. A relation R is in 4NF if: whenever X ↠Y is a nontrivial MVD, then X is a superkey. BCNF versus 4NF: * FD X→Y implies MVD X ↠Y. Thus, if R is in 4NF, it is in BCNF. a BCNF violation is a 4NF violation * But R could be in BCNF and not 4NF. * Thus, 4NF  BCNF

Decomposition into 4NF

Decomposition into 4NF Algorithm 4NF(R, T) Input: A relation R and its FDs T and MVFs F Output: A collection C of relations in 4NF 1. C = ; C’ = {(R, T, F)}; 2. While C’   Do 2.1 Pick (R’, T’, F’) from C’; \\ remove from C’ 2.2 If (R’, T’, F’) has a 4NF violator X↠Y; 2.3 Then decompose (R’, T’, F’) into: (R1, T1, F1) where R1= X⋃Y(R’); (R2, T2, F2) where R2= X⋃W(R’); \\ where W is the set of attributes of R’ not in \\ X⋃Y, (T1, F1) and (T2, F2) are the FDs and \\ MVFs (T’, F’) of R’ projected on R1 and R2 Add (R1, T1, F1) and (R2, T2, F2) to C’; 2.4 Else Add (R’, T’, F’) to C; 3. Output C.

Decomposition into 4NF Remarks. Algorithm 4NF(R, T) Input: A relation R and its FDs T and MVFs F Output: A collection C of relations in 4NF 1. C = ; C’ = {(R, T, F)}; 2. While C’   Do 2.1 Pick (R’, T’, F’) from C’; \\ remove from C’ 2.2 If (R’, T’, F’) has a 4NF violator X↠Y; 2.3 Then decompose (R’, T’, F’) into: (R1, T1, F1) where R1= X⋃Y(R’); (R2, T2, F2) where R2= X⋃W(R’); \\ where W is the set of attributes of R’ not in \\ X⋃Y, (T1, F1) and (T2, F2) are the FDs and \\ MVFs (T’, F’) of R’ projected on R1 and R2 Add (R1, T1, F1) and (R2, T2, F2) to C’; 2.4 Else Add (R’, T’, F’) to C; 3. Output C.

Decomposition into 4NF Remarks. 1. Very similar to the algorithm for BCNF; Algorithm 4NF(R, T) Input: A relation R and its FDs T and MVFs F Output: A collection C of relations in 4NF 1. C = ; C’ = {(R, T, F)}; 2. While C’   Do 2.1 Pick (R’, T’, F’) from C’; \\ remove from C’ 2.2 If (R’, T’, F’) has a 4NF violator X↠Y; 2.3 Then decompose (R’, T’, F’) into: (R1, T1, F1) where R1= X⋃Y(R’); (R2, T2, F2) where R2= X⋃W(R’); \\ where W is the set of attributes of R’ not in \\ X⋃Y, (T1, F1) and (T2, F2) are the FDs and \\ MVFs (T’, F’) of R’ projected on R1 and R2 Add (R1, T1, F1) and (R2, T2, F2) to C’; 2.4 Else Add (R’, T’, F’) to C; 3. Output C.

Decomposition into 4NF Remarks. 1. Very similar to the algorithm for BCNF; 2. The projections (T1, F1) and (T2, F2) of (T’, F’) of R’ on R1 and R2 can be constructed; Algorithm 4NF(R, T) Input: A relation R and its FDs T and MVFs F Output: A collection C of relations in 4NF 1. C = ; C’ = {(R, T, F)}; 2. While C’   Do 2.1 Pick (R’, T’, F’) from C’; \\ remove from C’ 2.2 If (R’, T’, F’) has a 4NF violator X↠Y; 2.3 Then decompose (R’, T’, F’) into: (R1, T1, F1) where R1= X⋃Y(R’); (R2, T2, F2) where R2= X⋃W(R’); \\ where W is the set of attributes of R’ not in \\ X⋃Y, (T1, F1) and (T2, F2) are the FDs and \\ MVFs (T’, F’) of R’ projected on R1 and R2 Add (R1, T1, F1) and (R2, T2, F2) to C’; 2.4 Else Add (R’, T’, F’) to C; 3. Output C.

Decomposition into 4NF Remarks. 1. Very similar to the algorithm for BCNF; 2. The projections (T1, F1) and (T2, F2) of (T’, F’) of R’ on R1 and R2 can be constructed; 3. It can be proved that the algorithm produces relations from which the original relation is re-constructible; Algorithm 4NF(R, T) Input: A relation R and its FDs T and MVFs F Output: A collection C of relations in 4NF 1. C = ; C’ = {(R, T, F)}; 2. While C’   Do 2.1 Pick (R’, T’, F’) from C’; \\ remove from C’ 2.2 If (R’, T’, F’) has a 4NF violator X↠Y; 2.3 Then decompose (R’, T’, F’) into: (R1, T1, F1) where R1= X⋃Y(R’); (R2, T2, F2) where R2= X⋃W(R’); \\ where W is the set of attributes of R’ not in \\ X⋃Y, (T1, F1) and (T2, F2) are the FDs and \\ MVFs (T’, F’) of R’ projected on R1 and R2 Add (R1, T1, F1) and (R2, T2, F2) to C’; 2.4 Else Add (R’, T’, F’) to C; 3. Output C.

Decomposition into 4NF Remarks. 1. Very similar to the algorithm for BCNF; 2. The projections (T1, F1) and (T2, F2) of (T’, F’) of R’ on R1 and R2 can be constructed; 3. It can be proved that the algorithm produces relations from which the original relation is re-constructible; 4. The algorithm eliminates BCNF and MVF violations. Algorithm 4NF(R, T) Input: A relation R and its FDs T and MVFs F Output: A collection C of relations in 4NF 1. C = ; C’ = {(R, T, F)}; 2. While C’   Do 2.1 Pick (R’, T’, F’) from C’; \\ remove from C’ 2.2 If (R’, T’, F’) has a 4NF violator X↠Y; 2.3 Then decompose (R’, T’, F’) into: (R1, T1, F1) where R1= X⋃Y(R’); (R2, T2, F2) where R2= X⋃W(R’); \\ where W is the set of attributes of R’ not in \\ X⋃Y, (T1, F1) and (T2, F2) are the FDs and \\ MVFs (T’, F’) of R’ projected on R1 and R2 Add (R1, T1, F1) and (R2, T2, F2) to C’; 2.4 Else Add (R’, T’, F’) to C; 3. Output C.

Example

Example Consumers(name, addr, phones, candiesLiked)

Example Consumers(name, addr, phones, candiesLiked) FD: name → addr MVD’s: name ↠ phones, name ↠ candiesLiked Key is {name, phones, candiesLiked}. All dependencies violate 4NF.

Example Consumers(name, addr, phones, candiesLiked) FD: name → addr MVD’s: name ↠ phones, name ↠ candiesLiked Key is {name, phones, candiesLiked}. All dependencies violate 4NF. Decompose using name → addr:

Example Consumers(name, addr, phones, candiesLiked) FD: name → addr MVD’s: name ↠ phones, name ↠ candiesLiked Key is {name, phones, candiesLiked}. All dependencies violate 4NF. Decompose using name → addr: Consumers1(name, addr) In 4NF; only dependency is name → addr.

Example Consumers(name, addr, phones, candiesLiked) FD: name → addr MVD’s: name ↠ phones, name ↠ candiesLiked Key is {name, phones, candiesLiked}. All dependencies violate 4NF. Decompose using name → addr: Consumers1(name, addr) In 4NF; only dependency is name → addr. Consumers2(name, phones, candiesLiked)

Example Consumers(name, addr, phones, candiesLiked) FD: name → addr MVD’s: name ↠ phones, name ↠ candiesLiked Key is {name, phones, candiesLiked}. All dependencies violate 4NF. Decompose using name → addr: Consumers1(name, addr) In 4NF; only dependency is name → addr. Consumers2(name, phones, candiesLiked) Not in 4NF. MVD’s name ↠ phones and name ↠ candiesLiked apply. No FD’s, so all three attributes form the key.

Example Consumers(name, addr, phones, candiesLiked) FD: name → addr MVD’s: name ↠ phones, name ↠ candiesLiked Key is {name, phones, candiesLiked}. All dependencies violate 4NF. Decompose using name → addr: Consumers1(name, addr) In 4NF; only dependency is name → addr. Consumers2(name, phones, candiesLiked) Not in 4NF. MVD’s name ↠ phones and name ↠ candiesLiked apply. No FD’s, so all three attributes form the key. Either name↠phones or name↠candiesLiked gives: Consumers3(name, phones) Consumers4(name, candiesLiked)

Normal Form Comparisons

Normal Form Comparisons 3NF BCNF 4NF  BCNF  3NF 4NF

Normal Form Comparisons 3NF BCNF 4NF  BCNF  3NF 4NF Property 3NF BCNF 4NF eliminates FD redundancies no (most) yes eliminates MVD redundancies no preserves FDs recoverable