Download presentation
Presentation is loading. Please wait.
Published byMadeline Conley Modified over 6 years ago
1
Relational Database Schema Designer Using Bernstein’s Algorithm
Project Team: P10 adinda | daryl | xiaojie | woan ni
2
Introduction Non- 3NF 3NF Bernstein’s Algorithm
3
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.
4
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.
5
Software Demonstration
6
Code Implementation PRE-STEP FUNCTION DEPENDENCY FUNCTION DEPENDENCY
FUNCTIONAL DEPENDENCY FUNCTIONAL DEPENDENCY 3NF RELATION FUNCTIONAL DEPENDENCY : STEP 6 INPUT BERNSTEIN’S OUTPUT
7
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
8
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
9
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
10
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
11
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
12
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
13
Remove extraneous attributes
STEP 1 LHS1 = A RHS1 = E STEP 1 Remove extraneous attributes A → E A → E LHS2 = AB RHS2 = BE AB → BE
14
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
15
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
16
STEP 2 LHS1 = A RHS1 = BE A → BE STEP 2 Find minimal cover A+ → ABCE
LHS2 = E RHS2 = C E → C
17
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
18
Partition into relations
STEP 3 H1 A → B STEP 3 Partition into relations A → B A → C A → C H2 B → C B → C
19
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
20
STEP 4 J J FD1 STEP 4 Merge equivalent keys J J FD2 H H : H H H FDN
21
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
22
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
23
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.
24
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]
25
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.
26
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.
27
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.
28
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.
29
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.
30
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)
31
Questions and Answers
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.