DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades...

20
433 L15: Normalization CS3200 Database design (sp18 s2) https://course.ccs.neu.edu/cs3200sp18s2/ 3/12/2018

Transcript of DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades...

Page 1: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

433

L15:Normalization

CS3200 Databasedesign(sp18 s2)https://course.ccs.neu.edu/cs3200sp18s2/3/12/2018

Page 2: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

434

Announcements!

• KeepbringingyournameplatesJ• VerifyyourgradesandfeedbackonBB.Ifsomethingisunclearorconfusing,ordisplaysincorrectly,pleaseletusknow(e.g.,viaPiazzainstructorsonly)

• P2 ispostedandupdatedcalendar• Exam2 nextweek:contentiseverythingseenuntilthisThursday:setuplikeforExam1:laptopSQL+paperdatabasedesign+papertransactions

• Outlinetoday- HW4,Projects- Decompositions- Transactions!

Page 3: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

435

Page 4: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

436

Ryan'squestion:ParkingTickets:ERDiagram

STID LName FName PhoneNo StLic LicNo

Code Fine

Ticketnr Date Code@ STID@

Student

TicketCode

Ticket

Violation

Page 5: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

437

Ryan'squestion:ParkingTickets:ERDiagram

Page 6: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

438

Decompositions

Page 7: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

439

Recap:Decomposetoremoveredundancies

• Wesawthatredundanciesinthedata(“badFDs”)canleadtodataanomalies

• Wedevelopedmechanismstodetectandremoveredundanciesbydecomposingtablesinto3NF orBCNF- BCNF decompositionisstandardpractice- verypowerful&widelyused!

• However,sometimesdecompositionscanleadtomoresubtleunwantedeffects…

Whendoesthishappen?

Page 8: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

440

DecompositionsinGeneral

R1 =theprojection ofRonA1,...,An,B1,...,Bm

R(A1,...,An,B1,...,Bm,C1,...,Cp)

R1(A1,...,An,B1,...,Bm) R2(A1,...,An,C1,...,Cp)

R2 =theprojection ofRonA1,...,An,C1,...,Cp

Page 9: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

441

TheoryofDecomposition

Name Price CategoryGizmo 19.99 Gadget

OneClick 24.99 CameraGizmo 19.99 Camera

Name PriceGizmo 19.99

OneClick 24.99Gizmo 19.99

Name CategoryGizmo Gadget

OneClick CameraGizmo Camera

I.e.itisaLosslessdecomposition

Sometimesadecompositionis“correct”

Page 10: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

442

LossyDecomposition

Name CategoryGizmo Gadget

OneClick CameraGizmo Camera

Price Category19.99 Gadget24.99 Camera19.99 Camera

What’swronghere?

Howeversometimesitisn’tName Price Category

Gizmo 19.99 GadgetOneClick 24.99 Camera

Gizmo 19.99 Camera

Page 11: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

443

LosslessDecompositions

AdecompositionRto(R1,R2)islossless ifR=R1JoinR2

R(A1,...,An,B1,...,Bm,C1,...,Cp)

R1(A1,...,An,B1,...,Bm) R2(A1,...,An,C1,...,Cp)

Page 12: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

444

LosslessDecompositions

BCNFdecompositionisalwayslossless.Why?

Note:don’tneed{A1,...,An}à {C1,...,Cp}

If {A1,...,An}à {B1,...,Bm}Thenthedecompositionislossless

R(A1,...,An,B1,...,Bm,C1,...,Cp)

R1(A1,...,An,B1,...,Bm) R2(A1,...,An,C1,...,Cp)

Page 13: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

445

AproblemwithBCNF

Note:Thisishistoricallyinaccurate,butitmakesiteasiertoexplain

Problem:ToenforceaFD,mustreconstructoriginalrelation—oneachinsert!

Page 14: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

446

AProblemwithBCNF{Unit} à {Company}{Company,Product} à {Unit}

WedoaBCNFdecompositionona“bad”FD:{Unit}+ = {Unit, Company}

WelosetheFD{Company,Product} à {Unit}!!

Unit Company Product… … …

Unit Company… …

Unit Product… …

{Unit} à {Company}

Page 15: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

447

SoWhyisthataProblem?

Noproblemsofar.Alllocal FD’saresatisfied.

Unit CompanyGalaga99 NEUBingo NEU

Unit ProductGalaga99 DatabasesBingo Databases

Unit Company ProductGalaga99 NEU DatabasesBingo NEU Databases

Let’sputallthedatabackintoasingletableagain:

{Unit} à {Company}

ViolatestheFD{Company,Product} à {Unit}!!

{Unit} à {Company}{Company,Product} à {Unit}

Page 16: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

448

TheProblem

• WestartedwithatableRandFDsF

• WedecomposedRintoBCNFtablesR1,R2,…withtheirownFDsF1,F2,…

• Weinsertsometuplesintoeachoftherelations—whichsatisfytheirlocalFDsbutwhenreconstructitviolatessomeFDacrosstables!

PracticalProblem:ToenforceFD,mustreconstructR—oneachinsert!

Page 17: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

449

PossibleSolutions

• Variouswaystohandlesothatdecompositionsarealllossless/noFDslost- Forexample3NF: stopshortoffullBCNF decompositions.

• Usuallyatradeoffbetweenredundancy/dataanomaliesandFDpreservation…

BCNFstillmostcommon- withadditionalstepstokeeptrackoflostFDs…

Page 18: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

450

4NF and higher

Page 19: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

451

3NFMotivation

ArelationRisin3rdnormalformif:Wheneverthereisanontrivialdep.A1,A2,...,An® BforR,then{A1,A2,...,An }isasuper-keyforR,orBispartofakey.

Tradeoffs:BCNF:noanomalies,butmaylosesomeFDs3NF:keepsallFDs,butmayhavesomeanomalies

Page 20: DB - ER - 180312 · 434 Announcements! • Keep bringing your name plates J • Verify your grades and feedback on BB. If something is unclear or confusing, or displays incorrectly,

452

Motivationof4NFandhigher

Course Lecturer Book

cse444 Alexandra Completebook

cse444 Wolfgang Completebook

cse444 Alexandra Cowbook

Assumeforeachcourse,wecanindependentlychoosealecturerandabook.Whatistheproblem?

Multi-valueddependency(MVD)Course®® Lecturer:Ineverylegalinstance,eachCourse valueisassociatedwithasetofLecturer valuesandthissetisindependentofthevaluesintheotherattributes(hereBook).

Classes

cse444 Wolfgang Cowbook