Beruflich Dokumente
Kultur Dokumente
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.2
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.3
Combine Schemas?
Suppose we combine borrow and loan to get
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.4
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.5
The next slide shows how we lose information -- we cannot reconstruct the
original employee relation -- and so, this is a lossy decomposition.
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.6
A Lossy Decomposition
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.7
Identification
parts
A relational schema R is in first normal form if the domains of all
We assume all relations are in first normal form (and revisit this in
Chapter 9)
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.8
used.
z
Suppose that students are given roll numbers which are strings of
the form CS0012 or EE1127
If the first two characters are extracted to find the department, the
domain of roll numbers is not atomic.
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.9
functional dependencies
multivalued dependencies
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.10
Functional Dependencies
Constraints on the set of legal relations.
Require that the value for a certain set of attributes determines
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.11
R and R
The functional dependency
holds on R if and only if for any legal relations r(R), whenever any
two tuples t1 and t2 of r agree on the attributes , they also agree
on the attributes . That is,
t1[] = t2 [] t1[ ] = t2 [ ]
Example: Consider r(A,B ) with the following instance of r.
1 4
1 5
3 7
On this instance, A B does NOT hold, but B A does hold.
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.12
K R, and
for no K, R
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.13
test relations to see if they are legal under a given set of functional
dependencies.
dependency even if the functional dependency does not hold on all legal
instances.
z
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.14
relation
z
Example:
customer_name customer_name
In general, is trivial if
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.15
of F.
We denote the closure of F by F+.
F+ is a superset of F.
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.16
not a superkey
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.17
( U )
(R-(-))
In our example,
z
= loan_number
= amount
( U ) = ( loan_number, amount )
( R - ( - ) ) = ( customer_id, loan_number )
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.18
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.19
in F+
at least one of the following holds:
z
is trivial (i.e., )
is a superkey for R
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.20
Goals of Normalization
Let R be a relation scheme with a set F of functional
dependencies.
Decide whether a relation scheme R is in good form.
In the case that a relation scheme R is not in good form,
decompose it into a set of relation scheme {R1, R2, ..., Rn} such
that
z
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.21
sufficiently normalized
Consider a database
any one of which can be the courses instructor, and the set of books,
all of which are required for the course (no matter who teaches it).
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.22
teacher
database
database
database
database
database
database
operating systems
operating systems
operating systems
operating systems
Avi
Avi
Hank
Hank
Sudarshan
Sudarshan
Avi
Avi
Pete
Pete
book
DB Concepts
Ullman
DB Concepts
Ullman
DB Concepts
Ullman
OS Concepts
Stallings
OS Concepts
Stallings
classes
There are no non-trivial functional dependencies and therefore the
relation is in BCNF
Insertion anomalies i.e., if Marilyn is a new teacher that can teach
7.23
course
teacher
database
database
database
operating systems
operating systems
Avi
Hank
Sudarshan
Avi
Jim
teaches
course
book
database
database
operating systems
operating systems
DB Concepts
Ullman
OS Concepts
Shaw
text
This suggests the need for higher normal forms, such as Fourth
Normal Form (4NF), which we shall see later.
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.24
Functional-Dependency Theory
We now consider the formal theory that tells us which functional
preserving
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.25
of F.
We denote the closure of F by F+.
We can find all of F+ by applying Armstrongs Axioms:
z
if , then
(reflexivity)
if , then
(augmentation)
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.26
Example
R = (A, B, C, G, H, I)
F={ AB
AC
CG H
CG I
B H}
some members of F+
z
AH
by
AG I
by
CG HI
by
7.27
F+=F
repeat
for each functional dependency f in F+
apply reflexivity and augmentation rules on f
add the resulting functional dependencies to F +
for each pair of functional dependencies f1and f2 in F +
if f1 and f2 can be combined using transitivity
then add the resulting functional dependency to F +
until F + does not change any further
NOTE: We shall see an alternative procedure for this task later
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.28
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.29
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.30
AC
CG H
CG I
B H}
(AG)+
1. result = AG
2. result = ABCG
(A C and A B)
3. result = ABCGH
Is AG a super key?
2.
Does AG R? == Is (AG)+ R
Is any subset of AG a superkey?
1.
1.
Does A R? == Is (A)+ R
2.
Does G R? == Is (G)+ R
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.31
Computing closure of F
z
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.32
Canonical Cover
Sets of functional dependencies may have redundant dependencies
to
{A B, B C, A D}
E.g.:
on LHS:
{A B, B C, AC D} can be simplified
to
{A B, B C, A D}
Intuitively, a canonical cover of F is a minimal set of functional
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.33
Extraneous Attributes
Consider a set F of functional dependencies and the functional
dependency in F.
z
Attribute A is extraneous in if A
and F logically implies (F { }) {( A) }.
Attribute A is extraneous in if A
and the set of functional dependencies
(F { }) { ( A)} logically implies F.
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.34
2.
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.35
Canonical Cover
A canonical cover for F is a set of dependencies Fc such that
z
repeat
Use the union rule to replace any dependencies in F
1 1 and 1 2 with 1 1 2
Find a functional dependency with an
extraneous attribute either in or in
If an extraneous attribute is found, delete it from
until F does not change
Note: Union rule may become applicable after some extraneous attributes
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.36
R = (A, B, C)
F = {A BC
BC
AB
AB C}
A is extraneous in AB C
z
C is extraneous in A BC
z
AB
BC
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.37
Lossless-join Decomposition
For the case of R = (R1, R2), we require that for all possible
relations r on schema R
r = R1 (r )
R2 (r )
R1 R 2 R1
R1 R 2 R2
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.38
Example
R = (A, B, C)
F = {A B, B C)
z
Lossless-join decomposition:
R1 R2 = {B} and B BC
Dependency preserving
Lossless-join decomposition:
R1 R2 = {A} and A AB
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.39
R2)
Dependency Preservation
If
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.40
R1, R2, , Rn we apply the following test (with attribute closure done with
respect to F)
z
result =
while (changes to result) do
for each Ri in the decomposition
t = (result Ri)+ Ri
result = result t
dependency preserving
This procedure takes polynomial time, instead of the exponential time
required to compute F+ and (F1 F2 Fn)+
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.41
Example
R = (A, B, C )
F = {A B
B C}
Key = {A}
R is not in BCNF
Decomposition R1 = (A, B), R2 = (B, C)
z
R1 and R2 in BCNF
Lossless-join decomposition
Dependency preserving
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.42
check only the dependencies in the given set F for violation of BCNF,
rather than checking all dependencies in F+.
z
decomposition of R
z
In
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.43
or use the original set of dependencies F that hold on R, but with the
following test:
for every set of attributes Ri, check that + (the attribute
closure of ) either includes no attribute of Ri- , or includes all
attributes of Ri.
the condition is violated by some in F, the dependency
(+ - ) Ri
can be shown to hold on Ri, and Ri violates BCNF.
If
We
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.44
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.45
F = {A B
B C}
Key = {A}
R is not in BCNF (B C but B is not superkey)
Decomposition
z
R1 = (B, C)
R2 = (A,B)
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.46
R4 = (customer_name, loan_number )
Final decomposition
R1, R3, R4
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.47
F = {JK L
LK}
Two candidate keys = JK and JL
R is not in BCNF
Any decomposition of R will fail to preserve
JK L
This implies that testing for JK L requires a join
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.48
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.49
3NF Example
Relation R:
z
R = (J, K, L )
F = {JK L, L K }
R is in 3NF
JK L
LK
JK is a superkey
K is contained in a candidate key
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.50
Redundancy in 3NF
There is some redundancy in this schema
Example of problems due to redundancy in 3NF
z
R = (J, K, L)
F = {JK L, L K }
J
j1
l1
k1
j2
l1
k1
j3
l1
k1
null
l2
k2
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.51
F+.
Use attribute closure to check for each dependency , if is a
superkey.
If is not a superkey, we have to verify if each attribute in is
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.52
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.53
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.54
Example
Relation schema:
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.55
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.56
Design Goals
Goal for a relational database design is:
z
BCNF.
Lossless join.
Dependency preservation.
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.57
multivalued dependency
holds on R if in any legal relation r(R), for all pairs for tuples t1
and t2 in r such that t1[] = t2 [], there exist tuples t3 and t4 in
r such that:
t1[] = t2 [] = t3 [] = t4 []
t3[]
= t1 []
t3[R ] = t2[R ]
t4 []
= t2[]
t4[R ] = t1[R ]
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.58
MVD (Cont.)
Tabular representation of
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.59
Example
Let R be a relation schema with a set of attributes that are partitioned
Y Z if Y W
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.60
Example (Cont.)
In our example:
course teacher
course book
The above formal definition is supposed to formalize the
If Y Z then Y Z
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.61
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.62
Theory of MVDs
From the definition of multivalued dependency, we can derive the
following rule:
z
If , then
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.63
is trivial (i.e., or = R)
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.64
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.65
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.66
Example
R =(A, B, C, G, H, I)
F ={ A B
B HI
CG H }
R is not in 4NF since A B and A is not a superkey for R
Decomposition
a) R1 = (A, B)
(R1 is in 4NF)
b) R2 = (A, C, G, H, I)
c) R3 = (C, G, H)
(R3 is in 4NF)
d) R4 = (A, C, G, I)
e) R5 = (A, I)
(R5 is in 4NF)
f)R6 = (A, C, G)
(R6 is in 4NF)
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.67
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.68
R could have been a single relation containing all attributes that are of
interest (called universal relation).
R could have been the result of some ad hoc design of relations, which
we then test/convert to normal form.
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.69
correctly, the tables generated from the E-R diagram should not need
further normalization.
However, in a real (imperfect) design, there can be functional
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.70
faster lookup
extra coding work for programmer and possibility of error in extra code
account
z
depositor
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.71
Is
Used
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.72
are valid.
A snapshot is the value of the data at a particular point in time.
Adding a temporal component results in functional dependencies like
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.73
End of Chapter
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.76
separately.
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.77
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.78
Q.E.D.
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.79
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.80
Figure 7.6
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.81
Figure 7.7
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.82
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.83
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.84
Database System Concepts, 5th Ed., slide version 5.0, June 2005.
7.85