This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: The Relational Data Model
Functional Dependencies 1 Functional Dependencies
x X > A 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 the attribute A. Say "X > A holds in R." Notice 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 }. 2 Example
x Drinkers(name, addr, beersLiked, manf, favBeer). x Reasonable FD's to assert:
1. name > addr 2. name > favBeer 3. beersLiked > manf 3 Example Data
addr beersLiked manf favBeer Voyager Bud A.B. WickedAle Voyager WickedAle Pete's WickedAle Enterprise Bud A.B. way way k Because name > addr Because name > favBeer Because beersLiked > manf 4 FD's With Multiple Attributes
x No need for FD's with > 1 attribute on right. x > 1 attribute on left may be essential. Example: bar beer > price But sometimes convenient to combine FD's as a shorthand. Example: name > addr and name > favBeer become name > addr favBeer 5 Keys of Relations
x K is a key for relation R if:
1. Set K functionally determines all attributes of R 2. For no proper subset of K is (1) true. If K satisfies (1), but perhaps not (2), then K is a superkey. Note E/R keys have no requirement for minimality, as in (2) for relational keys. 6 Example
x Consider relation Drinkers(name, addr, beersLiked, manf, favBeer). x {name, beersLiked} is a superkey because together these attributes determine all the other attributes. name > addr favBeer beersLiked > manf 7 Example, Cont.
x {name, beersLiked} is a key because neither {name} nor {beersLiked} is a superkey. x In this example, there are no other keys, but lots of superkeys. Any superset of {name, beersLiked}.
8 name doesn't > manf; beersLiked doesn't > addr. E/R and Relational Keys
x Keys in E/R are properties of entities x Keys in relations are properties of tuples. x Usually, one tuple corresponds to one entity, so the ideas are the same. x But in poor relational designs, one entity can become several tuples, so E/R keys and Relational keys are different. 9 Example Data
addr beersLiked manf favBeer Voyager Bud A.B. WickedAle Voyager WickedAle Pete's WickedAle Enterprise Bud A.B. Relational key = name beersLiked But in E/R, name is a key for Drinkers, and beersLiked is a key for Beers. Note: 2 tuples for Janeway entity and 2 tuples for Bud entity. way way k 10 Where Do Keys Come From?
1. We could simply assert a key K. Then the only FD's are K > A for all atributes A, and K turns out to be the only key obtainable from the FD's. 2. We could assert FD's and deduce the keys by systematic exploration.
x E/R gives us FD's from entityset keys and manyone relationships. 11 FD's From "Physics"
x While most FD's come from E/R keyness and manyone relationships, some are really physical laws. x Example: "no two courses can meet in the same room at the same time" tells us: hour room > course. 12 Inferring FD's: Motivation
x In order to design relation schemas well, we often need to tell what FD's hold in a relation. x We are given FD's X1 > A1, X2 > A2,..., Xn > 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.
13 Inference Test
x To test if Y > B, start assuming two tuples agree in all attributes of Y. x Use the given FD's to infer that these tuples must also agree in certain other attributes. x If B is eventually found to be one of these attributes, then Y > B is true; otherwise, the two tuples, with any forced equalities form a twotuple relation that proves Y > B does not follow from the given FD's.
14 Closure Test
x An easier way to test is to compute the closure of Y, denoted Y +. x Basis: Y + = Y. x 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 +. 15 X Y+ A new Y+ 16 Finding All Implied FD's
x Motivation: "normalization," the process where we break a relation schema into two or more schemas. x 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 !
17 Basic Idea
x To know what FD's hold in a projection, we start with given FD's and find all FD's that follow from given ones. x Then, restrict to those FD's that involve only attributes of the projected schema. 18 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. 4. Finally, use only FD's involving projected attributes.
x Because XY >A follows from X >A. 19 A Few Tricks
x Never need to compute the closure of the empty set or of the set of all attributes. x If we find X + = all attributes, don't bother computing the closure of any supersets of X. 20 Example
x ABC with FD's A >B and B >C. Project onto AC. A +=ABC ; yields A >B, A >C. B +=BC ; yields B >C. C +=C ; yields nothing. BC +=BC ; yields nothing. We do not need to compute AB + or AC +. 21 Example, Continued
x Resulting FD's: A >B, A >C, and B >C. x Projection onto AC : A >C. Only FD that involves a subset of {A,C }. 22 A Geometric View of FD's
x Imagine the set of all instances of a particular relation. x That is, all finite sets of tuples that have the proper number of components. x Each instance is a point in this space. 23 Example: R(A,B) {(1,2), (3,4)} {(5,1)} {} {(1,2), (3,4), (1,3)}
24 An FD is a Subset of Instances
x For each FD X > A there is a subset of all instances that satisfy the FD. x We can represent an FD by a region in the space. x Trivial FD : an FD that is represented by the entire space. Example: A > A. 25 Example: A > B for R(A,B) {(1,2), (3,4)} {} A > B {(5,1)} {(1,2), (3,4), (1,3)}
26 Representing Sets of FD's
x If each FD is a set of relation instances, then a collection of FD's corresponds to the intersection of those sets. Intersection = all instances that satisfy all of the FD's. 27 Example
Instances satisfying A>B, B>C, and CD>A A>B B>C CD>A 28 Implication of FD's
x If an FD Y > B follows from FD's X1 > A1,..., Xn > An , then the region in the space of instances for Y > B must include the intersection of the regions for the FD's Xi > Ai . That is, every instance satisfying all the FD's Xi > Ai surely satisfies Y > B. But an instance could satisfy Y > B, yet not be in this intersection. 29 Example A>B A>C B>C 30 ...
View
Full
Document
 Spring '08
 CHIRKOVA
 Relational model

Click to edit the document details