Docsity

Relational Database Design Theory: BCNF and 4NF, Slides of Introduction to Database Management Systems

Toggle sidebar
bg1
1
Relational Database Design Theory
Part II
CPS 116
Introduction to Database Systems
2
Announcements
๎š™Homework #2 sample solution available
๎š™Project milestone #1 due today (Sep. 30)
๎š™Midterm next Thursday in class
๎šƒOpen book, open notes
๎šƒSample midterm (from last year) available
โ€ข Solution available next Tuesday
3
Review
๎š™Functional dependencies
๎šƒXโ†’Y: If two rows agree on X, they must agree on Y
)A generalization of the key concept
๎š™Non-key functional dependencies: a source of redundancy
๎šƒNon-trivial Xโ†’Ywhere Xis not a superkey
)Called a BCNF violation
๎š™BCNF decomposition: a method for removing redundancies
๎šƒGiven R(X, Y, Z) and a BCNF violation Xโ†’Y, decompose Rinto
R1(X, Y) and R2(X, Z)
)A lossless join decomposition
๎š™Schema in BCNF has no redundancy due to FDโ€™s
4
Next
๎š™3NF (BCNF is too much)
๎š™Multivalued dependencies: another source of
redundancy
๎š™4NF (BCNF is not enough)
5
Motivation for 3NF
๎š™Address (street_address, city, state, zip)
๎šƒstreet_address, city, state โ†’zip
๎šƒzip โ†’city, state
๎š™Keys
๎šƒ{street_address, city, state}
๎šƒ{street_address, zip}
๎š™BCNF?
๎šƒViolation: zip โ†’city, state
6
To decompose or not to decompose
Address1(zip, city, state)
Address2(street_address, zip)
๎š™FDโ€™s in Address1
๎šƒzip โ†’city, state
๎š™FDโ€™s in Address2
๎šƒNone!
๎š™Hey, where is street_address, city, state โ†’zip?
๎šƒCannot check without joining Address1and Address2back together
๎š™Problem: Some lossless join decomposition is not
dependency-preserving
๎š™Dilemma: Should we get rid of redundancy at the expense
of making constraints harder to enforce?
pf3
pf4

Partial preview of the text

Download Relational Database Design Theory: BCNF and 4NF and more Slides Introduction to Database Management Systems in PDF only on Docsity!

Relational Database Design Theory

Part II

CPS 116

Introduction to Database Systems

Announcements

ย™ Homework #2 sample solution available

ย™ Project milestone #1 due today (Sep. 30)

ย™ Midterm next Thursday in class

ยƒ Open book, open notes ยƒ Sample midterm (from last year) available

  • Solution available next Tuesday

3

Review

ย™ Functional dependencies ยƒ X โ†’ Y: If two rows agree on X, they must agree on Y )A generalization of the key concept

ย™ Non-key functional dependencies: a source of redundancy ยƒ Non-trivial X โ†’ Y where X is not a superkey )Called a BCNF violation

ย™ BCNF decomposition: a method for removing redundancies ยƒ Given R(X, Y, Z) and a BCNF violation X โ†’ Y, decompose R into R 1 (X, Y) and R 2 (X, Z) )A lossless join decomposition

ย™ Schema in BCNF has no redundancy due to FDโ€™s

4

Next

ย™ 3NF (BCNF is too much)

ย™ Multivalued dependencies: another source of

redundancy

ย™ 4NF (BCNF is not enough)

5

Motivation for 3NF

ย™ Address (street_address, city, state, zip)

ยƒ street_address, city, state โ†’ zip ยƒ zip โ†’ city, state

ย™ Keys

ยƒ {street_address, city, state} ยƒ {street_address, zip}

ย™ BCNF?

ยƒ Violation: zip โ†’ city, state

6

To decompose or not to decompose

