Docsity

Design Theory for Relational Databases - Database Systems - Lecture Slides, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download Design Theory for Relational Databases - Database Systems - Lecture Slides and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

Design Theory for Relational

Databases

Functional Dependencies Decompositions Normal Forms

Functional Dependencies

  • X -> Y is an assertion about a relation R that whenever two tuples of R agree on all the attributes of X , then they must also agree on all attributes in set Y. - Say “ X -> Y holds in R .” - Convention: …, X , Y , Z represent sets of attributes; A , B , C ,… represent single attributes. - Convention: no set formers in sets of attributes, just ABC , rather than { A , B , C }.

Example: FD’s

Drinkers(name, addr, beersLiked, manf, favBeer)

  • Reasonable FD’s to assert:
    1. name -> addr favBeer  Note this FD is the same as name -> addr and name -> favBeer.
    2. beersLiked -> manf

Example: Possible Data

5

name addr beersLiked manf favBeer Janeway Voyager Bud A.B. WickedAle Janeway Voyager WickedAle Pete’s WickedAle Spock Enterprise Bud A.B. Bud

Because name -> addr Because name -> favBeer Because beersLiked -> manf

Example: Superkey

Drinkers(name, addr, beersLiked, manf, favBeer)

  • {name, beersLiked} is a superkey because together these attributes determine all the other attributes. - name -> addr favBeer - beersLiked -> manf

Example: Key

  • {name, beersLiked} is a key because neither {name} nor {beersLiked} is a superkey. - name doesn’t -> manf; beersLiked doesn’t -> addr.
  • There are no other keys, but lots of superkeys.
    • Any superset of {name, beersLiked}.

More FD’s From “Physics”

  • Example: “no two courses can meet in the same room at the same time” tells us: hour room -> course.

Inferring FD’s

  • We are given FD’s X 1 -> A 1 , X 2 -> A 2 ,…, X (^) n -> An , and we want to know whether an FD Y -> B must hold in any relation that satisfies the given FD’s. - Example: If A -> B and B -> C hold, surely A -> C holds, even if we don’t say so.
  • Important for design of good relation schemas.

Inference Test – (2)

  • Use the given FD’s to infer that these tuples must also agree in certain other attributes. - If B is one of these attributes, then Y -> B is true. - Otherwise, the two tuples, with any forced equalities, form a two-tuple relation that proves Y -> B does not follow from the given FD’s.

Closure Test

  • An easier way to test is to compute the closure of Y , denoted Y +.
  • Basis: Y +^ = Y.
  • Induction: Look for an FD’s left side X that is a subset of the current Y +. If the FD is^ X^ ->^ A , add A to Y +.

Finding All Implied FD’s

  • Motivation: “normalization,” the process where we break a relation schema into two or more schemas.
  • Example: ABCD with FD’s AB -> C , C -> D , and D -> A. - Decompose into ABC , AD. What FD’s hold in ABC ? - Not only AB -> C , but also C -> A!

Why?

17

ABC a 1 b 1 c

ABCD

a 2 b 2 c

Thus, tuples in the projection with equal C’s have equal A’s; C -> A.

a 1 b 1 cd 1 a 2 b 2 cd 2

comes from

d 1 =d 2 because C -> D a 1 =a 2 because D -> A

Simple, Exponential Algorithm

  1. For each set of attributes X , compute X +.
  2. Add X -> A for all A in X +^ - X.
  3. However, drop XY -> A whenever we discover X -> A.  Because XY -> A follows from X -> A in any projection.
  4. Finally, use only FD’s involving projected attributes.

A Few Tricks

  • No need to compute the closure of the empty set or of the set of all attributes.
  • If we find X +^ = all attributes, so is the closure of any superset of X.