DAVID DENG CS157B MARCH 23, 2010 Dependency Preserving Decomposition.

Slides:



Advertisements
Similar presentations
Schema Refinement: Normal Forms
Advertisements

Schema Refinement: Canonical/minimal Covers
Functional Dependencies- Examples
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
Lecture 21 CS 157 B Revision of Midterm3 Prof. Sin-Min Lee.
Logical Database Design (3 of 3) John Ortiz. Lecture 7Logical Database Design (2)2 Normalization  If a relation is not in BCNF or 3NF, we refine it by.
CS 440 Database Management Systems Practice problems for normalization.
Review for Final Exam Lecture Week 14. Problems on Functional Dependencies and Normal Forms.
Normalization theory exercises Dr. Shiyong Lu Department of Computer Science Wayne State University ©copyright 2007, all rights reserved.
1 Design Theory. 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.
Properties of Armstrong’s Axioms Soundness All dependencies generated by the Axioms are correct Completeness Repeatedly applying these rules can generate.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 227 Database Systems I Design Theory for Relational Databases.
CS Algorithm : Decomposition into 3NF  Obviously, the algorithm for lossless join decomp into BCNF can be used to obtain a lossless join decomp.
Classroom Exercise: Normalization
Relational Design. DatabaseDesign Process Conceptual Modeling -- ER diagrams ER schema transformed to relational schema Designer may add additional integrity.
Lossless Decomposition Elias Aseged SE 157B - DB 2.
1 Introduction to Database Systems CSE 444 Lectures 8 & 9 Database Design April 16 & 18, 2008.
Normal Form Design addendum by C. Zaniolo. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Normal Form Design Compute the canonical cover.
Design Theory.
1 Normalization Chapter What it’s all about Given a relation, R, and a set of functional dependencies, F, on R. Assume that R is not in a desirable.
The principal problem that we encounter is redundancy, where a fact is repeated in more than one tuple. Most common cause: attempts to group into one relation.
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 9.
Decomposition By Yuhung Chen CS157A Section 2 October
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #7 Matthew P. Johnson Stern School of Business, NYU Spring,
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
Cs3431 Normalization Part II. cs3431 Attribute Closure : Example Consider R (A, B, C, D, E) with FDs A  B, B  C, CD  E Does A  E hold ? (Is A  E.
Boyce-Codd NF & Lossless Decomposition Professor Sin-Min Lee.
Fall 2001Arthur Keller – CS 1804–1 Schedule Today Oct. 4 (TH) Functional Dependencies and Normalization. u Read Sections Project Part 1 due. Oct.
1 Triggers: Correction. 2 Mutating Tables (Explanation) The problems with mutating tables are mainly with FOR EACH ROW triggers STATEMENT triggers can.
Multi-valued Dependencies and Fourth Normal Form
Normal Forms1. 2 The Problems of Redundancy Redundancy is at the root of several problems associated with relational schemas: Wastes storage Causes problems.
Schema Refinement and Normalization. Functional Dependencies (Review) A functional dependency X  Y holds over relation schema R if, for every allowable.
CS143 Review: Normalization Theory Q: Is it a good table design? We can start with an ER diagram or with a large relation that contain a sample of the.
Lecture 09: Functional Dependencies. Outline Functional dependencies (3.4) Rules about FDs (3.5) Design of a Relational schema (3.6)
SCUJ. Holliday - coen 1784–1 Schedule Today: u Normal Forms. u Section 3.6. Next u Relational Algebra. Read chapter 5 to page 199 After that u SQL Queries.
THIRD NORMAL FORM (3NF) A relation R is in BCNF if whenever a FD XA holds in R, one of the following statements is true: XA is a trivial FD, or X is.
R EVIEW. 22 Exam Su 3:30PM - 6:30PM 2010/12/12 Room C9000.
Functional Dependencies. FarkasCSCE 5202 Reading and Exercises Database Systems- The Complete Book: Chapter 3.1, 3.2, 3.3., 3.4 Following lecture slides.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
Minimum Cover of F. Minimal Cover for a Set of FDs Minimal cover G for a set of FDs F: –Closure of F = closure of G. –Right hand side of each FD in G.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.
Multivalued Dependencies and 4th NF CIS 4301 Lecture Notes Lecture /21/2006.
CS 222 Database Management System Spring Lecture 4 Database Design Theory Korra Sathya Babu Department of Computer Science NIT Rourkela.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
© D. Wong Functional Dependencies (FD)  Given: relation schema R(A1, …, An), and X and Y be subsets of (A1, … An). FD : X  Y means X functionally.
Algorithm of Compute F+
Copyright © Curt Hill Schema Refinement II 2 nd NF to 3 rd NF to BCNF.
1 Lecture 9: Database Design Wednesday, January 25, 2006.
Normalization and FUNctional Dependencies. Redundancy: root of several problems with relational schemas: –redundant storage, insert/delete/update anomalies.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
Formal definition of a key A key is a set of attributes A 1,..., A n such that for any other attribute B: A 1,..., A n  B A minimal key is a set of attributes.
CS 440 Database Management Systems
Relational Database Design (Discussion Session)
Normalization First Normal Form (1NF) Boyce-Codd Normal Form (BCNF)
CS 480: Database Systems Lecture 22 March 6, 2013.
Plan for Today Normal forms
Dependency Preservation
How to test Whether Subschemes in BCNF??
Cse 344 May 16th – Normalization.
Introduction to Database Systems CSE 444 Lectures 8 & 9 Database Design October 12 & 15, 2007.
Lecture 09: Functional Dependencies, Database Design
Lecture 07: E/R Diagrams and Functional Dependencies
Some slides are from Dr. Sara Cohen
Relational Database Design
CSC 453 Database Systems Lecture
Quiz 2 Let R(A,B,C,D) be a relation schema with
Lecture 09: Functional Dependencies
CS4222 Principles of Database System
Presentation transcript:

DAVID DENG CS157B MARCH 23, 2010 Dependency Preserving Decomposition

Intro Decomposition help us eliminate redundancy, root of data anomalies. Decomposition should be:  1. Lossless  2. Dependency Preserving

What’s Dependency Preservation? When the decomposition of a relational scheme preserved the associated set of functional dependencies. Formal Definition: If R is decomposed into R1, R2,…, Rn, then {F1  F2  …  Fn} + = F +

Algorithm to check for Dependency Preservation begin; for each X  Y in F and with R (R1, R2, …, Rn) { let Z = X; while there are changes in Z { from i=1 to n Z = Z  ((Z  Ri) +  Ri) w.r.t to F; } if Y is a proper subset of Z, current fd is preserved else decomposition is not dependency preserving; } this is a dependency preserving decomposition; end;

Explain Algorithm Part 1 1. Choose a functional dependency in set F, say you choose X  Y. 2. Let set Z to the “left hand side” of the functional dependency, X such Z = X Starting with R1 in the decomposed set {R1, R2,…Rn) 3. Intersect Z with R1, Z  R1 4. Find the closure of the result from step 3 (Z  R1) using original set F 5. Intersect the result from step 4 ((Z  R1) + ) with R1 again.

Explain Algorithm Part 2 6. Updated Z with new attribute in the result from step Repeat step 3-6 from R2, R3, …, Rn. 8. If there’s any changes between original Z before step 3 and after step 7, repeat step Check whether Y is a proper subset of current Z. If it is not, this decomposition is a violation of dependency preservation. You can stop now. 10. If Y is a proper subset of current Z, repeat 1-9 until you check ALL functional dependencies in set F.

Another look at Algorithm Test each X  Y in F for dependency preservation result = X while (changes to result) do for each Ri in decomposition t = (result  Ri)+  Ri result = result  t if Y  result, return true; else, return false; [Note: If any false is returned for algorithm, whole decomposition is not dependency preserving.]

Let’s walk through an example of using this algorithm.

Example using Algorithm Given the following: R(A,B,C,D,E) F = {AB  C, C  E, B  D, E  A} R1(B,C,D)R2(A,C,E) Is this decomposition dependency preserving?

Example R(A,B,C,D,E)F = {AB  C, C  E, B  D, E  A} Decomposition:R1(B,C,D)R2(A,C,E) Z=AB For Z  R1 = AB  BCD = B {B} + = BD {B} +  R1 = BD  BCD = BD Update Z = AB  BD = ABD, continue

Example R(A,B,C,D,E)F = {AB  C, C  E, B  D, E  A} Decomposition:R1(B,C,D)R2(A,C,E) Z=ABD For Z  R2 = ABD  ACE = A {A} + = A {A} +  R2 = A  ACE = A Update Z, Z is still ABD Since Z changed, repeat checking R1 to R2.

Example R(A,B,C,D,E)F = {AB  C, C  E, B  D, E  A} Decomposition:R1(B,C,D)R2(A,C,E) Z=ABD For Z  R1 = ABD  BCD = BD {BD} + = BD {BD} +  R1 = BD  BCD = BD Update Z = ABD  BD = ABD, so Z hasn’t changed but you still have to continue.

Example R(A,B,C,D,E)F = {AB  C, C  E, B  D, E  A} Decomposition:R1(B,C,D)R2(A,C,E) Z=ABD and checking R2 was done 2 slides ago Z will still be ABD. Since Z hasn’t change, you can conclude AB  C is not preserved. Let’s practice with other functional dependencies.

Example R(A,B,C,D,E)F = {AB  C, C  E, B  D, E  A} Decomposition:R1(B,C,D)R2(A,C,E) Z=X=B For Z  R1 = B  BCD = B {B} + = BD {B} +  R1 = BD  BCD = BD Update Z = B  BD = BD Since Y=D is proper subset of BD, B  D is preserved.

Example R(A,B,C,D,E)F = {AB  C, C  E, B  D, E  A} Decomposition:R1(B,C,D)R2(A,C,E) Z=X=C For Z  R2 = C  ACE = C {C} + = CEA {C} +  R1 = CEA  ACE = ACE Update Z = C  ACE= ACE Since Y=E is proper subset of ACE, C  E is preserved.

Example R(A,B,C,D,E)F = {AB  C, C  E, B  D, E  A} Decomposition:R1(B,C,D)R2(A,C,E) Z=X=E For Z  R1 = E  ACE = E {E} + = EA {E} +  R1 = EA  ACE = EA Update Z = E  EA= EA Since Y=A is proper subset of EA, E  A is preserved.

Example R(A,B,C,D,E)F = {AB  C, C  E, B  D, E  A} Decomposition:R1(B,C,D)R2(A,C,E) Shortcut: For any functional dependency, if both LHS and RHS collectively are within any of the sub scheme Ri. Then this functional dependency is preserved.

Exercise #1 Let R{A,B,C,D} and F={A  B, B  C, C  D, D  A} Let’s decomposed R into R1 = AB, R2 = BC, and R3 = CD Is this a dependency preserving decomposition?

Answer to Exercise #1 Yes it is. You can immediately see that A  B, B  C, C  D are preserved for R1, R2, R3 The key is to check whether D  A is preserved. Let’s walk through the algorithm. R{A,B,C,D} F={A  B, B  C, C  D, D  A} Decomposition: R1 = AB, R2 = BC, and R3 = CD

Answer to Exercise #1 Z = X = D For Z  R1 = D  AB = empty set For Z  R2 = D  BC = empty set For Z  R3 = D  CD = D Find {D} + = DABC Find {D} +  R3 = DABC  CD = CD Update Z to CD. Since Z changed, repeat. R{A,B,C,D} F={A  B, B  C, C  D, D  A} Decomposition: R1 = AB, R2 = BC, and R3 = CD

Answer to Exercise #1 Z = CD For Z  R1 = CD  AB = empty set For Z  R2 = CD  BC = C Find {C} + = CDAB Find {C} +  R2 = CDAB  BC = BC Update Z = CD  BC = BCD R{A,B,C,D} F={A  B, B  C, C  D, D  A} Decomposition: R1 = AB, R2 = BC, and R3 = CD

Answer to Exercise #1 Z = BCD For Z  R3 = BCD  CD = CD Find {CD}+ = CDAB Find {CD}+  R3 = CDAB  CD = CD Update Z is still BCD. Since Z changed, repeat going trough R1 to R3. R{A,B,C,D} F={A  B, B  C, C  D, D  A} Decomposition: R1 = AB, R2 = BC, and R3 = CD

Answer to Exercise #1 Z = BCD For Z  R1 = BCD  AB = B Find {B} + = BCDA Find {B} +  R1 = BCDA  AB = AB Update Z = BCD  AB = ABCD. Since Y = A is a subset of ABCD, function D  A is preserved. R{A,B,C,D} F={A  B, B  C, C  D, D  A} Decomposition: R1 = AB, R2 = BC, and R3 = CD

Exercise #2 R{A,B,C,D,E) F={A  BD, B  E} Decomposition: R1{A,B,C}R2{A,D}R3{B,D,E} Is this a dependency preserving decomposition?

Answer to Exercise #2 Let’s start with A  BD: Z = A Z  R1 = A  ABC = A {A} + = ABDE {A} +  R1 = ABDE  ABC = AB Update Z = A  AB = AB R{A,B,C,D,E)F={A  BD, B  E} Decomposition: R1{A,B,C} R2{A,D}R3{B,D,E}

Answer to Exercise #2 Z = AB Z  R2 = A  AD = A {A} + = ABDE {A} +  R1 = ABDE  AD = AD Update Z = AB  AD = ABD Thus A  BD preserved R{A,B,C,D,E)F={A  BD, B  E} Decomposition: R1{A,B,C} R2{A,D}R3{B,D,E}

Answer to Exercise #2 Based on R3, B  E is preserved. Check B  E: Z = B Z  R1 = B  ABC = B {B} + = BE {B} +  R1 = BE  ABC = B Update Z = B still the same R{A,B,C,D,E)F={A  BD, B  E} Decomposition: R1{A,B,C} R2{A,D}R3{B,D,E}

Answer to Exercise #2 Z = B Z  R2 = B  AD = empty set Z  R3 = B  BDE = B {B} + = BE {B} +  R3 = BE  BDE = BE Update Z = B  BE = BE Thus B  E preserved R{A,B,C,D,E)F={A  BD, B  E} Decomposition: R1{A,B,C} R2{A,D}R3{B,D,E}

End Reference: Yu Hung Chen, “Decomposition”, HungChen.ppt, SJSU (lol), HungChen.ppt Gary D. Boetticher, “Preserving Dependencies”, University of Houston Clear Lake, Dr. C. C. Chan, “Example of Dependency Preserving Decomposition”, Dp%20decomposition.htm, University of Akron, Fall Dp%20decomposition.htm Tang Nan, “Functional Dependency”,