Professional Documents
Culture Documents
Decomposition and
Functional Dependency
Outline
Redundancy
Decomposition at first glance
Functional dependency
Dependency properties
2
Why?
We have learnt that, an ER diagram
can be directly converted to relational
tables.
3
An example of redundancy
rating
id hourly-wages
employee
4
An example of redundancy
6
An example of redundancy (cont.)
rating
id hourly-wages
7
Outline
Redundancy
Decomposition at first glance
Functional dependency
Dependency properties
8
Basic questions to ask
Do we need to decompose a relation?
9
Decomposition
Just now, we decomposed
EMPLOYEE into two tables, to
avoid redundancy.
10
Illegal decomposition
11
Another illegal decomposition
The judgment is not that easy! Lossless Join?
NO!
A B
1 2
2 2
A B C
A B C 3 3
1 2 3
1 2 3
1 2 2
2 2 2
2 2 3
3 3 1
2 2 2
B C
3 3 1
2 3
2 2
3 1
12
legal decomposition
13
Some confusing notions
Key? Better Definitions
An abbreviation of candidate key. Later
Candidate key?
A minimal set of attributes that uniquely identifies every tuple.
Primary key?
A candidate key selected by a database designer
Superkey
Any superset of a candidate key.
14
Decomposition may not be obvious
15
Outline
Redundancy
Decomposition at first glance
Functional dependency
Dependency properties
16
Why does redundancy exist?
Reason:
rating determines hourly-wages.
rating hourly-wages
is called a functional dependence (FD).
18
FD (cont.)
Do we have
hourly-wages rating?
Do we have id rating?
Yes, because each employee has only a single rating.
19
FD (cont.)
Do we have id id?
Of course, known as a trivial FD.
Do we have
id (rating, hourly-wages)?
Yes, because each employee has only a single (rating,
hourly-wages)-combination.
My id = 1
20
FD (cont.)
Do we have
(id, rating) hourly-wages?
23
Where are FDs from?
Two channels.
First, common senses.
HK-id name.
country capital.
(father, mother) eldest-child.
…
24
Outline
Redundancy
Decomposition at first glance
Functional dependency
Dependency properties
25
A candidate key determines all
For example, a candidate
key of EMPLOYEE is id.
Thus, id determines any
combination of the attributes.
id id
id rating
id hourly-wages
id rating, hourly-wages
id id, rating, hourly-wages
If we know the tuple’s id, then its any attribute has only 1
possibility.
26
Super key determines all
A candidate key is id.
Then, (id, rating) determines
any combination of the attributes.
(id, rating) id
(id, rating) rating
(id, rating) hourly-wages
(id, rating) rating, hourly-wages
(id, rating) id, rating, hourly-wages
We only need id to claim that the tuple’s any attribute has only 1
possibility.
So, of course, given its (id, rating), we can make the same claim.
27
Trivial functional dependences
“id id” is trivially true.
Examples:
(id, rating) id
(id, rating) rating
(id, rating) (id, rating)
(id, hourly-wages) id
(id, rating, hourly-wages) (id, rating)
…
29
Inference rules for FDs
Given a set of FDs F, we can infer additional FDs that hold
whenever the FDs in F hold
One example:
id rating
rating hourly-wages
30
Union
Given
cust-id cust-name (1)
cust-id cust-city (2)
we can derive
cust-id (cust-name, cust-city) (3)
Reasoning:
By (1), if we know cust-id, then we know cust-name.
By (2), if we know cust-id, then we know cust-city..
Hence, if we know cust-id, then we know the (cust-name, cust-city)-
combination.
31
Transitivity
Given
creditcard-no cust-id (1)
cust-id cust-name (2)
we can derive
creditcard-no cust-name (3)
Reasoning:
By (1), if we know creditcard-no, then we know cust-id.
By (2), if we know cust-id, then we know cust-name.
Hence, if we know creditcard-no, then we know cust-name.
32
Augmentation
Given
creditcard-no cust-id (1)
we can derive
(creditcard-no, branch-id) (cust-id, branch-id) (2)
Reasoning:
By (1), if we know creditcard-no 40101342, we know cust-id 1.
Hence, if (40101342, B1) = (creditcard-no, branch-id) of a tuple, we
know that (1, B1) = (stu-id , branch-id) of the tuple
33
FD derivation
Given
creditcard-no cust-id (1)
(cust-id, branch-id) acc-id (2)
We can derive (creditcard-no, branch-id) acc-id as follows.
36
Disprove FDs
Consider R(A, B, C, D, E) with FDs F ={A→B, B →D, DE→C}
Prove or disprove F |= A → C
A B C D E
---------------------------
2 4 3 1 3
4 1 6 4 2
37
Closure Test
A standard way to test if FDs hold is to compute the closure of
Y, denoted Y+
Note that Y + is a set of attributes, not FDs
Basis step: 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 +.
38
Prove FDs : A revisit
Consider R(A, B, C, D, E) with FDs F ={A→B, B →D, DE→C}
Prove or disprove F |= AE → C
AE+= AEBDC
39
Disprove FDs : A revisit
Consider R(A, B, C, D, E) with FDs F ={A→B, B →D, DE→C}
Prove or disprove F |= A → C
A+=ABD
40