Académique Documents
Professionnel Documents
Culture Documents
UNIT 4
Schema Refinement and
Normal Forms
Text :
n 3rd edition: Chapter 19, sections 19.1-19.6,
or
n 2nd edition: Chapter 15 sections 15.1-15.7
G. Tsiknis
G. Tsiknis
Unit 4
n Despite our best efforts, tables obtained from ER model by the methods
value of D, we write:
A, B, C D
A, B, C D is a functional dependency
A,B,C is a determinant
D is said to depends on A,B,C
Sometimes written as {A,B,C} D or A B C D
n Must be careful:
Wrong decomposition may loose information
Unit 4
G. Tsiknis
Unit 4
G. Tsiknis
i.e., given two tuples in r, if the X values agree, then the Y values
must also agree. (X and Y are sets of attributes.)
informally, precisely one Y-value is associated with each X value
G.
Jones
G.
92001200
Smith
A.
94001020
Smith
Student
name
G.
Jones
G.
92001200
Smith
A.
94001020
Smith
Unit 4
99111120
address
1234 W.
12th Ave.
2020 E.
th
18 St.
2020 E.
18th St.
th
1234 W. 12
Ave.
2020 E. 18 th
St.
2020 E. 18 th
St.
city
acode phone
Victoria
250
Van
604
Van
604
major
889-4444
CPSC
409-2222
MATH
222-2222
CPSC
G. Tsiknis
Unit 4
sid
address
Example (Contd.)
name
99111120
sid is the key: sid name, address, city, acode, phone, major
city determines area_code : city acode
sid
phone
Vict
889-4444
CPSC
Van
409-2222
MATH
Van
222-2222
CPSC
G. Tsiknis
major
city
sid acode
FDs in F hold.
ACode
city
acode
Vict 250
Reflexivity: If Y X, then X Y
Augmentation: If X Y, then X Z Y Z for any Z
Transitivity: If X Y and Y Z, then X Z
Van 604
Unit 4
G. Tsiknis
Example: Supplier-Part DB
n Suppliers supply parts to projects.
n Functional dependencies:
df1:
fd2:
fd3:
fd4:
given
1, augmentation
2, augmentation
3, 4, transitivity
G. Tsiknis
G. Tsiknis
df1:
fd2:
fd3:
fd4:
Unit 4
G. Tsiknis
10
reflex
fd1, decomp
2, fd2, trans
2, aug
3, aug
1, 5, union
4, 6, union
7, fd4, union
11
Unit 4
G. Tsiknis
12
SupplierPart(s#,sname,city,status,p#,pname,qty)
n fd1: s# sname, city
n fd2: city status
n fd3: p# pname
n fd4: s#, p# qty
{s#}+ =
{p#}+ =
{s#,p#}+ =
G. Tsiknis
Unit 4
13
Normal Forms
Unit 4
14
sets of values)
n A table is by definition in 1NF:
All fields have single values
Atomicity is subjective, within reason (e.g., yyyy-mm-dd, 123 Main
Street)
But, tables cannot have 2 entries for the same cell (e.g., for
author, you cant enter Raghu Ramakrishnan & Johannes
Gehrke in the same cell)
G. Tsiknis
G. Tsiknis
15
n
n
n
n
Unit 4
G. Tsiknis
16
G. Tsiknis
17
Unit 4
18
Lossless-Join Decompositions
n Definitions: If r, r1, r2 are relations and X, Y are sets of attributes:
X(r) is the part of r that contains the attributes X (vertical slice)
r1 >< r2 is the join of the two relations; i.e. each tuple of r1 is joint with
every tuple in r2 that has the same values on the common attributes.
straightforward way.
G. Tsiknis
19
Unit 4
G. Tsiknis
20
Lossless-Join Check
n The decomposition of R into X and Y is lossless-join wrt
A
1
4
7
B
2
5
2
C
3
6
8
decom
pose
A
1
4
7
B
2
5
2
B
2
5
2
C
3
6
8
join
A
1
4
7
1
7
B
2
5
2
2
2
X n Y X, or
X n Y Y
I.e. the common attributes of X and Y contain a key for either X or
Y
C
3
6
8
8
3
n Therefore, if
Unit 4
G. Tsiknis
21
G. Tsiknis
Unit 4
22
n Example:
Relation: (C, S, J, D, P, Q, V ),
FDs: C S J D P Q V, J PC, S DP, JS
n Is this in BCNF?
C+ =
(S D)+ =
(JP)+ =
J+=
n Decomposition:
(C, S, J, D, P, Q, V )
Remember: For all non-trivial functional dependencies Xb,
X must be a superkey for a relation to be in BCNF
(C, S, J, D, Q, V )
(C, J, D, Q, V )
(S, D, P)
(J, S)
order in which we ``deal with them could lead to very different sets of
relations!
Unit 4
G. Tsiknis
23
Unit 4
G. Tsiknis
24
Relations: R(J,K,L,M,N)
FD: JKL, KLM, LMN, MNJ, NJK
BUT
n Such decomposition may not preserve the dependencies
Is this in BCNF?
Y is dependency-preserving decomposition if
for any FD g, if g is implied from F, g is also implied
from the restrictions of F to X and Y, and vice versa.
n Example:
Relation: (company, plant, product)
FDs: plant company
company, product plant
Decomposition: (plant, company) (plant, product)
G. Tsiknis
Unit 4
25
plant
product
Oshava-GM
GM
St. Catharines-GM
GM
Oshava-GM
St. Catharines-GM
engine
engine
Lets put all the data back into a single table again:
company
plant
product
GM
Oshava-GM
engine
GM
St. Catharines-GM
engine
plant company
company, product plant
Keys: {company, product}, {plant,Product}
Is it in BCNF? 3NF?
FDs :
26
plant
Unit 4
G. Tsiknis
Unit 4
27
Unit 4
G. Tsiknis
28
3NF vs BCNF
n Any relation with 2 attributes is in 3NF and in BCNF
Closure of F = closure of G
Right hand side of each FD in G is a single attribute
If we modify G by deleting an FD or by deleting attributes from an FD
in G, the closure changes.
G. Tsiknis
29
Unit 4
RHS)
2. Minimize LHS of each FD
3. Delete Redundant FDs
Example:
AB, ABCDE, EFG, EFH, ACDF EG
G. Tsiknis
30
Unit 4
G. Tsiknis
31
Unit 4
G. Tsiknis
32
Denormalization
preserve dependencies
n 3NF may not be satisfactory if a relation has multiple &
overlapping keys
n BCNF decomposition is always lossless, but may not
preserve dependencies
n Good heuristic :
G. Tsiknis
33
Unit 4
G. Tsiknis
34