BCNF & Lossless Decomposition: Prof. Sin-Min Lee Department of Computer Science
BCNF & Lossless Decomposition: Prof. Sin-Min Lee Department of Computer Science
BCNF & Lossless Decomposition: Prof. Sin-Min Lee Department of Computer Science
A B
1 4
1 5
3 7
• On this instance, A B does NOT hold, but B A does hold.
1. Closure
• Given a set of functional dependencies, F, its
closure, F+ , is all FDs that are implied by FDs in
F.
• e.g. If A B, and B C,
• then clearly A C
Armstrong’s Axioms
• We can find F+ by applying Armstrong’s Axioms:
– if , then (reflexivity)
– if , then (augmentation)
– if , and , then (transitivity)
• 1. Start with B = A.
• 2. Go over all functional dependencies, , in
F+
• 3. If B, then
• Add to B
• 4. Repeat till B changes
• R = (A, B, C, G, H, I) Example
F={ AB
AC
CG H
CG I
B H}
• (AG) + ?
• 1. result = AG
2. result = ABCG (A C and A B)
3. result = ABCGH (CG H and CG AGBC)
4. result = ABCGHI (CG I and CG AGBCH
• Determining if A B is a valid FD
• Check if A+ contains B
20 Research Hundredfold
30 Marketing Leeds
Deptno Location
Deptno Dname 10 Leeds
10 Bradfprd
10 IT
10 Kent
20 Research
20 Hundredfold
30 Marketing
30 Leeds
Second Normal Form (2NF)
Each attribute must be functionally dependent on
the primary key.
• If the primary key is a single attribute, then the relation is in 2NF
• The test for 2NF involves testing for FDs whose left-hand-side
attribute are part of the primary key
• Disallow partial dependency, where non-keys attributes depend on
part of a composite primary key
• In short, remove partial dependencies
Relation X2
EmpNo EName Salary Address
Third Normal Form (3NF)
Remove transitive dependencies.
Transitive dependency
A non-prime attribute is dependent on another, non-prime
attribute or attributes
Attribute is the result of a calculation
Examples:
Area code attribute based on City attribute of a customer
Total price attribute of order entry based on quantity attribute
and unit price attribute (calculated value)
Solution:
• Any transitive dependencies are moved into a smaller table.
Transitive Dependence
Give a relation R, EmpNo EName Salary Address
Assume the following FD hold:
Ename Address
Note : Both Ename and Address attributes are non-key attributes in R, and since
Address depends on a non-Prime attribute Name, which depends on the primary
key(EmpNo), a transitive dependency exists
EmpNo Ename, Ename Addresst , EmpNo Address
R1 R2
EmpNo EName Salary Ename Address
– STU-ADV(SID,Fname)
ADV-SUBJ(Fname,Subject)
Multi-valued Dependency
• Two or more functionally independent multi-
valued attributes are dependent on another
attribute
– EMPLOYEE(Name,Dependent,Project)
• Data redundancy and modification anomalies
• 4NF: BCNF & no multi-valued dependencies
– EMPLOYEE(Name,Dependent)
– EMPLOYEE(Name, Project)
Database Normalization
• Boyce-Codd Normal Form (BCNF)
– A relation is in Boyce-Codd normal form (BCNF) if
every determinant in the table is a candidate key.
(A determinant is any attribute whose value determines
other values with a row.)
Figure 5.7
The Decomposition of a Table Structure to Meet
BCNF Requirements
Figure 5.8
Lossless-join Decomposition
● For the case of R = (R1, R2), we require that
for all possible relations r on schema R
r = R1 (r ) |X| R2 (r )
● A decomposition of R into R1 and R2 is
lossless join if and only if at least one of the
following dependencies is in F : +
● R1 R2 R1
● R1 R2 R2
● R = (A, B, C)
F = {A B, B C)
● Can be decomposed in two different ways
● R1 = (A, B), R2 = (B, C)
● Lossless-join decomposition:
R1 R2 = {B} and B BC
● Dependency preserving
● R1 = (A, B), R2 = (A, C)
● Lossless-join decomposition:
R1 R2 = {A} and A AB
● Not dependency preserving
(cannot check B C without computing R1 |X| R2)
Dependency Preservation
● Let Fi be the set of dependencies F +
Table 5.2
Decomposition into BCNF
Perform lossless-join decompositions of each of the following
scheme into BCNF schemes: R(A, B, C, D, E) with dependency set
{AB CDE, C D, D E}
A B C D A B C D
C D A B C E D E A B C D
D E A B C C D A B C
Given the FDs {B D, AB C, D B} and the relation {A,
B, C, D}, give a two distinct lossless join decomposition to
BNCF indicating the keys of each of the resulting relations.
A B C D A B C D
B D A B C B D A C D
Definition of MVD
• A multivalued dependency (MVD)
X ->->Y is an assertion that if two tuples of
a relation agree on all the attributes of X,
then their components in the set of
attributes Y may be swapped, and the result
will be two tuples that are also in the
relation.
Example
• The name-addr-phones-beersLiked example
illustrated the MVD
name->->phones
and the MVD
name ->-> beersLiked.
Picture of MVD X ->->Y
X Y others
equal
exchange
MVD Rules
• Every FD is an MVD.
– If X ->Y, then swapping Y ’s between two tuples that
agree on X doesn’t change the tuples.
– Therefore, the “new” tuples are surely in the
relation, and we know X ->->Y.
• 1. Trivial
• 2. A is a superkey of R
• If not, then
• Choose a dependency in F+ that breaks the BCNF rules, say A B
• Create R1 = A B
• Create R2 = A (R – B – A)
• Note that: R1 ∩ R2 = A and A AB (= R1), so this is lossless decomposition
BC
• R1 = (B, C) • R2 = (A, B)
• F1 = {B C} • F2 = {A B}
• Candidate keys = {B} • Candidate keys = {A}
• BCNF = true • BCNF = true
• Example 2-1
R = (A, B, C, D, E)
• F = {A B, BC D}
• Candidate keys = {ACE}
• BCNF = Violated by {A B, BC D} etc…
• From A B and BC D
by pseudo-transitivity
AB
• R1 = (A, B) • R2 = (A, C, D, E)
• F1 = {A B} • F2 = {AC D}
• Candidate keys = {A} • Candidate keys = {ACE}
• BCNF = true • BCNF = false (AC D)
• Dependency preservation ???
• We can check: AC D • R4 = (A, C, E)
• A B (R1), AC D (R3), • F4 = {} [[ only trivial ]]
• but we lost BC D • Candidate keys = {ACE}
• R3 = (A, C, D) • BCNF = true
• So this is not a dependency • F3 = {AC D}
• -preserving decomposition
• Candidate keys = {AC}
• BCNF = true
• Example 2-2
R = (A, B, C, D, E)
• F = {A B, BC D}
• Candidate keys = {ACE}
• BCNF = Violated by {A B, BC D} etc…
BC D
• R1 = (B, C, D) • R2 = (B, C, A, E)
• F1 = {BC D} • F2 = {A B}
• Candidate keys = {BC} • Candidate keys = {ACE}
• BCNF = true • BCNF = false (A B)
• Dependency preservation ???
• We can check:
AB
• BC D (R1), A B (R3), • R3 = (A, B) • R4 = (A, C, E)
• Dependency-preserving • F4 = {} [[ only trivial ]]
• F3 = {A B}
• decomposition • Candidate keys = {ACE}
• Candidate keys = {A} • BCNF = true
• BCNF = true
Example 3
• R = (A, B, C, D, E, H)
• F = {A BC, E HA}
• Candidate keys = {DE}
• BCNF = Violated by {A BC} etc…
A BC
• R1 = (A, B, C) • R2 = (A, D, E, H)
• F1 = {A BC} • F2 = {E HA}
• Candidate keys = {A} • Candidate keys = {DE}
• BCNF = true • BCNF = false (E HA)
• Dependency preservation ???
• We can check: E HA
• R4 = (ED)
• A BC (R1), E HA (R3),
• F4 = {} [[ only
• Dependency-preserving • R3 = (E, H, A) trivial ]]
• decomposition • F3 = {E HA} • Candidate keys = {DE}
• Candidate keys = {E} • BCNF = true
• BCNF = true