Functional Dependencies
Functional Dependencies
FunctionalDependency(FD)
When ,ifvalueofaisofaspecificvalue,bmustbetheotherindicatedvalueandnotanother
value
Tablebelowshowsthat sinceifA=1,B=5.A=2,B=4.
A B
1 5
1 5
2 4
Tablebelowviolates sincewhenA=1,B=5&B=2.
A B
1 5
1 2
2 4
Trivial,Nontrivial,Completelynontrivial
Trivial, ,RHSissubsetofLHS
NonTrivial, ,LHSandRHSgotsomecommonattributes
CompletelyNonTrivial, ,LHSandRHStotallynolink
LogicallyImplies
ifeveryFDinFisinG
Closure
ClosureofFmeanseverythingthatcanbelinkeddirectly&indirectlyfrom1attributetoanother
e.g. , , , , , , ,
Startwith1FDandcalculatetherest.
Calculationofclosureattributes
GivenR(a,b,c,d)R={ , ,
Tofindclosureofe.g.
1. Startwith
2. Lookthroughthedependenciesandseeifanyotherattributescanbederievedfromother
FDs
from ,
from ,
3. WhenthereisnomorechangeswhenloopingthroughtheFDs,thentheresultistheClosure
ofthatattribute
EquivalentFD
if ,alsocanuse
Axioms
Reflexivity:given(a,b,c) .Subset
Augmentation: , .Multiplybothsidesbyy
Transitivity: ,
Union: ,
Decomposition: , ,
KeysStuff
Superkey:AbunchofattributesthatcandetermineallattributesinR,usuallyhaveredundant
attributes.Nocombinationofthekeysmustbethesameintherelation
Key/Candidatekey:AbunchofattributesthatcandetermineallattributesofRANDnosubsetof
thatkeycanbeasuperkey(noredundantattributes)
Todeterminethekey,lookforattributesmissingintheRHSandstartfromthere.
Primeattribute:AnattributethatisinsomekeyofR
Minimal/CanonicalCover
MinimalnumberofFDsrequiredthatstillmapsbacktoFDsofF
Step1:DecomposeallRHStosingleattributes
Step2:Removalofredundantattributes
ForeachoftheFDs
ForeachattributeintheLHSofanFD
1. Findtheclosureofthat(FDremoved)attribute
a. iftheclosurecontainstheRHS,thentheattributeisredundant
b. elseitisnotnonredundant
Step3:RemovalofredundantFDs
ForeachoftheFDs(afterremovalofredundantattributes)
1. FindclosureofLHSusingFDw.r.t(FwiththatFDremoved)
a. IfclosurecontainsRHS,redundant.
b. Elsenotredundant
Resultsinaminimalcover
Checkingforlossless
Ifmultipletables,findouthowtheyaredecomposedandcheckforeachbreakdowniflosslessornot
Alternatemethod
Createatablewhere
columns=#ofattributes
rows=#ofdecompositions
e.g. , , ,
, ,
Startwith
A B C D E G
X X
X X
X X X X
X X
ForeachFD,ifwehave2rowswithXforLHS,andatleast1XontheRHS.FilluptheRHSofthose
rowswithoutX.
A B C D E G
X X O
X X
X X X X
X X
Continuewiththerest(Repeatagainandagainuntilnomorecanbefilled)
A B C D E G
X X O O O
X X O
X X X X O
X X
IfthereisarowwithallX/O,thismeansdecompositionislossless,otherwiselossy(asinthis
example).Whatthisisdoingisjoiningthetablestoseeifwecangetbacktheoriginaldata)
LosslessJoinDecompositions
If isnontrivial.ThenthedecompositionofRinto , isalosslessjoindecomposition
Calculating :
1. Startwithresultasemptyset
2. LoopthrougheachattributeofFincludingcombinationsofattributes(calledb)
a. Computetheclosureofb
b. RemovenonrelatedFDsofa,byintersectingwitha.ThusLHSclosure
c. Addthe(LHSclosure)totheresultset
Checkingifdependencyispreserved
and Trivialtoproof,mainaimistoprooffirstcondition
IfthereisanFDinFsuchthattheunionsdontcontainf,thenitisnotdependencypreserving.
DependencyPreservingDecompositions
1. Computeprojections foreachtable
2. Unionalltheprojections,calledG
3. LoopthrougheachFD, ,inF
a. Compute wrtG
b. if doesnotcontainb,thenno
BoyceCoddNormalForm(BCNF)
Assumptions:RHSisasingleattribute
NotallschemashasadependencypreservingBCNF
TobeBCNF:ForeverynontrivialFD( )ofF,ifaisnotasupeykey,violatesBCNF.OnlyifALL
FDsdontviolatethenitisBCNF.
**CanonlycheckagainstoriginalFDwhencheckingiftheoriginalschemaisinBCNF**
**Whencheckingdecomposedschema,checkwithEVERY **
e.g. , , , , , andthat ,
in iscomputedfrom ,
BCNFProperty(lemma2)
Anyschemathathas2attributesisBCNF
BCNFTest/DecomposingtoBCNF(Input:Fand ,returnsnull/FDthatviolatesBCNF)
1. If2attributes,returnnull(BCNFPropertylemma2)
2. Loopthrougheachain
a. let w.r.tF( isanFDthatholdson )
b. ifX=a,FDistrivial,tossaway
c. ifX= ,alphaissuperkey,doesnotviolateBCNF,tossaway
d. elsereturn (SuchaFDviolatesBCNF)
3. returnnull
Example
, , , , ,with ,
, , , , , using from
, , , , , , , using from
BCNFatthispoint
ThirdNormalForm(3NF)
Guaranteeslosslessjoinandpreservedependencies
3NF:ForeverynontrivialFD ,aisasuperkeyorbisaprimeattribute(appearinsomekey)
Violationof3NF:ForeverynontrivialFD ,aisnotsuperkeyandbisnonprimeattribute
3NFDecomposition/Synthesisalgorithm
GivenFmustbeaminimalcoverofR.Returns3NFdecomposition.
1. Startanemptysetforresult
2. ApplyunionruleforFDscalledG(GroupFDswithsameLHS,reduceno.oftablescreated)
3. ForeachFDinG( )
a. Createschema ,
b. Addthisschematoresult(Willresultin#FDtables)
4. Chooseakeykandcreateatablewiththoseattributes(formissingattributesinFD)
5. Removeredundanttablesinresult(e.g.ABC,ABCD,canremovetablewithABC,ifsuperset,
removesmallerone)
6. Returnresult