Address 1 (zip, city, state) Address 2 (street_address, zip) ย™ FDโ€™s in Address 1 ยƒ zip โ†’ city, state ย™ FDโ€™s in Address 2 ยƒ None! ย™ Hey, where is street_address, city, state โ†’ zip? ยƒ Cannot check without joining Address 1 and Address 2 back together ย™ Problem: Some lossless join decomposition is not dependency-preserving ย™ Dilemma: Should we get rid of redundancy at the expense of making constraints harder to enforce?

3NF

ย™ R is in Third Normal Form (3NF) if for every non-trivial FD X โ†’ A (where A is single attribute), either ยƒ X is a superkey of R, or ยƒ A is a member of at least one key of R )Intuitively, BCNF decomposition on X โ†’ A would โ€œbreakโ€ the key containing A

ย™ So Address is already in 3NF

ย™ Tradeoff: ยƒ Can enforce all original FDโ€™s on individual decomposed relations ยƒ Might have some redundancy due to FDโ€™s

BNCF = no redundancy?

ย™ Student (SID, CID, club)

ยƒ Suppose your classes have nothing to do with the clubs you join ยƒ FDโ€™s?

  • None ยƒ BNCF?
  • Yes ยƒ Redundancies?
  • Tons!

SID CID club 142 CPS116 ballet 142 CPS116 sumo 142 CPS114 ballet 142 CPS114 sumo 123 CPS116 chess 123 CPS116 golf ... ... ...

9

Multivalued dependencies

ย™ A multivalued dependency (MVD) has the form

X Y, where X and Y are sets of attributes in a

relation R

ย™ X Y means that whenever two rows in R agree on

all the attributes of X, then we can swap their Y

components and get two new rows that are also in R

X Y Z a b1 c a b2 c ... ... ...

X Y Z a b1 c a b2 c a b1 c a b2 c ... ... ...

Must be in R too

10

MVD examples

Student (SID, CID, club)

ย™ SID CID

ย™ SID club

ยƒ Intuition: given SID, CID and club are โ€œindependentโ€

ย™ SID, CID club

ยƒ Trivial: LHS โˆช RHS = all attributes of R

ย™ SID, CID SID

ยƒ Trivial: LHS โЇ RHS

11

Complete MVD + FD rules

ย™ FD reflexivity, augmentation, and transitivity ย™ MVD complementation: If X Y, then X attrs(R) โ€“ X โ€“ Y ย™ MVD augmentation: If X Y and V โІ W, then XW YV

ย™ MVD transitivity: If X Y and Y Z, then X Z โ€“ Y ย™ Replication (FD is MVD): If X โ†’ Y, then X Y ย™ Coalescence: If X Y and Z โІ Y and there is some W disjoint from Y such that W โ†’ Z, then X โ†’ Z

Try proving things using these!

12

An elegant solution: chase

ย™ Given a set of FDโ€™s and MVDโ€™s D, does another

dependency d (FD or MVD) follow from D?

ย™ Procedure

ยƒ Start with the hypothesis of d, and treat them as โ€œseedโ€ tuples in a relation ยƒ Apply the given dependencies in D repeatedly

  • If we apply an FD, we infer equality of two symbols
  • If we apply an MVD, we infer more tuples ยƒ If we infer the conclusion of d, we have a proof ยƒ Otherwise, if nothing more can be inferred, we have a counterexample

3NF, BCNF, 4NF, and beyond

ย™ Of historical interests

ยƒ 1NF: All column values must be atomic ยƒ 2NF: There is no partial functional dependency (a non- trivial FD X โ†’ A where X is a proper subset of some key)

Redundancy due to MVDโ€™s Possible Possible No

Redundancy due to FDโ€™s Possible No No

Lose FDโ€™s? No Possible Possible

Anomaly/normal form 3NF BCNF 4NF

Summary

ย™ Philosophy behind BCNF, 4NF:

Data should depend on the key, the whole key, and

nothing but the key!

ย™ Philosophy behind 3NF:

โ€ฆ But not at the expense of more expensive

constraint enforcement!