Functional Dependencies Getting a good DB design Lisa Ball November 2012
Outline (2012) SEE NEXT SLIDE FOR ALL TOPICS (some for you to read) Normalization covered by Dr Sanchez Armstrong s Axioms other axioms that can be proven from Closure {} + uses Armstrong s axioms to find all valid f.d. s Minimal Set Closure Equivalence show equivalence of 2 sets of f.d.s Lossless joins (2 tables only) prevents spurious (incorrect) rows on joins 2
Topics Chapter 15 Normalization (covered in other lectures) Informal Design Guidelines (15.1) Introduction to Functional Dependencies (15.2) basic idea Normalization (15.3, 15.4) 2NF (no partial dependencies) 3NF (no transitive dependencies) Chapter 16 Functional Dependencies Functional Dependency Inference Rules (16.1.1) Armstrong s Axioms & other axioms that can be proven from Closure {} + uses axioms to find all valid f.d. s Equivalence (16.1.2) show equivalence of 2 sets of f.d.s Minimal Sets (16.1.3) Lossless joins: 2 tables only (16.2.4) prevents spurious (incorrect) rows on joins Algorithms for Relational DB Schema Design to 3NF (16.3.1) NULLS, Dangling Tuples, and Alternative Relational Designs (16.4) 3
Chapter 15 & Comment on Ch 16 Dr Ball s absence (2012) Covered by Dr Sanchez Some of our chapter 16 topics started out of order this year (2012). closure & minimal cover covered before Additional axioms (IR4-6) let s do topics in same order as text some will be repeat 4
Some Normalization Comments (a look back-ch 15) Examples VIN Make, Model, Color ISBN Title SSN Name (but not address- e.g. spouses) Sample data only proves FD s that do NOT hold A B C D A B? No. Look at Y-X & Y-Z X U X Y Y X Z X Z Y Y Y Y Z W Z A C No A D No D? No??? Can t tell B,C (all vals unique) 6
Armstrong s Axioms (inference rules) for FD s (IR1) Reflexive Rule If Y X, X Y attributes determine themselves (IR2) Augmentation Rule X Y XZ YZ (or XZ Y) adding attributes on both sides yields another valid f.d. (IR3) Transitive Rule X Y, Y Z X Z Provided our initial f.d. s are sound, these rules are sound (find only valid new f.d. s) and complete (can find all valid f.d. s) 7
Additional Provable Axioms (FD s) Additional Axioms Decomposition (projective) X YZ X Y Union (additive) X Y, X Z Pseudotransitive X Y, WY Z X YZ WX Z Given with proofs in text, pages 546-547 you should be able to do, along with others 8
Disproof of Axioms (FD s) Does this follow from the axioms? just be able to show one disproof example X Z, Y Z X Y??? Just have to show 1 disproof you should be able to do, along with others X Y Z A D R This satisfies lhs, NOT rhs (X Y ) A E R B E R 9
Closure of a set of f.d. s: F + Definition: Closure the set of all fd s that include F (given) and all dependencies that can be inferred from F Use axioms (inference rules) to derive F + (closure) For each lhs, find closure (loop through) alg. 16.1 Let s look at examples. Also in text (employee, project, hours) Why? only way to determine if 2 sets of f.d. s are equivalent we start with semantically obvious ones we want smaller set in normalization algorithms 10
Closure Examples Paper copies for now 2012 (already covered) you: go practice some more, now using all 6 inference rules 11
Equivalence of 2 sets of f.d. s E B A D A AB D try to remove lhs attr s B + = {A,B,D} D + = {A,D} AB + = {A,B,D} Are these covered by F? YES F B D D A try to remove lhs attr s B + = {A,B,D} D + = {A,D} Are these covered by E? YES 12
Minimal Set (Cover) No redundancies in standard form different sets lead to different schema designs. we want minimal set before we normalize simplest schema design 3 conditions single attribute on each rhs can t remove any f.d. and still have equivalence (same closure) can t remove any lhs attr s and still have equivalence 2012: largely covered (use axioms) 13
Lossless Joins: 2 tables. Lossless joins: 2 tables only (16.2.4) prevents spurious (incorrect) rows on joins Algorithms exists for > 2 tables we don t cover thesee 14
Testing for Lossless Joins: 2 tables. PROPERTY LJ1 (lossless join test for binary decompositions): A decomposition D = {R1, R2} of R has the lossless join property with respect to a set of functional dependencies F on R if and only if either The f.d. ((R1 R2) (R1- R2)) is in F +, or The f.d. ((R1 R2) (R2 - R1)) is in F +. 15
Lossless Joins: Example see text for now 16
EXAMPLES & EXTERNAL SOURCES SECTION 17
Examples & Sources Textbook course Page: Sample Exams Youtube: Univ. Houston Clear Lake 18