Download presentation

Presentation is loading. Please wait.

Published byStephen Buckles Modified about 1 year ago

1
1 Design Theory

2
2 Minimal Sets of Dependancies A set of dependencies is minimal if: 1.Every right side is a single attribute 2.For no X A in F and proper subset Z of X is F – {X A} U {Z A} equivalent to F. 3.For no X A in F is the set F – {X A} equivalent to F If G is equivalent to F and G is minimal, we say that G is a minimal cover of F

3
3 Finding Minimal Covers 1.Replace each FD of the form X A 1...A n with n FDs:X A 1,..., X A n 2.For each FD A 1...A n B and each attribute A i if F – {A 1...A n B} U {A 1...A i-1 A i+1...A n B} is equivalent to F, then delete A i from the left side. How do we check this? It is enough to check if F implies A 1...A i-1 A i+1...A n B. Why?

4
4 Finding Minimal Covers (cont) 3.For each FD X A, if F – {X A} is equivalent to F, then delete X A How do we check this? It is enough to check if F – {X A} implies X A. Why?

5
5 Example Find a minimal cover for: AB CD EG CACABE C BC DCG BD ACD BCE AG

6
6 Normal Form of a Schema A schema S is in BCNF if for every FD X Y that holds in S, –Y is a subset of X or –X is a super-key (i.e., X contains a key) If this is not the case, our schema may be problematic. Example: Sup_Info(name, address, item, price) name address name, item price

7
7 Decompositions A decomposition of a schema R is a set R 1...R n such that –R 1 is contained in R –R = R 1 U... U R n We may decompose a schema so that it will be a set of schemas all in BCNF. Not every decomposition is good. Can you find a trivial decomposition to BCNF?

8
8 Lossless Join Decompositions A decomposition R 1...R n of R is lossless if for all instances r of R that satisfy the FDs of R: r = R 1 (r) ... R n (r) Checking if a decomposition is lossless: Create a table with a column for each attribute and a row for each sub-schema In row i and column k, put a symbol a k if the attribute of column k is in the schema of row i. Otherwise, put b ik

9
9 Lossless Join Decompositions (2) While there is a dependency X A in F such that there are 2 rows that have the same values in X and differ in A do: –Choose one of the values. (if one is an a-value, then it must be chosen) –Make all the occurrences of the other value equal to the chosen value If the resulting relation has a row of all a-s, then the decomposition has a lossless join

10
10 Example R = ABCDE, R 1 = AD, R 2 = AB, R 3 = BE, R 4 = CDE, and R 5 = AE Functional dependencies: –A C –B C –C D –DE C –CE A

11
11 Example ABCDE a1a1 b 12 b 13 a4a4 b 15 a1a1 a2a2 b 23 b 24 b 25 b 31 a2a2 b 33 b 34 a5a5 b 41 b 42 a3a3 a4a4 a5a5 a1a1 b 52 b 53 b 54 a5a5

12
12 Decompositions that Preserve Dependencies Problem: Suppose that we decompose R and then insert rows into the decomposition. Is it possible that the join of these rows will contradict a FD? Example: R = CSZ (city, street, zip-code) then, CS Z, Z C hold in R. Suppose we decompose into SZ and CZ. This is lossless. However, we can contradict CS Z

13
13 Definitions We define Z (F) to be the set of dependencies X Y in F + such that X and Y are in Z. We say that a decomposition R 1...R n of R is dependency preserving if for all instances r of R that satisfy the FDs of R: R 1 (F) U... U R n (F) implies F Note that the other direction of implication clearly holds always.

14
14 Testing Dependency Preservation To check if the decomposition preserves X Y: Z:=X while changes to Z occur do for i:=1..n do Z:=Z U ((Z R i ) + R i ) /*closure w.r.t. F*/ Return true if Y is contained in Z U U

15
15 Example Suppose R=ABCD and we have a decomposition {AB, BC, CD}, and dependencies {A B, B C, C D, D A}. Does this decomposition preserve D A?

16
16 Goal Given a schema R, we would like to check if R is in BCNF (How?). –If yes, good –If not, try to find a decomposition of R that has a lossless join and is dependency preserving. Is this always possible? –lossless join: yes –dependency preserving: no

17
17 Decomposing to BCNF Lemma: 1.Every 2-attribute schema is in BCNF 2.If R is not in BCNF, then we can find attributes A and B in R such that (R – AB) A Proof: 1.Easy 2.Suppose that R is not in BCNF. Then there is a FD X A that violates the BCNF condition. Then, A is not in X and there is an attribute B other then A not in X (otherwise, X is a key).

18
18 Algorithm for Lossless Join, BCNF Decomposition Algorithm in handout. Example: Relation CTHRSG (course, teacher, hour, room, student, grade), FDs: –C T –HR C –HT R –CS G –HS R

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google