Presentation is loading. Please wait.

Presentation is loading. Please wait.

Design Theory.

Similar presentations


Presentation on theme: "Design Theory."— Presentation transcript:

1 Design Theory

2 Overview Starting Point: Set of functional dependencies that describe real-world constraints Goal: Create tables that do not contain redundancies, so that there is less wasted space there is less of a chance to introduce errors in the database

3 Design Theory Armstrong's axioms defined, so that we can derive functional dependencies Need to identify a key: find a single key find all keys Both algorithms use as a subroutine an algorithm that computes the closure.

4 Closure of a Set of Attributes
Let U be a set of attributes and F be a set of functional dependencies on U. Suppose that X  U is a set of attributes. Definition: X+ = { A | F X  A} We would like to compute X+ |=

5 Algorithm From Class Compute Closure(X, F) C := X
While there is a V  W in F such that (V  C)and (W  C) do C := C  W 3.Return C Complexity?

6 Example R=ABCDE F={ABC, CEB, DA, BCE} {A}+ = {A,B}+ = {B,D}+=

7 Important Decomposition Characteristics

8 Lossless Join Decomposition has a lossless-join property if the natural join of projections is always equal to the original relation. Necessary, otherwise original relation cannot be recreated, even if tables are not modified.

9 Dependency Preservation
Decomposition is dependency preserving if F can be recovered from the projections. Allows us to check that inserts/updates are correct without joining the sub-relations.

10 What about This Decomposition?
Smith DB Cohen Jones OS Levy F = {C  T} C S DB Cohen OS Levy T S Smith Cohen Jones Levy

11 And This?… T C S Smith DB Cohen Algo Katz Jones OS Levy F = {C  T} T

12 And This? T C S Smith DB Cohen Algo Katz Jones OS Levy F = {C  T} C S

13 Checking Decomposition Properties
Check for a lossless join using the algorithm from class (a’s and b’s). Check for dependency preserving using an algorithm shown today.

14 Dependency Preservation
R=ABC Dependencies {AB, BC} Decomposition {AB, AC} Is it lossless? Does it preserve BC?

15 Dependency Preservation (cont’d)
B A 100 10 1 2 200 20 3 B A 10 1 2 20 3 4 C A 100 1 2 200 3 300 4

16 Definition (1) Let R1...Rk be a decomposition of R We define Ri (F) to be the set of dependencies XY in F+ such that X and Y are in Ri

17 Definitions (2) We say that R1...Rk of R is dependency preserving if: (R1 (F) U ... U Rk (F))+ = F+ Note that one inclusion clearly always holds.

18 Algorithm (1) /* check if X->Y is preserved */
IsPreserved(X,Y,R1…k) Z:=X while changes to Z occur do for i=1 to k do Z:= Z  ((Z  Ri)+  Ri) if YZ return true else return false

19 Algorithm(2) IsDependencyPreserving(F,R1…k) for each X->Y in F do
if not IsPreserved(X,Y,R1…k) return false return true

20 Example (1) R=ABCD F = {A -> B, B -> C, C -> D, D -> A}
R1=AB, R2=BC, R3=CD Is this decomposition dependency preserving?

21 Example (2) R = ABCDE F = {A -> ABCDE, BC -> A, DE -> C}
R1 = ABDE, R2 = DEC Is this decomposition dependency preserving?

22 Minimal Cover

23 Minimal Cover(1) F is called minimal if:
If XY is in F then Y is a single attribute If XA is in F then F - {XA} is not equivalent to F If XA is in F and Z is in X, then F – {XA} U {ZA} is not equivalent to F

24 Minimal Cover(2) If G+ = F+ and G is minimal then G is called a minimal cover of F A minimal cover always exist for a set of functional dependencies

25 Computing a Minimal Cover
3 Steps: We may assume that all right sides in F are singletons (why??) For each XA in F and for each B in X, check if F |= X\B  A. If so, substitute XA with X\BA For each XA in F, check if F - {XA} |= XA. If so, remove XA

26 Normal Forms

27 The Basic Idea If a relation R with functional dependencies F is in a normal form, then certain problems can be avoided (e.g., redundancy)

28 Boyce-Codd Normal Form (BCNF)
Every dependency XA in F+ must be either Trivial, or X is a super-key for R

29 Third Normal Form (3NF) For every dependency XA in F+ one of the following must hold: XA is trivial X is a super-key for R A is an attribute of a key for R

30 Example Suppose that R = ABC. For each of the following, decide whether R is in BCNF/3NF: F = {} F = {A -> B} F = {A -> B, A -> C} F = {A -> B, B -> C} F = {A -> B, BC -> A}

31 Decomposition into 3NF (1)
Given a relation R with functional dependencies F (assume w.l.o.g. that F is minimal): Step 1: For each XA in F, create a sub-scheme XA Step 2: If no sub-scheme created so far contains a key, add a key as a sub-scheme

32 Decomposition into 3NF (2)
Step 3: Remove sub-schemes that are contained in other sub-schemes The result is a decomposition into 3NF that is dependency preserving and has a lossless join

33 Example (1) Find a decomposition into 3NF for the relational scheme R = ABCDEFGH, with the functional dependencies F = {AB, ABCDE, EFGH, ACDFEG}

34 Example (2) Minimal cover G = {AB, ACDE, EFG, EFH} Key ACDF
Decomposition: AB, ACDE, EFG, EFH, ACDF

35 Decomposition into BCNF
There always exists a decomposition into BCNF that has a lossless join There does not always exist a decomposition into BCNF that is dependency preserving Example: Consider the relation SBD (sailor, boat, date) with the F = {SBD, DB} There exists a polynomial algorithm for finding such a decomposition


Download ppt "Design Theory."

Similar presentations


Ads by Google