lecture 6: design theory · fds for relational schema design •high-level idea: why do we care...
TRANSCRIPT
![Page 1: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/1.jpg)
Lecture6:DesignTheory
Lectures6
![Page 2: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/2.jpg)
Announcements
• SolutionstoPS1arepostedonline.Gradescomingsoon!
• Projectpart1isout.• Checkyourgroupsandletusknowifyouhaveanyissues.• Wehaveassignedpeopletogroupsthathadonlytwomembers.
• ActivitiesandNotebooksarethereforyourbenefit!
Lecture6
![Page 3: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/3.jpg)
Lecture6:DesignTheoryI
Lecture6
![Page 4: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/4.jpg)
Today’sLecture
1. Normalforms&functionaldependencies• ACTIVITY:FindingFDs
2. Findingfunctionaldependencies
3. Closures,superkeys &keys• ACTIVITY:Thekeyorakey?
4
Lecture6
![Page 5: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/5.jpg)
1.Normalforms&functionaldependencies
5
Lecture6>Section1
![Page 6: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/6.jpg)
Whatyouwilllearnaboutinthissection
1. Overviewofdesigntheory&normalforms
2. Dataanomalies&constraints
3. Functionaldependencies
4. ACTIVITY:FindingFDs
6
Lecture6>Section1
![Page 7: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/7.jpg)
DesignTheory
• Designtheoryisabouthowtorepresentyourdatatoavoidanomalies.
• Itisamostlymechanicalprocess• Toolscancarryoutroutineportions
• Wehaveanotebookimplementingallalgorithms!• We’llplaywithitintheactivities!
Lecture6>Section1>Overview
![Page 8: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/8.jpg)
NormalForms• 1st NormalForm(1NF) =Alltablesareflat
• 2nd NormalForm =disused
• Boyce-Codd NormalForm(BCNF)
• 3rd NormalForm(3NF)
• 4thand5th NormalForms =seetextbooks
DBdesignsbasedonfunctionaldependencies,intendedtopreventdataanomalies
Ourfocusforthislecture+thenexttwoones
Lecture6>Section1>Overview
![Page 9: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/9.jpg)
1st NormalForm(1NF)
Student CoursesMary {CS564,CS368}Joe {CS564,CS552}… …
Violates1NF.
1NFConstraint:Typesmustbeatomic!
Student CoursesMary CS564Mary CS368Joe CS564Joe CS552
In1st NF
Lecture6>Section1>Overview
![Page 10: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/10.jpg)
DataAnomalies&Constraints
Lecture6>Section1>Dataanomalies&constraints
![Page 11: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/11.jpg)
ConstraintsPrevent(some)AnomaliesintheData
Student Course RoomMary CS564 B01Joe CS564 B01Sam CS564 B01.. .. ..
Ifeverycourseisinonlyoneroom,containsredundantinformation!
Apoorlydesigneddatabasecausesanomalies:
Lecture6>Section1>Dataanomalies&constraints
![Page 12: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/12.jpg)
ConstraintsPrevent(some)AnomaliesintheData
Student Course RoomMary CS564 B01Joe CS564 C12Sam CS564 B01.. .. ..
Ifweupdatetheroomnumberforonetuple,wegetinconsistentdata=anupdate anomaly
Apoorlydesigneddatabasecausesanomalies:
Lecture6>Section1>Dataanomalies&constraints
![Page 13: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/13.jpg)
ConstraintsPrevent(some)AnomaliesintheData
Student Course Room.. .. ..
Ifeveryonedropstheclass,welosewhatroomtheclassisin!=adelete anomaly
Apoorlydesigneddatabasecausesanomalies:
Lecture6>Section1>Dataanomalies&constraints
![Page 14: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/14.jpg)
ConstraintsPrevent(some)AnomaliesintheData
Student Course RoomMary CS564 B01Joe CS564 B01Sam CS564 B01.. .. ..
Similarly,wecan’treservearoomwithoutstudents=aninsertanomaly
Apoorlydesigneddatabasecausesanomalies:
… CS368 C12
Lecture6>Section1>Dataanomalies&constraints
![Page 15: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/15.jpg)
ConstraintsPrevent(some)AnomaliesintheData
Student CourseMary CS564Joe CS564Sam CS564.. ..
Course RoomCS564 B01CS368 C12
Today:developtheorytounderstandwhythisdesignmaybebetterand howtofindthisdecomposition…
Isthisformbetter?
• Redundancy?• Updateanomaly?• Deleteanomaly?• Insertanomaly?
Lecture6>Section1>Dataanomalies&constraints
![Page 16: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/16.jpg)
FunctionalDependencies
Lecture6>Section1>Functionaldependencies
![Page 17: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/17.jpg)
FunctionalDependency
A->Bmeansthat“whenevertwotuplesagreeonAthentheyagreeonB.”
Def:LetA,Bbesets ofattributesWewriteAà BorsayAfunctionallydeterminesBif,foranytuplest1 andt2:
t1[A]=t2[A]impliest1[B]=t2[B]
andwecallAà Bafunctionaldependency
Lecture6>Section1>Functionaldependencies
![Page 18: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/18.jpg)
APictureOfFDs
A1 … Am B1 … Bn
Defn (again):GivenattributesetsA={A1,…,Am} andB={B1,…Bn}inR,
Lecture6>Section1>Functionaldependencies
![Page 19: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/19.jpg)
A1 … Am B1 … Bn
APictureOfFDs
ti
tj
Defn (again):GivenattributesetsA={A1,…,Am} andB={B1,…Bn}inR,
Thefunctionaldependency Aà BonRholdsifforanyti,tj inR:
Lecture6>Section1>Functionaldependencies
![Page 20: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/20.jpg)
APictureOfFDsDefn (again):GivenattributesetsA={A1,…,Am} andB={B1,…Bn}inR,
Thefunctionaldependency Aà BonRholdsifforanyti,tj inR:
ti[A1]=tj[A1]ANDti[A2]=tj[A2]AND…ANDti[Am]=tj[Am]
A1 … Am B1 … Bn
ti
tj
Ift1,t2agreehere..
Lecture6>Section1>Functionaldependencies
![Page 21: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/21.jpg)
APictureOfFDsDefn (again):GivenattributesetsA={A1,…,Am} andB={B1,…Bn}inR,
Thefunctionaldependency Aà BonRholdsifforanyti,tj inR:
if ti[A1]=tj[A1]ANDti[A2]=tj[A2]AND…ANDti[Am]=tj[Am]
then ti[B1]=tj[B1]ANDti[B2]=tj[B2]AND…ANDti[Bn]=tj[Bn]
A1 … Am B1 … Bn
ti
tj
Ift1,t2agreehere.. …theyalsoagreehere!
Lecture6>Section1>Functionaldependencies
![Page 22: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/22.jpg)
FDsforRelationalSchemaDesign
• High-levelidea:whydowecareaboutFDs?
1. Startwithsomerelationalschema
2. Modelitsfunctionaldependencies(FDs)
3. Usethesetodesignabetterschema1. Onewhichminimizesthepossibilityofanomalies
Lecture6>Section1>Functionaldependencies
![Page 23: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/23.jpg)
FunctionalDependenciesasConstraints
Student Course RoomMary CS564 B01Joe CS564 B01Sam CS564 B01.. .. ..
Note:TheFD{Course}->{Room}holdsonthisinstance
Afunctionaldependencyisaformofconstraint
• Holds onsomeinstancesnotothers.
• Partoftheschema,helpsdefineavalidinstance.
Lecture6>Section1
Recall:aninstance ofaschemaisamultiset oftuplesconformingtothatschema,i.e.atable
![Page 24: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/24.jpg)
FunctionalDependenciesasConstraints
Student Course RoomMary CS564 B01Joe CS564 B01Sam CS564 B01.. .. ..
However,cannotprovethattheFD{Course}->{Room}ispartoftheschema
Notethat:• YoucancheckifanFDis
violated byexaminingasingleinstance;
• However,youcannotprovethatanFDispartoftheschemabyexaminingasingleinstance.• Thiswouldrequirechecking
everyvalidinstance
Lecture6>Section1
![Page 25: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/25.jpg)
25
MoreExamplesAnFDisaconstraintwhichholds,ordoesnothold onaninstance:
EmpID Name Phone PositionE0045 Smith 1234 ClerkE3542 Mike 9876 SalesrepE1111 Smith 9876 SalesrepE9999 Mary 1234 Lawyer
Lecture6>Section1>Functionaldependencies
![Page 26: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/26.jpg)
26
{Position}à {Phone}
EmpID Name Phone PositionE0045 Smith 1234 ClerkE3542 Mike 9876 ¬ SalesrepE1111 Smith 9876 ¬ SalesrepE9999 Mary 1234 Lawyer
MoreExamples
Lecture6>Section1>Functionaldependencies
![Page 27: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/27.jpg)
27
EmpID Name Phone PositionE0045 Smith 1234 ® ClerkE3542 Mike 9876 SalesrepE1111 Smith 9876 SalesrepE9999 Mary 1234 ® Lawyer
butnot {Phone}à {Position}
MoreExamples
Lecture6>Section1>Functionaldependencies
![Page 28: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/28.jpg)
ACTIVITY
28
Lecture6>Section1>ACTIVITY
A B C D E
1 2 4 3 63 2 5 1 81 4 4 5 71 2 4 3 63 2 5 1 8
Findatleastthree FDswhichareviolatedonthisinstance:
{ } à { }{ } à { }{ } à { }
![Page 29: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/29.jpg)
2.Findingfunctionaldependencies
29
Lecture6>Section2
![Page 30: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/30.jpg)
Whatyouwilllearnaboutinthissection
1. “Good”vs.“Bad”FDs:Intuition
2. FindingFDs
3. Closures
4. ACTIVITY:Computetheclosures
30
Lecture6>Section2
![Page 31: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/31.jpg)
31
“Good”vs.“Bad”FDs
Wecanstarttodevelopanotionofgoodvs.bad FDs:
EmpID Name Phone PositionE0045 Smith 1234 ClerkE3542 Mike 9876 SalesrepE1111 Smith 9876 SalesrepE9999 Mary 1234 Lawyer
Intuitively:
EmpID ->Name,Phone,Positionis“goodFD”• Minimalredundancy,
lesspossibilityofanomalies
Lecture6>Section2>Goodvs.BadFDs
![Page 32: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/32.jpg)
32
“Good”vs.“Bad”FDs
Wecanstarttodevelopanotionofgoodvs.bad FDs:
EmpID Name Phone PositionE0045 Smith 1234 ClerkE3542 Mike 9876 SalesrepE1111 Smith 9876 SalesrepE9999 Mary 1234 Lawyer
Intuitively:
EmpID ->Name,Phone,Positionis“goodFD”
ButPosition->Phoneisa“badFD”• Redundancy!
Possibilityofdataanomalies
Lecture6>Section2>Goodvs.BadFDs
![Page 33: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/33.jpg)
Student Course RoomMary CS564 B01Joe CS564 B01Sam CS564 B01.. .. ..
GivenasetofFDs(fromuser)ourgoalisto:1. FindallFDs,and2. Eliminatethe“BadOnes".
Returningtoouroriginalexample…canyouseehowthe“badFD”{Course}->{Room}couldleadtoan:• UpdateAnomaly• InsertAnomaly• DeleteAnomaly• …
“Good”vs.“Bad”FDs
Lecture6>Section2>Goodvs.BadFDs
![Page 34: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/34.jpg)
FDsforRelationalSchemaDesign
• High-levelidea:whydowecareaboutFDs?
1. Startwithsomerelationalschema
2. Findoutitsfunctionaldependencies(FDs)
3. Usethesetodesignabetterschema1. Onewhichminimizespossibilityofanomalies
Lecture6>Section2>FindingFDs
Thispartcanbetricky!
![Page 35: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/35.jpg)
FindingFunctionalDependencies
• Therecanbeaverylargenumber ofFDs…• Howtofindthemallefficiently?
• Wecan’tnecessarilyshowthatanyFDwillholdonallinstances…• Howtodothis?
Wewillstartwiththisproblem:GivenasetofFDs,F,whatotherFDsmusthold?
Lecture6>Section2>FindingFDs
![Page 36: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/36.jpg)
Equivalenttoasking:GivenasetofFDs,F={f1,…fn},doesanFDghold?
Inferenceproblem:Howdowedecide?
FindingFunctionalDependencies
Lecture6>Section2>FindingFDs
![Page 37: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/37.jpg)
FindingFunctionalDependencies
1.{Name}à {Color}2.{Category}à {Department}3.{Color,Category}à {Price}
Name Color Category Dep PriceGizmo Green Gadget Toys 49Widget Black Gadget Toys 59Gizmo Green Whatsit Garden 99
Which/howmanyotherFDsdo?!?
ProvidedFDs:Products
GiventheprovidedFDs,wecanseethat{Name,Category}à {Price}mustalsoholdonanyinstance…
Example:
Lecture6>Section2>FindingFDs
![Page 38: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/38.jpg)
Equivalenttoasking:GivenasetofFDs,F={f1,…fn},doesanFDghold?
Inferenceproblem:Howdowedecide?
Answer:ThreesimplerulescalledArmstrong’sRules.
1. Split/Combine,2. Reduction,and3. Transitivity…ideasbypicture
FindingFunctionalDependencies
Lecture6>Section2>FindingFDs
![Page 39: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/39.jpg)
1.Split/Combine
A1 … Am B1 … Bn
A1,…,Am à B1,…,Bn
Lecture6>Section2>FindingFDs
![Page 40: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/40.jpg)
1.Split/Combine
A1 … Am B1 … Bn
A1,…,Am à B1,…,Bn
…isequivalenttothefollowingn FDs…
A1,…,Am à Bi fori=1,…,n
Lecture6>Section2>FindingFDs
![Page 41: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/41.jpg)
1.Split/Combine
A1 … Am B1 … Bn
A1,…,Am à B1,…,Bn
…isequivalentto…
Andvice-versa,A1,…,Am à Bi fori=1,…,n
Lecture6>Section2>FindingFDs
![Page 42: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/42.jpg)
2.Reduction/TrivialA1 … Am
A1,…,Am à Aj foranyj=1,…,m
Lecture6>Section2>FindingFDs
![Page 43: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/43.jpg)
3.TransitiveClosure
A1 … Am B1 … Bn C1 … Ck
A1,…,Am à B1,…,Bn andB1,…,Bn à C1,…,Ck
Lecture6>Section2>FindingFDs
![Page 44: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/44.jpg)
3.TransitiveClosure
A1 … Am B1 … Bn C1 … Ck
A1,…,Am à B1,…,Bn andB1,…,Bn à C1,…,Ck
impliesA1,…,Am à C1,…,Ck
Lecture6>Section2>FindingFDs
![Page 45: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/45.jpg)
FindingFunctionalDependencies
1.{Name}à {Color}2.{Category}à {Department}3.{Color,Category}à {Price}
Name Color Category Dep PriceGizmo Green Gadget Toys 49Widget Black Gadget Toys 59Gizmo Green Whatsit Garden 99
Which/howmanyotherFDshold?
ProvidedFDs:Products
Example:
Lecture6>Section2>FindingFDs
![Page 46: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/46.jpg)
FindingFunctionalDependencies
1.{Name}à {Color}2.{Category}à {Dept.}3.{Color,Category}à{Price}
Which/howmanyotherFDshold?
ProvidedFDs:InferredFDs:
Example:
Inferred FD Ruleused
4. {Name,Category}->{Name} ?5.{Name,Category}->{Color} ?6.{Name,Category} ->{Category} ?7.{Name,Category ->{Color,Category} ?8.{Name,Category}->{Price} ?
Lecture6>Section2>FindingFDs
![Page 47: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/47.jpg)
FindingFunctionalDependencies
1.{Name}à {Color}2.{Category}à {Dept.}3.{Color,Category}à{Price}
Canwefindanalgorithmicwaytodothis?
ProvidedFDs:InferredFDs:
Example:
Inferred FD Ruleused
4. {Name,Category}->{Name} Trivial5.{Name,Category}->{Color} Transitive (4->1)6.{Name,Category} ->{Category} Trivial7.{Name,Category ->{Color,Category} Split/combine (5+6)8.{Name,Category}->{Price} Transitive(7-> 3)
Lecture6>Section2>FindingFDs
![Page 48: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/48.jpg)
Closures
Lecture6>Section2 >Closures
![Page 49: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/49.jpg)
49
ClosureofasetofAttributes
Given asetofattributesA1,…,An andasetofFDsF:Thentheclosure,{A1,…,An}+ isthesetofattributesB s.t. {A1,…,An}à B
{name} à {color}{category} à {department}{color, category} à {price}
Example: F=
ExampleClosures:
{name}+ = {name, color}{name, category}+ ={name, category, color, dept, price}{color}+ = {color}
Lecture6>Section2 >Closures
![Page 50: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/50.jpg)
50
ClosureAlgorithm
StartwithX={A1,…,An}andsetofFDsF.
Repeatuntil Xdoesn’tchange;do:
if {B1,…,Bn}à CisentailedbyF
and {B1,…,Bn}⊆ X
then addCtoX.
Return XasX+
Lecture6>Section2 >Closures
![Page 51: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/51.jpg)
51
ClosureAlgorithmStartwithX={A1,…,An},FDsF.Repeatuntil Xdoesn’tchange;do:if {B1,…,Bn}à CisinFand {B1,
…,Bn}⊆ X:then addCtoX.
Return XasX+
{name} à {color}
{category} à {dept}
{color, category} à{price}
F=
{name, category}+ ={name, category}
Lecture6>Section2 >Closures
![Page 52: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/52.jpg)
52
ClosureAlgorithmStartwithX={A1,…,An},FDsF.Repeatuntil Xdoesn’tchange;do:if {B1,…,Bn}à CisinFand {B1,
…,Bn}⊆ X:then addCtoX.
Return XasX+
{name} à {color}
{category} à {dept}
{color, category} à{price}
F=
{name, category}+ ={name, category}
{name, category}+ ={name, category, color}
Lecture6>Section2 >Closures
![Page 53: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/53.jpg)
53
ClosureAlgorithmStartwithX={A1,…,An},FDsF.Repeatuntil Xdoesn’tchange;do:if {B1,…,Bn}à CisinFand {B1,
…,Bn}⊆ X:then addCtoX.
Return XasX+
{name} à {color}
{category} à {dept}
{color, category} à{price}
F=
{name, category}+ ={name, category}
{name, category}+ ={name, category, color}
{name, category}+ ={name, category, color, dept}
Lecture6>Section2 >Closures
![Page 54: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/54.jpg)
54
ClosureAlgorithmStartwithX={A1,…,An},FDsF.Repeatuntil Xdoesn’tchange;do:if {B1,…,Bn}à CisinFand {B1,
…,Bn}⊆ X:then addCtoX.
Return XasX+
F=
{name, category}+ ={name, category}
{name, category}+ ={name, category, color, dept, price}
{name, category}+ ={name, category, color}
{name, category}+ ={name, category, color, dept}{name} à {color}
{category} à {dept}
{color, category} à{price}
Lecture6>Section2 >Closures
![Page 55: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/55.jpg)
Example
55
Compute{A,B}+ ={A,B,}
Compute{A,F}+ ={A,F,}
R(A,B,C,D,E,F) {A,B} à {C}{A,D} à {E}{B} à {D}{A,F} à {B}
Lecture6>Section2 >Closures
![Page 56: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/56.jpg)
Example
56
Compute{A,B}+ ={A,B,C,D}
Compute{A,F}+ ={A,F,B}
R(A,B,C,D,E,F) {A,B} à {C}{A,D} à {E}{B} à {D}{A,F} à {B}
Lecture6>Section2 >Closures
![Page 57: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/57.jpg)
Example
57
Compute{A,B}+ ={A,B,C,D,E}
Compute{A,F}+ ={A,B,C,D,E,F}
R(A,B,C,D,E,F) {A,B} à {C}{A,D} à {E}{B} à {D}{A,F} à {B}
Lecture6>Section2 >Closures
![Page 58: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/58.jpg)
3.Closures,Superkeys &Keys
58
Lecture6>Section3
![Page 59: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/59.jpg)
Whatyouwilllearnaboutinthissection
1. ClosuresPt.II
2. Superkeys &Keys
3. ACTIVITY:Thekeyorakey?
59
Lecture6>Section3
![Page 60: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/60.jpg)
60
WhyDoWeNeed theClosure?
• WithclosurewecanfindallFD’seasily
• TocheckifX® A
1. ComputeX+
2. CheckifAÎ X+
NoteherethatX isaset ofattributes,butA isasingleattribute.
RecalltheSplit/combine rule:Xà A1,…,Xà AnimpliesXà {A1,…,An}
Lecture6>Section3>ClosuresPt.II
![Page 61: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/61.jpg)
61
UsingClosuretoInferALLFDs{A,B} à C{A,D} à B{B} à D
Example:GivenF=Step1:ComputeX+,foreverysetofattributesX:
{A}+ = {A}{B}+ = {B,D}{C}+ = {C}{D}+ = {D}{A,B}+ = {A,B,C,D}{A,C}+ = {A,C}{A,D}+ = {A,B,C,D}{A,B,C}+ = {A,B,D}+ = {A,C,D}+ = {A,B,C,D} {B,C,D}+ = {B,C,D}{A,B,C,D}+ = {A,B,C,D}
Noneedtocomputethese-why?
Lecture6>Section3>ClosuresPt.II
![Page 62: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/62.jpg)
62
UsingClosuretoInferALLFDs{A,B} à C{A,D} à B{B} à D
Example:GivenF=Step1:ComputeX+,foreverysetofattributesX:
{A}+ = {A}, {B}+ = {B,D}, {C}+ = {C}, {D}+ = {D}, {A,B}+ = {A,B,C,D}, {A,C}+ = {A,C}, {A,D}+ = {A,B,C,D}, {A,B,C}+ = {A,B,D}+ = {A,C,D}+ = {A,B,C,D}, {B,C,D}+ = {B,C,D}, {A,B,C,D}+ = {A,B,C,D}
Step2:EnumerateallFDsXà Y,s.t. YÍ X+ andXÇ Y=Æ:
{A,B} à {C,D}, {A,D} à {B,C},{A,B,C} à {D}, {A,B,D} à {C},{A,C,D} à {B}
Lecture6>Section3>ClosuresPt.II
![Page 63: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/63.jpg)
63
UsingClosuretoInferALLFDs{A,B} à C{A,D} à B{B} à D
Example:GivenF=
{A}+ = {A}, {B}+ = {B,D}, {C}+ = {C}, {D}+ = {D}, {A,B}+ = {A,B,C,D}, {A,C}+ = {A,C}, {A,D}+ = {A,B,C,D}, {A,B,C}+ = {A,B,D}+ = {A,C,D}+ = {A,B,C,D}, {B,C,D}+ = {B,C,D}, {A,B,C,D}+ = {A,B,C,D}
Step2:EnumerateallFDsXà Y,s.t. YÍ X+ andXÇ Y=Æ:
{A,B} à {C,D}, {A,D} à {B,C},{A,B,C} à {D}, {A,B,D} à {C},{A,C,D} à {B}
“YisintheclosureofX”
Lecture6>Section3>ClosuresPt.II
Step1:ComputeX+,foreverysetofattributesX:
![Page 64: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/64.jpg)
64
UsingClosuretoInferALLFDs{A,B} à C{A,D} à B{B} à D
Example:GivenF=
{A}+ = {A}, {B}+ = {B,D}, {C}+ = {C}, {D}+ = {D}, {A,B}+ = {A,B,C,D}, {A,C}+ = {A,C}, {A,D}+ = {A,B,C,D}, {A,B,C}+ = {A,B,D}+ = {A,C,D}+ = {A,B,C,D}, {B,C,D}+ = {B,C,D}, {A,B,C,D}+ = {A,B,C,D}
Step2:EnumerateallFDsXà Y,s.t. YÍ X+ andXÇ Y=Æ:
{A,B} à {C,D}, {A,D} à {B,C},{A,B,C} à {D}, {A,B,D} à {C},{A,C,D} à {B}
TheFDXà Yisnon-trivial
Lecture6>Section3>ClosuresPt.II
Step1:ComputeX+,foreverysetofattributesX:
![Page 65: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/65.jpg)
Superkeys andKeys
Lecture6>Section3>Superkeys &Keys
![Page 66: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/66.jpg)
KeysandSuperkeys
Asuperkey isasetofattributesA1,…,An s.t.foranyother attributeB inR,wehave {A1,…,An}à B
Akey isaminimal superkey
I.e.allattributesarefunctionallydeterminedbyasuperkey
Meaningthatnosubsetofakeyisalsoasuperkey
Lecture6>Section3>Superkeys &Keys
![Page 67: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/67.jpg)
FindingKeysandSuperkeys
• ForeachsetofattributesX
1. ComputeX+
2. IfX+=setofallattributesthenXisasuperkey
3. IfXisminimal,thenitisakey
Lecture6>Section3>Superkeys &Keys
![Page 68: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/68.jpg)
ExampleofFindingKeysProduct(name, price, category, color)
{name, category} à price{category} à color
Whatisakey?
Lecture6>Section3>Superkeys &Keys
![Page 69: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/69.jpg)
ExampleofKeysProduct(name, price, category, color)
{name, category} à price{category} à color
{name, category}+ = {name, price, category, color}= thesetofallattributes⟹ thisisasuperkey⟹ thisisakey,sinceneithername norcategoryaloneisasuperkey
Lecture6>Section3>Superkeys &Keys
![Page 70: Lecture 6: Design Theory · FDs for Relational Schema Design •High-level idea: why do we care about FDs? 1. Start with some relational schema 2. Find out its functional dependencies](https://reader033.vdocuments.mx/reader033/viewer/2022051604/60054e37a98f790e0115abef/html5/thumbnails/70.jpg)
Activity-6.ipynb
70
Lecture6>Section3 >ACTIVITY