Relational Database Schema Designer Using Bernstein’s Algorithm

Slides:



Advertisements
Similar presentations
Schema Refinement: Canonical/minimal Covers
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
Announcements Read 6.1 – 6.3 for Wednesday Project Step 3, due now Homework 5, due Friday 10/22 Project Step 4, due Monday Research paper –List of sources.
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.
Database Management COP4540, SCS, FIU Functional Dependencies (Chapter 14)
CS Algorithm : Decomposition into 3NF  Obviously, the algorithm for lossless join decomp into BCNF can be used to obtain a lossless join decomp.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
Normal Form Design addendum by C. Zaniolo. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Normal Form Design Compute the canonical cover.
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 9.
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
Introduction to Schema Refinement. Different problems may arise when converting a relation into standard form They are Data redundancy Update Anomalies.
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
Chapter 10 Functional Dependencies and Normalization for Relational Databases.
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.
Normal Forms through BCNF CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
Functional Dependencies. FarkasCSCE 5202 Reading and Exercises Database Systems- The Complete Book: Chapter 3.1, 3.2, 3.3., 3.4 Following lecture slides.
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.
Chapter 7 Functional Dependencies Copyright © 2004 Pearson Education, Inc.
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
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.
Chapter 8 Relational Database Design. 2 Relational Database Design: Goals n Reduce data redundancy (undesirable replication of data values) n Minimize.
Normalization and FUNctional Dependencies. Redundancy: root of several problems with relational schemas: –redundant storage, insert/delete/update anomalies.
Case tool Relational Database Schema Designer Cai Xinlei Tang Ning Xu Chen Zhang Yichuan CS4221 P06.
Functional Dependencies and Normalization 1 Instructor: Mohamed Eltabakh Part 2.
Chapter 16: Relational Database Design and Further Dependencies
Relational Database Schema Designer using Bernstein’s Algorithm
CS 440 Database Management Systems
Functional Dependency and Normalization
CS 440 Database Management Systems
Relational Database Design (Discussion Session)
Schema Refinement and Normal Forms
Database Management Systems (CS 564)
CS4221 Database Design Group P05 Name Matriculation Number
Normalization Functional Dependencies Presented by: Dr. Samir Tartir
CS411 Database Systems 08: Midterm Review Kazuhiro Minami 1.
Normalization First Normal Form (1NF) Boyce-Codd Normal Form (BCNF)
Canonical Cover & Normal Forms
Relational Database Design
CS 480: Database Systems Lecture 22 March 6, 2013.
3.1 Functional Dependencies
Chapter 9 Designing Databases
CS4221 Project Relational Database Schema using Bernstein’s Algorithm
Functional Dependencies and Normalization
Relational Database Schema Designer: CASE tool
Canonical Cover & Normal Forms
Faloutsos & Pavlo SCS /615 Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization.
Normalization Murali Mani.
Functional Dependencies and Normalization
Functional Dependencies and Normalization
Temple University – CIS Dept. CIS331– Principles of Database Systems
Lecture 09: Functional Dependencies, Database Design
Normalization Part II cs3431.
Lecture 8: Database Design
Functional Dependencies
Lecture 07: E/R Diagrams and Functional Dependencies
Normalization cs3431.
Some slides are from Dr. Sara Cohen
CS 405G: Introduction to Database Systems
Instructor: Mohamed Eltabakh
Chapter 19 (part 1) Functional Dependencies
Instructor: Mohamed Eltabakh
CSC 453 Database Systems Lecture
Functional Dependencies and Normalization
Functional Dependencies and Normalization
CS4222 Principles of Database System
Presentation transcript:

Relational Database Schema Designer Using Bernstein’s Algorithm Project Team: P10 adinda | daryl | xiaojie | woan ni

Introduction Non- 3NF 3NF Bernstein’s Algorithm

Key Features FD VALIDATION 3NF COMPLIANCE GUI User graphic interface (GUI) is provided for user, which will allow easy adding, editing and deletion of function dependencies for user. The software also checks if the user-provided functional dependencies are valid before proceeding. Base on the user-provided functional dependencies, the software will derive the 3NF database base on Bernstein’s algorithm and result will be displayed on our software user interface. Our software provides the results of intermediate steps of the Bernstein’s algorithm till the final result. Our software provides the closure for each of the functional dependencies based on the user-provided functional dependencies. As Bernstein’s algorithm is not perfect, our software provides the solution for 2 Bernstein’s shortcomings.

Key Features MANAGE SHORTCOMINGS STEP-BY-STEP CLOSURE User graphic interface (GUI) is provided for user, which will allow easy adding, editing and deletion of function dependencies for user. The software also checks if the user-provided functional dependencies are valid before proceeding. Base on the user-provided functional dependencies, the software will derive the 3NF database base on Bernstein’s algorithm and result will be displayed on our software user interface. Our software provides the results of intermediate steps of the Bernstein’s algorithm till the final result. Our software provides the closure for each of the functional dependencies based on the user-provided functional dependencies. As Bernstein’s algorithm is not perfect, our software provides the solution for 2 Bernstein’s shortcomings.

