Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC-310 Database Systems

Similar presentations


Presentation on theme: "CPSC-310 Database Systems"— Presentation transcript:

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

2 Computing Closure Computing the closure Y+ of a set Y of attributes.
Algorithm Closure(Y) 1. Y+ = Y; 2. While changes Do 2.1 look for an FD X → B where X is a subset of Y+ but B is not in Y+; 2.2 add B to Y+; 3. every A in Y+\Y satisfies Y → A Y+ new Y+ X A It can be proved that the Algorithm Closure(Y) finds exactly those FDs Y → A implied by the given FDs.

3 Eliminating bad FD X → A (for all A)
Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

4 Normalization Algorithm
Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T.

5 Normalization Algorithm
Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T. 1. For each subset Y of Z Do construct Y+;

6 Normalization Algorithm
Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T. 1. For each subset Y of Z Do construct Y+; 2. Record the superkeys and keys Y for R (Y+=Z);

7 Normalization Algorithm
Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T. 1. For each subset Y of Z Do construct Y+; 2. Record the superkeys and keys Y for R (Y+=Z); 3. If there is a subset Y of Z such that Y+≠ Z and Y+≠ Y \\ Y → A is a bad FD for some A

8 Normalization Algorithm
Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T. 1. For each subset Y of Z Do construct Y+; 2. Record the superkeys and keys Y for R (Y+=Z); 3. If there is a subset Y of Z such that Y+≠ Z and Y+≠ Y \\ Y → A is a bad FD for some A Then 3.1 Call Decomposition(Y) to decompose the relation R into two smaller relations R1 and R2;

9 Normalization Algorithm
Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T. 1. For each subset Y of Z Do construct Y+; 2. Record the superkeys and keys Y for R (Y+=Z); 3. If there is a subset Y of Z such that Y+≠ Z and Y+≠ Y \\ Y → A is a bad FD for some A Then 3.1 Call Decomposition(Y) to decompose the relation R into two smaller relations R1 and R2; 3.2 Call Decomposed-FDs(Rk) for k = 1, 2 to construct the FD sets T1 for R1 and T2 for R2;

10 Normalization Algorithm
Algorithm Normalization(R, T) Input: A relation R with attribute set Z and FD set T. 1. For each subset Y of Z Do construct Y+; 2. Record the superkeys and keys Y for R (Y+=Z); 3. If there is a subset Y of Z such that Y+≠ Z and Y+≠ Y \\ Y → A is a bad FD for some A Then 3.1 Call Decomposition(Y) to decompose the relation R into two smaller relations R1 and R2; 3.2 Call Decomposed-FDs(Rk) for k = 1, 2 to construct the FD sets T1 for R1 and T2 for R2; Example. R(A, B, C, D, E) T = {AB → D, AC → E, BC → D, D → A, E → B}

11 Eliminating bad FD X → A (for all A)
Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

12 Eliminating bad FD X → A (for all A)
Remarks. Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

13 Eliminating bad FD X → A (for all A)
Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

14 Eliminating bad FD X → A (for all A)
Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: * X→A is still an FD in R1=(X+) but now X is a superkey for R1; Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

15 Eliminating bad FD X → A (for all A)
Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: * X→A is still an FD in R1=(X+) but now X is a superkey for R1; * X→A is not FD in R2=(X∪W) because A is not in X∪W. Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

16 Eliminating bad FD X → A (for all A)
Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: * X→A is still an FD in R1=(X+) but now X is a superkey for R1; * X→A is not FD in R2=(X∪W) because A is not in X∪W. Does Decomposition(X) change (i.e., lose or add extra) information for R? Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

17 Eliminating bad FD X → A (for all A)
Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: * X→A is still an FD in R1=(X+) but now X is a superkey for R1; * X→A is not FD in R2=(X∪W) because A is not in X∪W. Does Decomposition(X) change (i.e., lose or add extra) information for R: No. Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

18 Eliminating bad FD X → A (for all A)
Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: * X→A is still an FD in R1=(X+) but now X is a superkey for R1; * X→A is not FD in R2=(X∪W) because A is not in X∪W. Does Decomposition(X) change (i.e., lose or add extra) information for R: No. Can R1 and R2 still have bad FDs? Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

19 Eliminating bad FD X → A (for all A)
Remarks. Algorithm Decomposition(X) eliminates the bad FD X→A: * X→A is still an FD in R1=(X+) but now X is a superkey for R1; * X→A is not FD in R2=(X∪W) because A is not in X∪W. Does Decomposition(X) change (i.e., lose or add extra) information for R: No. Can R1 and R2 still have bad FDs: Yes. Algorithm Decomposition(X) 1. Compute S1 = X+ using the FDs in R; 2. Let W be the set of attributes that are not in S1; 3. Make a relation R1 of schema S1; 4. Make a relation R2 with schema S2 = X ∪ W; 5. Compute the FDs for R1 and R2. Algorithm Decomposed-FDs(R1) 1. T1 = ; \\ T1 is the FDs for R1 2. For each subset Y of S1 Do 2.1 compute Y+ using the FDs in R; 2.2 For each A in S1∩(Y+\Y) add Y → A to T1; 3. While changes Do 3.1 Drop from T1 those FDs that are derivable from the others; 3.2 For each XB → A in T1, if X → A is implied by T1, then replace XB → A in T1 by X → A.

20 Boyce-Codd Normal Form (BCNF)
Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey.

21 Boyce-Codd Normal Form (BCNF)
Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.)

22 Boyce-Codd Normal Form (BCNF)
Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 1. Likes(drinker, addr, zip, beer, manf) FD’s: T = {drinker → addr, addr → zip, beer → manf}

23 Boyce-Codd Normal Form (BCNF)
Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 1. Likes(drinker, addr, zip, beer, manf) FD’s: T = {drinker → addr, addr → zip, beer → manf} The only key is {drinker, beer}.

24 Boyce-Codd Normal Form (BCNF)
Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 1. Likes(drinker, addr, zip, beer, manf) FD’s: T = {drinker → addr, addr → zip, beer → manf} The only key is {drinker, beer}. In each FD, the left side is not a superkey.

25 Boyce-Codd Normal Form (BCNF)
Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 1. Likes(drinker, addr, zip, beer, manf) FD’s: T = {drinker → addr, addr → zip, beer → manf} The only key is {drinker, beer}. In each FD, the left side is not a superkey. Any one of these FD’s shows Likes is not in BCNF

26 Boyce-Codd Normal Form (BCNF)
Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 2. Beers(name, manf, manfAddr) FD’s: T = {name → manf, manf → manfAddr}

27 Boyce-Codd Normal Form (BCNF)
Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 2. Beers(name, manf, manfAddr) FD’s: T = {name → manf, manf → manfAddr} The only key is {name}.

28 Boyce-Codd Normal Form (BCNF)
Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 2. Beers(name, manf, manfAddr) FD’s: T = {name → manf, manf → manfAddr} The only key is {name}. name → manf does not violate BCNF.

29 Boyce-Codd Normal Form (BCNF)
Definition. A relation R is in Boyce-Codd Normal Form (BCNF) if every nontrivial FD X→A (i.e., AX) has its left side X a superkey. (Thus, a relation in BCNF has no bad FDs.) Example 2. Beers(name, manf, manfAddr) FD’s: T = {name → manf, manf → manfAddr} The only key is {name}. name → manf does not violate BCNF. However, manf → manfAddr violates BCNF.


Download ppt "CPSC-310 Database Systems"

Similar presentations


Ads by Google