Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D. Given a set of attributes X, the closure X+ is the set of attributes functionally determined by X Given a relation R and a set F of functional dependencies, we need a way to find whether a functional dependency X Y is true with respect to F Given relation R with attributes A, B, C, D, E and A BC, CD E, BE C AE _____? From reflexivity, AE+ = { A, E } From A BC, AE+ = { A, B, C, E } No other rules are applicable or add to AE+ We conclude that AE ABCE or simply AE BC Or AE A, AE B, AE C, and AE E Given a set F of functional dependencies, the closure X+ of a set of attributes X is determined by the following algorithm: Initialize X+ to X Repeat until X+ does not change: ▪ Find any unapplied functional dependency Y Z in F such that Y X+ ▪ Set X+ = X+ Z A key K for a given relation R is a minimal set of attributes A1, A2, ..., An such that closure {A1, A2, ..., An}+ is the set of all attributes of R MusicGroup(name, artist, genre, dateformed, datefirstjoined) name genre dateformed name artist datefirstjoined K must be (name, artist) because K+ = {name, artist, genre, dateformed, datefirstjoined} Given a set F of functional dependencies, closure F+ is the set of all functional dependencies implied by F F+ can be found using the set of inference rules (reflexivity, transitivity, augmentation, etc.) Sets F1 and F2 of functional dependencies are considered equal if they have the same closure (i.e. F1+ = F2+) In addition to determining closure F+ for set F of functional dependencies, we can also derive any functional dependency that follows from F via Armstrong’s axioms: Reflexivity (if Y X, then X Y) Augmentation (if X Y, then XZ YZ) Transitivity (if X Y and Y Z, then X Z) Given a set F of functional dependencies, any set of functional dependencies that’s equivalent to F is called a basis We limit the possibilities by requiring that each dependency has a single attribute on the right-hand side How many bases are there for a relation R with n functional dependencies in F? A minimal basis for a relation R is a basis B that satisfies the following conditions: All functional dependencies in B have singleton right-hand sides If any functional dependency is removed from B, the result is no longer a basis If any left-hand side attribute is removed from a functional dependency of B, the result is no longer a basis Given basis B, we can determine whether it is a minimal basis via the algorithm below: For each functional dependency X Y in B, check if B – { X Y } still implies X Y ▪ if so, remove X Y For each functional dependency XW Y in B, check if X+ is the same with respect to F and ( F – { XW Y } ) { X Y } ▪ if so, replace XW Y with X Y Given relation R( A, B, C, D ) and functional dependencies AB C, C D, and D A What are the keys of R? What are the superkeys of R that are not keys? Is the given set of functional dependencies a basis? Is it a minimal basis? What’s wrong with the relation below? MusicGroup( name, artist, genre, dateformed, datefirstjoined ) i.e. how can tuples become corrupted or incorrect? Without normalization, problems with relations include: Unnecessary redundancy Insert anomalies Update anomalies Delete anomalies Splitting a relation into two (more specific) relations is called decomposition The objective is to have each resulting relation be atomic i.e. each relation should contain only information related to the key A given relation R with set F of functional dependencies is in BCNF if and only if all functional dependencies X Y in F are: either trivial (i.e. Y X) or X is a superkey of R If relation R is not in BCNF, it is possible to use decomposition to transform R to BCNF Given a set F of functional dependencies for relation R( A1, A2, ..., An ) that is not in BCNF: Convert F to a minimal basis Find an X Y that violates BCNF Compute closure X+ Decompose R into: ▪ R1 containing all attributes of X+ ▪ R2 containing { A1, A2, ..., An } – ( X+ – X ) Project functional dependencies onto R1 and R2 Given relation R( A, B, C, D, E ) and functional dependencies AB AC, CE D, B A, and D AE What are the keys of R? What are the superkeys of R that are not keys? Is the given set of functional dependencies a basis? Is it a minimal basis? Is relation R in BCNF? If not, decompose R such that it is in BCNF