Teaching Aid for Bernstein’s Algorithm

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

description

CS4221 Database Design. Teaching Aid for Bernstein’s Algorithm. Group P10. Daphne Tay A0071939U Pan Lu A0070083N Tan Wee Kwan A0074053M Yeo Yai Hui A0069830Y. Objective. T eaching aid with interactive user interface Learn in a simple yet efficient manner. - PowerPoint PPT Presentation

Transcript of Teaching Aid for Bernstein’s Algorithm

Relational Database Schema Designer Using Bernstein’s Algorithm

Project Team: P10adinda | daryl | xiaojie | woan ni

3NFNon- 3NF

Bernstein’s Algorithm

Introduction

Key Features

GUI FDVALIDATION

3NFCOMPLIANCE

Key Features

STEP-BY-STEP CLOSURE MANAGESHORTCOMINGS

Software Demonstration

Code Implementation

STEP 1

STEP 6

PRE-STEP

::

FUNCTIONDEPENDENCYFUNCTION

DEPENDENCYFUNCTIONDEPENDENCYFUNCTIONAL

DEPENDENCYFUNCTIONALDEPENDENCY

FUNCTIONDEPENDENCYFUNCTION

DEPENDENCYFUNCTIONALDEPENDENCY3NF RELATION

INPUT OUTPUTBERNSTEIN’S

Pre-step

PRE-STEP

Merge same LHS

Derive closures

FUNCTIONDEPENDENCYFUNCTION

DEPENDENCYFUNCTIONDEPENDENCYFUNCTIONAL

DEPENDENCYFunctional Dependency

FUNCTIONDEPENDENCYFUNCTION

DEPENDENCYFUNCTIONALDEPENDENCYFunctional

Dependency

FUNCTIONDEPENDENCYFUNCTION

DEPENDENCYFUNCTIONALDEPENDENCYClosure

Merged dependencies

Closures

Validated dependencies

AE → B

A → E

LHS1 = ARHS1 = E

LHS2 = AERHS2 = B

LHS1 is subset of

LHS2

A subset of RHS1, x, is subset of

LHS2

LHS2 = LHS2 - x

yes

yes

STEP 1no

no

STEP 1

Remove extraneous attributes

AE → B

A → E

LHS1 = ARHS1 = E

LHS2 = AERHS2 = B

A is subset of AE

A subset of E, E, is

subset of AE

LHS2 = AE - E = A

yes

yes

STEP 1no

no

STEP 1

Remove extraneous attributes

AE → B

A → E

LHS1 = ARHS1 = E

LHS2 = AERHS2 = B

STEP 1

STEP 1

Remove extraneous attributes

A → E

A → B

AB → BE

A → E

LHS1 = ARHS1 = E

LHS2 = ABRHS2 = BE

LHS1 is a subset of LHS2 and RHS1 is a

subset of RHS2

LHS2 - LHS1 =

RHS2 - RHS1

Remove FD2

yes

yes

STEP 1no

no

STEP 1

Remove extraneous attributes

AB → BE

A → E

LHS1 = ARHS1 = E

LHS2 = ABRHS2 = BE

A is a subset of AB and E

is a subset of BE

AB - A=

BE - E

Remove AB → BE

yes

yes

STEP 1no

no

STEP 1

Remove extraneous attributes

AB → BE

A → E

LHS1 = ARHS1 = E

LHS2 = ABRHS2 = BE

STEP 1

STEP 1

Remove extraneous attributes

A → E

E → C

A → BE

LHS1 = ARHS1 = BE

LHS2 = ERHS2 = C

RHS1 is a subset of

LHS2

Remove FD2

yes

STEP 2no

STEP 2

Find minimal cover

Append RHS2 to closure of LHS1

E → C

A → BE

LHS1 = ARHS1 = BE

LHS2 = ERHS2 = C

E is a subset of BE

Remove E → C

yes

STEP 2no

STEP 2

Find minimal cover

Append C to closure of A

E → C

A → BE

LHS1 = ARHS1 = BE

LHS2 = ERHS2 = C

STEP 2

STEP 2

Find minimal cover

A+ → ABCE

A → C

A → BLHS1 = LHS2

yes

STEP 3

noSTEP 3

Partition into relations

Put FD1 and FD2 in one relation, H

B → C

STEP 3A → B

A → C

H1

A → C

A → B

STEP 3

Partition into relations

B → C B → C

H2

STEP 4

STEP 4

Merge equivalent keys

Group FDs with the same closure

Group has more than 1 elements

Find equivalent FDs and put them in J

Do nothing to corresponding

H

Find union of FDs in group

Subtract J from union as H

FD2

FD1

FDN

::

J

STEP 4

FD2

FD1

STEP 4

Merge equivalent keys

FDN

JJ

J

HH

HH

H

::

STEP 5

HH

HFD

STEP 5

Remove transitive

dependencies

HHFD

H1

H2

Get closure of FD of H(x), C1

C1 = LHS of FD of

H(y)

compare H(x) with H(y) where x != y

compare H(x) with H(y+1)Get closure of FD of H(y), C2

C2 = RHS of FD of

H(x)

Remove FD of H(x)

Add Js to Hs

STEP 6

HH

HFD

HHFD

STEP 6

Generaterelations

Combine LHS and RHS as attributes

Set LHS of FD as key

Relation

Relation

Bernstein’s Shortcoming 1Problem

Cannot guarantee losslessness

Solution1. Combine all attributes from step 62. Find relations that are subset of others 3. Find missing attributes4. Obtain keys to form new relation

Bernstein’s Shortcoming 1R = {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 2Problem

Does not include all keys

SolutionFor two arbitrary keys (X,Y) of all keys that can be formed among relations

1. If the closure X+ shares some attributes with Y,2. A new key Z formed, where Z = (Y - (X+ ∩ Y)) X∪3. If Z R (where Y is a key in R) and (all the keys in R) Z⊆ ⊄4. Z is the missing key.5. Repeat above steps until no more new key found.

Bernstein’s Shortcoming 2R = {A, B, C, D}F = {A, B → C, C → B}

R1 = {A, B, C, D} [after Bernstein’s]R2 = {C, B} [after Bernstein’s]

Bernstein’s Shortcoming 3Problem

Superfluous attributes

Solution1. Get all functional dependencies that cannot be retrieved from J set. For

two arbitrary functional dependencies from above set (X → Y and X’ → Y)2. If X’+ ⊆ X+3. All attributes in X’ are all redundant attributes4. Remove all these attributes from all the relations that have been affected

by any J set

Bernstein’s Shortcoming 3R = {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}

Bernstein’s Shortcoming 5Problem

Superfluous redundant attributes

SolutionFor all functional dependencies that have been computed after step 5

1. Take two arbitrary functional dependencies (X → Y and X’ → Y’) 2. If Y ∩ Y’ ≠ ∅3. If Y ∩ Y’ keys(R)⊄4. Remove all the attributes in Y ∩ Y’ from Y5. Repeat above steps until no more attribute can be removed

Bernstein’s Shortcoming 5R = {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