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

Post on 19-Mar-2020

2 views 0 download

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

433

L15:Normalization

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

434

Announcements!

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

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

• Outlinetoday- HW4,Projects- Decompositions- Transactions!

435

436

Ryan'squestion:ParkingTickets:ERDiagram

STID LName FName PhoneNo StLic LicNo

Code Fine

Ticketnr Date Code@ STID@

Student

TicketCode

Ticket

Violation

437

Ryan'squestion:ParkingTickets:ERDiagram

438

Decompositions

439

Recap:Decomposetoremoveredundancies

• Wesawthatredundanciesinthedata(“badFDs”)canleadtodataanomalies

• Wedevelopedmechanismstodetectandremoveredundanciesbydecomposingtablesinto3NF orBCNF- BCNF decompositionisstandardpractice- verypowerful&widelyused!

• However,sometimesdecompositionscanleadtomoresubtleunwantedeffects…

Whendoesthishappen?

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

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”

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

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)

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)

445

AproblemwithBCNF

Note:Thisishistoricallyinaccurate,butitmakesiteasiertoexplain

Problem:ToenforceaFD,mustreconstructoriginalrelation—oneachinsert!

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}

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}

448

TheProblem

• WestartedwithatableRandFDsF

• WedecomposedRintoBCNFtablesR1,R2,…withtheirownFDsF1,F2,…

• Weinsertsometuplesintoeachoftherelations—whichsatisfytheirlocalFDsbutwhenreconstructitviolatessomeFDacrosstables!

PracticalProblem:ToenforceFD,mustreconstructR—oneachinsert!

449

PossibleSolutions

• Variouswaystohandlesothatdecompositionsarealllossless/noFDslost- Forexample3NF: stopshortoffullBCNF decompositions.

• Usuallyatradeoffbetweenredundancy/dataanomaliesandFDpreservation…

BCNFstillmostcommon- withadditionalstepstokeeptrackoflostFDs…

450

4NF and higher

451

3NFMotivation

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

Tradeoffs:BCNF:noanomalies,butmaylosesomeFDs3NF:keepsallFDs,butmayhavesomeanomalies

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