CH 8
CH 8
Relational Database
1
Design
A B C A B B C
1 A 1 1 A
2 B 2 2 B
r A,B(r) B,C(r)
A B C
A (r) B (r)
1 A
2 B
1 4
1 5
3 7
On this instance, A → B does NOT hold, but B → A does
hold.
In general, → is trivial if
→
→ is trivial (i.e., )
is a superkey for R
inst_info
D. NAGA JYOTHI CSE DEPT.
How good is BCNF? (Cont.)
23
ID child_name
ID phone
512-555-1234
inst_phone 99999
512-555-4321
99999
512-555-1234
99999
512-555-4321
99999
AG → I
by augmenting A → C with G, to get AG → CG
and then transitivity with CG → I
CG → HI
by augmenting CG → I to infer CG → CGI,
and augmenting of CG → H to infer CGI → HI,
and then transitivity
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
result := ;
while (changes to result) do
for each → in F do
begin
if result then result := result
end
A Closure
F = {A → B
→C
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)
Is AG a candidate key?
1. Is AG a super key?
1. Does AG → R? == Is (AG)+ R
2. Is any subset of AG a superkey?
1. Does A → R? == Is (A)+ R
2. D. Does G →CSE
NAGA JYOTHI
R?DEPT.
== Is (G)+ R
Uses of Attribute Closure
33
There are several uses of the attribute closure algorithm:
Testing for superkey:
To test if is a superkey, we compute +, and check if + contains all
attributes of R.
Testing functional dependencies
To check if a functional dependency → holds (or, in other words,
is in F+), just check if +.
That is, we compute + by using attribute closure, and then check if
it contains .
Is a simple and cheap test, and very useful
Computing closure of F
For each R, we find the closure +, and for each S +, we output
a functional dependency → S.
Either test R for BCNF with respect to the restriction of F to R (that is,
i i
all FDs in F+ that contain only attributes from Ri)
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.
course is in BCNF
How do we know this?
building, room_number→capacity holds on class-1
but {building, room_number} is not a superkey for class-1.
We replace class-1 by:
classroom (building, room_number, capacity)
section (course_id, sec_id, semester, year, building,
room_number, time_slot_id)
R = (J, K, L )
F = {JK → L
L→K}
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
i_ID → dept_name
dept_name is contained in a candidate key
null l2 k2
where Ri and →→ is in D+