Let R be a relation schema. A functional dependency over R is an expression X
Y where X
R, Y
R. A state d(R) of R satisfies an FD X
Y iff whenever two tuples in d(R) agree on X, they also agree on Y.
S#
SCITY
A database with schema R satisfies X
Y iff every valid state of the database satisfies X
Y.
If A
B and B
C hold in a relation, then A
C also holds (they logically imply it).
Implies A set of FD's F over R implies an FD X
Y over R iff each relation d(R) which satisfies F must also satisfy X
.
Closure of F =
Design: Example of Closure [240]
etc.
Trivial FD's always hold:
Design: Armstrong's Axioms [241]
1. Reflexivity. If
then
holds trivially.
2. Augmentation. If
holds and
then
holds.
3. Transitivity. If
holds and
holds then
holds.
Design: Closure of a Set of Attributes [242]
Let
, then
wrt a set of FD's F =
{
can be inferred from F}
Example: R = ABC,
Example: R = ABCDEF,
X = AB
saturates
Must always halt since R is finite.
Design: Keys [243]
Key - If R is a relation schema with attributes A1..An and FD's F, and X is a subset of A1..An, then X is a key of R if
1.
is in
2. for no proper subset
is
in
First Example: A is a key for ABC
Second Example: AB is not a key for ABCDEF, but ABF is a key
Suppliers: S#P# is a key
If more than one candidate key, designate one as primary and the others as alternate keys. A superkey is any superset of a key. A prime is any attribute which is a member of a key.
Example: R(CITY,ST,ZIP) with FD's F:
so CITY ST is a key.
so ST ZIP is a key.
Decomposing Relation Schemas [244]
Let R be a relation schema. A decomposition of R is a set {R1..Rk} of relation schemas such that
1.
2.
Example of {S,P,SP} is a decomposition of BAD.
Conditions for a `reasonable' decomposition
This is a lossless join.
Let F be the set of FD's for BAD and
Is
equivalent to F (is it a cover)?
Lossless Join [245]
Project and Join are approximate inverses
| A | B |
| a1 | b1 |
| a2 | b2 |
| a3 | b3 |
| B | C |
| b1 | c1 |
| b2 | c2 |
| b2 | c3 |
| A | B | C |
| a1 | b1 | c1 |
| a2 | b2 | c2 |
| a2 | b2 | c3 |
Does
yield the first relation?
| A | B | C |
| a1 | b1 | c1 |
| a2 | b1 | c2 |
| A | B | C |
| a1 | b1 | c1 |
| a1 | b1 | c2 |
| a2 | b1 | c1 |
| a2 | b1 | c2 |
If EQUALITY then r has lossless join wrt AB,BC.
Design: Lossless Join [246]
Let R be a relation schema and F a set of dependencies over R. A decomposition D={R1..Rk} of R has lossless join wrt D iff, for every relation r(R) satisfying F,
In general
the above.
Example: Shipments
| S | P | Q | N | C | X | Y |
| S1 | P1 | 30 | s | l | n | l |
| S1 | P2 | 20 | s | l | b | p |
| S1 | P3 | 40 | s | l | s | r |
| S2 | P1 | 30 | j | p | n | l |
| S2 | P2 | 40 | j | p | b | p |
| S2 | P3 | 20 | j | p | s | r |
Decomposition D = {SNC,PXY,SPQ}
Design: Lossless Join [247]
| S | N | C |
| S1 | s | l |
| S2 | j | p |
| P | X | Y |
| P1 | n | l |
| P2 | b | p |
| P3 | s | r |
| S | P | Q |
| S1 | P1 | 30 |
| S1 | P2 | 20 |
| S1 | P3 | 40 |
| S2 | P1 | 30 |
| S2 | P2 | 40 |
| S2 | P3 | 20 |
r =
What if you always decomposed by every attribute?
Test for Lossless Join: Chase FD's [248]
Input:
Output: YES if the decomposition has the lossless join property.
Method:
Lossless Join: Example [249]
Supplier decomposition has lossless join
R = SNCPXYQ, D = (SNC,PXY,SPQ)
F = {
}
Key = SP since
| S | P | Q | N | C | X | Y |
| s | p1 | q1 | n | c | x1 | y1 |
| s1 | p | q2 | n1 | c1 | x | y |
| s | p | q | n2 | c2 | x2 | y2 |
Use:
| S | P | Q | N | C | X | Y |
| s | p1 | q1 | n | c | x1 | y1 |
| s1 | p | q2 | n1 | c1 | x | y |
| s | p | q | n | c | x | y |
The last row is all distinguised. Output YES.
This row is the `glue' that can put together the original.
Lossless Join: Example [250]
R = ABCDE, D = (ABC,BCD,ADE)
F = {
}
Key = AB since
| A | B | C | D | E |
| a | b | c | d1 | e1 |
| a1 | b | c | d | e2 |
| a | b1 | c1 | d | e |
Use
| A | B | C | D | E |
| a | b | c | d | e |
| a1 | b | c | d | e2 |
| a | b1 | c1 | d | e |
Row 1 is all distinguished, output YES.