Tutorial 9 DB Normalization
Tutorial 9 DB Normalization
Overview
• Check if a decomposition is lossless-join
• Check if a decomposition is dependency preserving
• Check if a decomposition is in BCNF
• Perform lossless join decomposition into relations in BCNF
2
Testing lossless join
• Given relation 𝑅 decomposed into 𝑅1 and 𝑅2.
• Let 𝐴𝑡𝑡 𝑅 be the set of attributes in relation 𝑅. Decomposition is
lossless if
𝐴𝑡𝑡 𝑅1 ∩ 𝐴𝑡𝑡 𝑅2 → 𝐴𝑡𝑡 𝑅1
Or
𝐴𝑡𝑡 𝑅1 ∩ 𝐴𝑡𝑡 𝑅2 → 𝐴𝑡𝑡 𝑅2
3
Reflexivity – if 𝛽 ⊆ 𝛼, then 𝛼 → 𝛽.
Transitivity – if 𝛼 → 𝛽 and 𝛽 → 𝛾, then 𝛼 → 𝛾
𝐵
𝑅
𝑅
4
Testing dependency preserving
• Given relation 𝑅 with FD 𝑭 decomposed into 𝑅1 , 𝑅2 , … let 𝑭𝑖 be the
set of FDs in 𝑭+ that include only attributes in 𝑅𝑖
• Decomposition is dependency preserving if
+
𝑭1 ∪ 𝑭2 ∪ ⋯ = 𝑭+
5
Reflexivity – if 𝛽 ⊆ 𝛼, then 𝛼 → 𝛽.
Transitivity – if 𝛼 → 𝛽 and 𝛽 → 𝛾, then 𝛼 → 𝛾
6
Testing BCNF for relation
• Given relation 𝑅 with FD 𝑭
• 𝑅 is in BCNF if for all non-trivial dependency 𝛼 → 𝛽 in 𝑭,
+
𝛼 = 𝐴𝑡𝑡(𝑅)
7
Testing for BCNF
To check if a non-trivial dependency a®b causes a violation of BCNF
1. compute a+ (the attribute closure of a), and
2. verify that it includes all attributes of R, that is, it is a superkey of R.
Simplified test: To check if a relation schema R is in BCNF, it suffices
to check only the dependencies in the given set F for violation of BCNF,
rather than checking all dependencies in F+.
If none of the dependencies in F causes a violation of BCNF, then
none of the dependencies in F+ will cause a violation of BCNF
either.
However, simplified test using only F is incorrect when testing a
relation in a decomposition of R
Consider R = (A, B, C, D, E), with F = { A ® B, BC ® D}
4 Decompose R into R1 = (A,B) and R2 = (A,C,D, E)
Database System Concepts - 6th Edition 8.45 ©Silberschatz, Korth and Sudarshan
Reflexivity – if 𝛽 ⊆ 𝛼, then 𝛼 → 𝛽.
Transitivity – if 𝛼 → 𝛽 and 𝛽 → 𝛾, then 𝛼 → 𝛾
8
Reflexivity – if 𝛽 ⊆ 𝛼, then 𝛼 → 𝛽.
Transitivity – if 𝛼 → 𝛽 and 𝛽 → 𝛾, then 𝛼 → 𝛾
9
Decomposing relations
• Given relation 𝑅 with FD 𝑭. (where 𝑅 is not in BCNF)
• Pick a dependency 𝛼 → 𝛽 in 𝑭.
• Split 𝑅 into relation 𝑅1 = 𝛼 ∪ 𝛽 and 𝑅2 = 𝛼 ∪ 𝛼 ∪ 𝛽 𝑐 .
• Check that 𝑅1 is in BCNF, decompose 𝑅1 if not.
• Check that 𝑅2 is in BCNF, decompose 𝑅2 if not.
10
Reflexivity – if 𝛽 ⊆ 𝛼, then 𝛼 → 𝛽.
Transitivity – if 𝛼 → 𝛽 and 𝛽 → 𝛾, then 𝛼 → 𝛾
• Common attributes: 𝐶
• 𝐶 + = 𝐶 , which doesn’t cover 𝑅1 nor 𝑅2.
• It is not a lossless join decomposition.
13
Given 𝑅 𝐴, 𝐵, 𝐶, 𝐷 , 𝑭 = 𝐴 → 𝐵, 𝐵𝐶 → 𝐷, 𝐷 → 𝐴
Answer – 2 If 𝑅 is decomposed into 𝑅3(𝐴, 𝐵, 𝐶) and 𝑅4 𝐵, 𝐶, 𝐷 , is it a
lossless join decomposition? If so, is it dependency preserving?
• Common attributes: 𝐵, 𝐶
• 𝐵, 𝐶 + = 𝐵, 𝐶, 𝐷 , which covers 𝑅4.
• It is a lossless join decomposition.
• Consider FDs in 𝑅3 (𝑭3 ) = 𝐴 → 𝐵, 𝐵𝐶 → 𝐴, and trivials FDs
• Consider FDs in 𝑅4 (𝑭4 ) = 𝐵𝐶 → 𝐷, and trivials FDs
• Now consider 𝐷 + for 𝑭3 ∪ 𝑭4 + , 𝐷 + = 𝐷 . Dependency 𝐷 → 𝐴
is gone. Therefore, it is not dependency preserving.
14
Given 𝑅 𝐴, 𝐵, 𝐶, 𝐷 , 𝑭 = 𝐴 → 𝐵, 𝐵𝐶 → 𝐷, 𝐷 → 𝐴
Answer – 3 Show that 𝑅 in not in BCNF.
15
Answer – 4 Given 𝑅 𝐴, 𝐵, 𝐶, 𝐷 , 𝑭 = 𝐴 → 𝐵, 𝐵𝐶 → 𝐷, 𝐷 → 𝐴
Give a lossless join decomposition of 𝑅 into relations in BCNF.
Pick 𝐴 → 𝐵 Check if the decomposition is dependency preserving.
16
Answer – 4 Given 𝑅 𝐴, 𝐵, 𝐶, 𝐷 , 𝑭 = 𝐴 → 𝐵, 𝐵𝐶 → 𝐷, 𝐷 → 𝐴
Give a lossless join decomposition of 𝑅 into relations in BCNF.
Pick 𝐵𝐶 → 𝐷 Check if the decomposition is dependency preserving.
17
Answer – 4 Given 𝑅 𝐴, 𝐵, 𝐶, 𝐷 , 𝑭 = 𝐴 → 𝐵, 𝐵𝐶 → 𝐷, 𝐷 → 𝐴
Give a lossless join decomposition of 𝑅 into relations in BCNF.
Pick 𝐷 → 𝐴 Check if the decomposition is dependency preserving.
18
Answer – 5 Given 𝑅 𝐴, 𝐵, 𝐶, 𝐷, 𝐸 , 𝑭 = 𝐴 → 𝐵, 𝐴𝐷 → 𝐸, 𝐶 → 𝐴𝐷𝐸 .
Give a lossless join decomposition of 𝑅 into relations in BCNF.
Pick 𝐴 → 𝐵 Check if the decomposition is dependency preserving.