Software Demonstration

Code Implementation PRE-STEP FUNCTION DEPENDENCY FUNCTION DEPENDENCY FUNCTIONAL DEPENDENCY FUNCTIONAL DEPENDENCY 3NF RELATION FUNCTIONAL DEPENDENCY : STEP 6 INPUT BERNSTEIN’S OUTPUT

Pre-step Merged dependencies FUNCTION Validated dependencies same LHS Derive closures FUNCTION DEPENDENCY Validated dependencies FUNCTION DEPENDENCY FUNCTIONAL DEPENDENCY Functional Dependency FUNCTION DEPENDENCY FUNCTION DEPENDENCY FUNCTION DEPENDENCY FUNCTIONAL DEPENDENCY Functional Dependency Closures FUNCTION DEPENDENCY FUNCTION DEPENDENCY FUNCTIONAL DEPENDENCY Closure

STEP 1 LHS1 is subset of LHS2 LHS1 = A no RHS1 = E STEP 1 A → E yes Remove extraneous attributes A → E yes A subset of RHS1, x, is subset of LHS2 LHS2 = AE RHS2 = B no AE → B yes LHS2 = LHS2 - x

Remove extraneous attributes STEP 1 A is subset of AE LHS1 = A RHS1 = E no STEP 1 Remove extraneous attributes A → E yes A subset of E, E, is subset of AE LHS2 = AE RHS2 = B no AE → B yes LHS2 = AE - E = A

Remove extraneous attributes STEP 1 LHS1 = A RHS1 = E STEP 1 Remove extraneous attributes A → E A → E LHS2 = AE RHS2 = B AE → B A → B

STEP 1 LHS1 = A no RHS1 = E STEP 1 A → E yes LHS1 is a subset of LHS2 and RHS1 is a subset of RHS2 LHS1 = A RHS1 = E no STEP 1 Remove extraneous attributes A → E yes LHS2 - LHS1 = RHS2 - RHS1 LHS2 = AB RHS2 = BE no AB → BE yes Remove FD2

STEP 1 A is a subset of AB and E is a subset of BE LHS1 = A no RHS1 = E no STEP 1 Remove extraneous attributes A → E yes AB - A = BE - E LHS2 = AB RHS2 = BE no AB → BE yes Remove AB → BE

Remove extraneous attributes STEP 1 LHS1 = A RHS1 = E STEP 1 Remove extraneous attributes A → E A → E LHS2 = AB RHS2 = BE AB → BE

STEP 2 RHS1 is a subset of LHS2 LHS1 = A no RHS1 = BE A → BE STEP 2 Find minimal cover A → BE yes Append RHS2 to closure of LHS1 LHS2 = E RHS2 = C E → C Remove FD2

STEP 2 E is a subset of BE LHS1 = A no RHS1 = BE A → BE STEP 2 yes Find minimal cover A → BE yes Append C to closure of A LHS2 = E RHS2 = C E → C Remove E → C

STEP 2 LHS1 = A RHS1 = BE A → BE STEP 2 Find minimal cover A+ → ABCE LHS2 = E RHS2 = C E → C

STEP 3 A → B STEP 3 LHS1 = LHS2 Partition into relations no A → C yes Put FD1 and FD2 in one relation, H B → C

Partition into relations STEP 3 H1 A → B STEP 3 Partition into relations A → B A → C A → C H2 B → C B → C

STEP 4 Group FDs with the same closure Group has more than 1 elements Merge equivalent keys FD2 Find equivalent FDs and put them in J Do nothing to corresponding H : Find union of FDs in group FDN Subtract J from union as H

STEP 4 J J FD1 STEP 4 Merge equivalent keys J J FD2 H H : H H H FDN

STEP 5 compare H(x) with H(y) where x != y Get closure of FD of H(x), C1 C1 = LHS of FD of H(y) STEP 5 Remove transitive dependencies H1 H H H FD compare H(x) with H(y+1) Get closure of FD of H(y), C2 C2 = RHS of FD of H(x) H2 H H FD Remove FD of H(x) Add Js to Hs

Combine LHS and RHS as attributes STEP 6 STEP 6 Generate relations Relation H H H FD Combine LHS and RHS as attributes Relation Set LHS of FD as key H H FD

