Functional Dependencies Keys Armstrong's Axioms A . A B . B Assume a relation with schema R(A , . ., A ). Reflexivity – If {B , . ., B } {A , . ., A } then 1 m 1 n 1 n 1 n 1 m A subset of {A , . ., A } is a superkey of R if it functionally A . A B . B . (These are the trivial functional 1 n 1 m 1 n determines all the attributes of R. dependencies.) “A , . ., A functionally determine B , . ., B ” 1 m 1 n Augmentation – If A . A B . B , then A superkey is a key if no proper subset of it is a superkey. 1 m 1 n A . A C . C B . B C . C . 1 m 1 k 1 n 1 k gearhead(person_ID, main_address, make, model, year, color, Transitivity – If A . A B . B and B . B C . income, parking_space, age, insurance_policy, tag_number) 1 m 1 n 1 n 1 . C , then A . A C . C . k 1 m 1 k These are sufficient to infer the consequences of a set of functional dependencies. 1 2 3 Splitting/Combining Closure of Attributes Computing the Closure A useful consequence of Armstrong's axioms is the Suppose that S is a set of functional dependencies and that To compute the closure of {A , . ., A } with respect to S: 1 m splitting/combining rule. {A , . ., A } is a set of attributes. The closure of {A , . ., 1 m 1 Let X = {A , . ., A }. A } (with respect to S) is the set of attributes B such that 1 m m A . A B is a consequence of the functional Repeat: A . A B . B 1 m 1 m 1 n dependencies in S. If B . B C . C is in S and {B , . ., B } is a subset if and only if 1 k 1 n 1 k of X, then for each i from 1 to n, C is added to X if it is not i for every i from 1 to n, A . A B . 1 m i The closure is denoted by {A , . ., A }+. already in X. 1 m (See Exercise 3.2.2 for some other potentially useful Until X cannot be made any larger. consequences.) 4 5 6 Minimal Bases Computing a minimal basis Projecting a set of FDs It is often useful to work with a minimal basis for a set of To compute a minimal basis from a set S of FDs: Given R(A , . ., A ) and set S of FDs. Suppose that R is the 1 n 1 functional dependencies and their consequences. projection (R). What functional dependencies hold on R ? Set S' to the FDs from S split so that all right sides are L 1 A minimal basis for a set S of functional dependencies and singletons. their consequences is a set B such that Let T be empty. Repeat: For each subset X of the attributes of R , compute X + with The FDs in B all have singleton right sides. 1 If a FD can be inferred from the other FDs in S', remove it. + If any FD is removed from B, the consequences of those respect to S and add X A to T for each attribute A in X If FD1 = A . A B and FD2 is the same with A that is also an attribute of R . that are left do not equal the consequences of S. 1 m i 1 removed for some i and FD2 can be inferred from S', If any attribute is removed from the left side of any FD in It is recommended that a minimal basis be computed for T. B, the consequences of the altered B do not equal the remove FD1 from S' and add FD2. Note that the proof that a FD belongs to T may refer to consequences of S. Until S' cannot be changed anymore. attributes of R that are not attributes of R . 1 7 8 9 Anomalies Anomalies(cont.) Normalization The main source of maintenance problems is requiring that too Insertion anomaly – When we input information about one Anomalies are reduced by decomposing a table into two or much information be stored in each row of a table, usually object, we are forced to input information about another more tables so that certain conditions are satisfied. A table because each row describes the properties of more than one object as well. that satisfies those conditions are said to be in normal form . object. Deletion anomaly – When delete all information about one Commonly used normal forms are: Redundancy – The same information about one object is object, we may delete information about another object as Boyce-Codd Normal Form (BCNF) stored in more than one row (because the object is related to well. (The information about the second object only more than one other object). appears in rows that contain the information about the first Third Normal Form object.) Update anomaly - When information about one object is Fourth Normal Form updated in one row, it may not be updated in all the other (Others exist: Fifth Normal Form, Domain Key Normal Form, rows where it exists. Project-Join Normal Form.) [gearhead] 10 11 12 First & Second Normal Forms Decomposition Boyce-Codd Normal Form A relation is in First Normal Form if its attribute domains If a relation is not in a desired advanced normal form, it is A relation R is in Boyce-Codd Normal Form if the left side of contain only atomic values (the values have no internal decomposed into two or more relations, each of which is in every nontrivial functional dependency for R is a superkey structure of interest to us). the desired advanced normal form. for R. (It is easy to set up a database so that all relations are in First A set of relations {R , ..., R } is a decomposition of a relation 1 n This avoids redundancy: suppose AB C, B D. The Normal Form from the beginning.) R if each R is a projection from R and the union of the relation R(A,B,C,D) is not in Boyce-Codd Normal Form. i A relation is in Second Normal Form if each attribute is either attributes for all the relations in the set equals the set of A | B | C | D A | B | C B | D in a key for the relation or is functionally determined only attributes for R. by one or more keys for the relation. (No attribute not in a 1 | 1 | 2 | 4 de- 1 | 1 | 2 1 | 4 key is functionally determined by a proper subset of a key.) 1 | 2 | 3 | 6 com- 1 | 2 | 3 2 | 6 (More advanced normal forms will imply that a relation is also 2 | 1 | 1 | 4 pose: 2 | 1 | 1 in Second Normal Form.) [gearhead] 2 | 2 | 4 | 6 2 | 2 | 4 13 14 15 Computing BCNF Testing X Y Lossless Joins Given a relation R(A , . ., A ) and set S of its functional + + The decomposition produced by the previous algorithm has 1 n To test whether X is a superkey for R, compute X . If X does dependencies. not contain all the attributes of R, X is not a superkey and the property that it has a lossless join , that is, the natural join the FD X Y violates the conditions for BCNF. of the relations in the decomposition reproduces the original Test the FDs in S until one is found, say X Y, where X is relation. (No information is lost.) not a superkey for R. (If none found, stop.) Example where join is not lossless: Replace R and S with R (X +) and the projection of S down to 1 A | B | C A | B B | C A | B | C R , and R (((A , . ., A ) − (X + − X)) and the projection of S 1 2 1 n 1 | 2 | 3 1 | 2 2 | 3 1 | 2 | 3 down to R . 2 4 | 2 | 6 4 | 2 2 | 6 1 | 2 | 6 Repeat the above on R and R with their sets of functional 1 2 4 | 2 | 3 dependencies. 4 | 2 | 6 16 [gearhead] 17 18 Chase Test Chase Test Example FDs Can Be Lost Given R(L) decomposed into R (L ), i = 1,...,k. For each i, i i Given R(A,B,C,D), FDs A B, B C, CD A. R is Given R(A,B,C) with FDs AB C, C A. Decompose R make a tuple t for R such that for each attribute A in L , the decomposed into R (A,D), R (A,C), R (B,C,D). into Boyce-Codd Normal Form relations. i i 1 2 3 value of A in t is a, and the other values in t are distinct t = < a, X1, X2, a > R (C, A) with FD C A i i 1 1 variables. t = < a, X3, a, X4> R (B,C) with no FDs Use the FDs for R to infer what values the variables have to 2 2 be. If the tuple < a,..., a> can be derived, the decomposition t = <X5, a, a, a> FD AB C has been lost. 3 has the lossless join property. If it can't be derived, the variables can be given non- a values so that the original t s Tuple < a, a , a, a> can be deduced. i form an instance of R that is not reproduced by the natural join of the R s. i 19 20 21 Third Normal Form 3NF Synthesis Algorithm Multivalued Dependencies A relation R is in Third Normal Form if the left side of every Given relation R and a minimal basis S of the FDs for R.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages6 Page
-
File Size-