Bernstein’s Shortcoming 1 Problem Cannot guarantee losslessness Solution Combine all attributes from step 6 Find relations that are subset of others Find missing attributes Obtain keys to form new relation To create the new relation, the first step is to combine all attributes in every relation by intersection from step 6’s result and in the process identifying which relation is a subset of the other relations (R ⊆ R’). The second step is to find the missing attribute. We cross check the user’s attribute inputs against our new combined attribute set. Finally, using the relations (where, R ⊄ any R’) found in the second step, we obtain a key of the relation (if multiple keys exist, only use the first key) and by combining the keys with the missing attribute we form our new relation.

Bernstein’s Shortcoming 1 R = {A, B, C, D} F = {A, B → C, A → C, D} R1 = {A, C, D} [after Bernstein’s] R2 = {A, B} [new relation added]

Bernstein’s Shortcoming 2 Problem Does not include all keys Solution For two arbitrary keys (X,Y) of all keys that can be formed among relations If the closure X+ shares some attributes with Y, A new key Z formed, where Z = (Y - (X+ ∩ Y)) ∪ X If Z ⊆ R (where Y is a key in R) and (all the keys in R)⊄Z Z is the missing key. Repeat above steps until no more new key found. To find all the keys, we compare all the keys among all the relations that have been computed after step 6. For two arbitrary keys (X, Y), first we compute the closure of one key (X+). If the intersection of the closure and the other key exists (if X+ ∩ Y ≠ ∅), we form a new key (Z) by replacing the intersection of Y with X and eliminate duplicate attributes (Z = (Y - (X+ ∩ Y)) ∪ X). If the relation (Rx) which has the key Y contains all the attributes in Z and all the keys of the relation are not a subset of Z ((Z ∈ Rx) && (for all keys (Rx) ⊄Z), we conclude that the new key (Z) should be added to remove the shortcoming of Bernstein’s algorithm.

Bernstein’s Shortcoming 2 R = {A, B, C, D} F = {A, B → C, C → B} R1 = {A, B, C, D} [after Bernstein’s] R2 = {C, B} [after Bernstein’s] given a relation R = {A, B, C, D} and respective functional dependencies F = {A, B → C, C → B}. After applying Bernstein’s algorithm, the result will be: R1 (A, B, C, D) where the key for R1 is A, B and R2 (C, B) where the key for R2 is C.

Bernstein’s Shortcoming 3 Problem Superfluous attributes Solution Get all functional dependencies that cannot be retrieved from J set. For two arbitrary functional dependencies from above set (X → Y and X’ → Y) If X’+ ⊆ X+ All attributes in X’ are all redundant attributes Remove all these attributes from all the relations that have been affected by any J set To find the superfluous attributes, first we find all the functional dependencies that do not share the same closure with any functional dependencies in the J set. Second, for any two functional dependencies in these functional dependencies (X → Y and X’ → Y), if the closure of one functional dependency is a subset of the closure of the other functional dependency (if X’+ ⊆ X+), then all the attributes on the left hand side of the first functional dependency (X’) are redundant attributes. Finally, we remove these redundant attributes from all the relations that have been affected by any J set that has been computed in step 4.

Bernstein’s Shortcoming 3 R = {A, B, C, D, E, F} F = {A, D → B, B → C, C → D, A, B → E, A, C → F} R1 = {A, B, C, D, E, F} R2 = {B, C} R3 = {C, D} For instance, given a relation R = {A, B, C, D, E, F} and respective functional dependencies F = {A, D → B, B → C, C → D, A, B → E, A, C → F}. After applying Bernstein’s algorithm, the result will be : R1 (A, B, C, D, E, F) R2 (B, C) R3 (C,D) where the key for R1 is A, B, A, C, A, D and key for R2 is B and key for R3 is C. For the above example, C is a superfluous attribute.

Bernstein’s Shortcoming 5 Problem Superfluous redundant attributes Solution For all functional dependencies that have been computed after step 5 Take two arbitrary functional dependencies (X → Y and X’ → Y’) If Y ∩ Y’ ≠ ∅ If Y ∩ Y’ ⊄keys(R) Remove all the attributes in Y ∩ Y’ from Y Repeat above steps until no more attribute can be removed To remove superfluous attributes, we compare all the functional dependencies that have computed after step 5. For two arbitrary functional dependencies (X → Y and X’ → Y’), if the right hand side of one functional dependency shares a certain common attributes of the right hand side of the other functional dependency (if Y ∩ Y’ ≠ ∅), then for all the attributes in this intersection, if the attribute is not a part of any key among all the relations (Y ∩ Y’ ⊄keys(R)), we remove this attribute from Y. We recursively perform the above step until no more attribute can be removed.

Bernstein’s Shortcoming 5 R = {Model#, Serial#, Price, Color, Name, Year} F = {{Model#, Serial#} → {Price, Color}, {Model# → Name}, {Serial# → Year}, {Name, Year → Price}} R1 (Model#, Serial#, Price, Color) R2 (Model#, Name) R3 (Serial#, Year) R4(Name, Year, Price)

Questions and Answers