Sunteți pe pagina 1din 8

CSE444MidtermExam

July28,2010

Name_______SampleSolution_________



Question1 /28

Question2 /20

Question3 /16

Question4 /20

Question5 /16

Total /100



Theexamisopentextbookandopenlecturenotes,includinganymarginalorothernotesyouhave
madeduringlecture.Pleaseputawayallothermaterialsincludingprojects,homework,oldexams,and
samplesolutions.Nocomputers,electronics,communications,orotherdevicesarepermitted.

Pleasewaittoturnthepageuntileveryonehastheirexamandyouaretoldtobegin.

CSE444Midterm,July28,2010SampleSolution Page1of8

Question1.SQL(28points,7eachpart)Wehaveasmalldatabasewiththreetablestokeeptrackof
mountainsandthepeoplewhoclimbthem.Thetablesandtheirattributesareasfollows:

Mountain(name,height,country,state)
Climber(cid,name,sex)
Ascent(cid,mountain,month,year)

Mountain:name(string)isassumedtobeuniqueforthisproblem;heightinfeet(integer);
countryandstate(orprovince,district,etc.)wherethemountainislocated(strings)
Climber:cid(uniqueinteger),name(string),sex(string,eitherMorF,andnevernull).
Differentclimbersmayhavethesamename,buttheywillhavedifferentcidnumbers.
Ascent:recordofasingleclimbbyasingleclimber.cidisaforeignkeyreferencingClimber,
mountainisaforeignkeyreferencinganameinMountain,monthandyearareintegers.We
assumethatnoclimberclimbsasinglemountainmorethanonceinagivenmonthandyear.

(a)WriteaSQLquerythatgivesthenamesofallclimberswhohaveclimbedthetallestmountain.You
mayassumethatthereisonlyonemountainthatistallerthanalloftheothers.Iftwoormoreclimbers
havethesamename,itisyourchoicewhetherthatnameappearsmorethanonce.

selectc.name
fromclimberc,ascenta,mountainm
wherec.cid=a.cidand
a.mountain=m.nameand
m.height>=all(selectheightfrommountain)

(b)WriteaSQLquerythatreturnsthepercentageofwomenamongtheclimbersthatascendedthe
mountainnamedRainierinJuly2007.Youmayassumethereareatleastonemanandonewomanin
thelistofclimbersthatascendedRainierduringthatmonth.

select100*women.nbr/total.nbr
from (selectcount(*)asnbr
fromascenta,climberc
wherea.cid=c.cidanda.mountain='Rainier'and
a.month=7anda.year=2007)
astotal,
(selectcount(*)asnbr
fromascenta,climberc
wherea.cid=c.cidanda.mountain='Rainier'and
a.month=7anda.year=2007andc.sex='F')
aswomen

(continuednextpage)

CSE444Midterm,July28,2010SampleSolution Page2of8
Question1.(cont)Schemasrepeatedforconvenience:

Mountain(name,height,country,state)
Climber(cid,name,sex)
Ascent(cid,mountain,month,year)

(c)WriteaSQLquerythatreturnsalistofeverymountaininthedatabaseandthenumberofdifferent
climberswhohaveascendedeachmountain,sortedindescendingorderbynumberofclimbers.
Climbersmayhaveclimbedthesamemountainmanytimes,buteachuniqueclimbershouldonlybe
countedonceinthetotalforeachmountain.Ifseveralmountainshavethesamenumberofclimbers,
thosemountainswiththesamenumbermaybelistedinanyorder.

selectcount(distincta.cid)asc_climbers
frommountainmleftouterjoinascenta
onm.name=a.mountain
groupbym.name
orderbyc_climbersdesc;

(d)WriteaSQLquerythatdeterminesthestateinthecountryUSAthathasthemostmountainsat
least12,000feethigh,andreturnsthenameofthatstateandalistofthosemountains,sortedby
mountainname.Youmayassumethereisonlyonestatewiththislargestnumberoftallmountains.
Youmayrepeatthenameofthestatealongwitheachmountainnameintheoutputifthatismore
convenient.

selectname,state
frommountain
wherecountry='USA'and
state=(
selectstate
frommountain
wherecountry='USA'andheight>=12000
groupbystate
havingcount(*)>=all(
selectcount(*)
frommountain
wherecountry='USA'andheight>=12000
groupbystate
)
)
andheight>=12000
orderbyname;

CSE444Midterm,July28,2010SampleSolution Page3of8
Question2.Conceptualdesign(20points)Wewouldliketodesignadatabasetokeeptrackofazoo.
(a)GiveanE/Rdiagramthatcapturesthefollowingentitiesandrelationships:

Thezooemployeesareknownaszookeepers.Eachzookeeperhasaname,auniqueemployee
IDnumber,andasalary.Heorshemayworkinanynumberofexhibits,ornoneatall
(administrativestaffdonotworkinexhibits,forexample).Azookeeperdoesnothavetowork
inanexhibittoheadit.
Thezoohasseveralexhibits.Eachonehasanexhibitnameandaheadzookeeperwhoisin
chargeofit.Azookeepermayheadmanyexhibits,buteachexhibithasatmostonehead.
Eachzookeeperhasatmostonemanager,whoisanotherzookeeper(somezookeepers,suchas
thedirectorofthezoo,havenomanager).Azookeepercanmanageanynumberofemployees,
includingnone.
Thezoohasmanyanimals.Eachhasaname,species,uniqueIDnumber,andaweeklybudget
foritscare.Eachanimalistendedbyatleastonezookeeper,andmayappearinatmostone
exhibit.Someanimals,suchasthosehousedintheveterinaryclinic,arenotinanyexhibit.

id name salary name

worksin

Zookeeper Exhibit

heads

manages

tends appearsin

Animal

id species name budget

(continuednextpage)

CSE444Midterm,July28,2010SampleSolution Page4of8
Question2(cont.)(b)GiveSQLCREATETABLEstatementsfortablesthatimplementyourE/Rdiagram
frompart(a).Youshouldgivetheattributenamesandtypesforeachtable,andclearlyindicatewhich
attributesarekeys,whichothersareunique,andwhichareforeignkeysreferencingothertables.

CREATETABLEZookeeper(
idINTEGERPRIMARYKEY,
nameVARCHAR(100),
salary_centsINTEGER,
manager_idINTEGERREFERENCESZookeeper(id)
);

CREATETABLEExhibit(
nameVARCHAR(100)PRIMARYKEY, PRIMARYKEYisoptionalhere
head_idINTEGERREFERENCESZookeeper(id)
);

CREATETABLEAnimal(
idINTEGERPRIMARYKEY,
speciesVARCHAR(100),
nameVARCHAR(100),
budget_centsINTEGER,
appears_inVARCHR(100)REFERENCESExhibit(name)
);

CREATETABLEWorksIn(
zkidINTEGERREFERENCESZookeeper(id),
exnameVARCHAR(100)REFERENCESExhibit(name),
PRIMARYKEY(zkid,exname)
);

CREATETABLETends(
zkidINTEGERREFERENCESZookeeper(id),
aidINTEGERREFERENCESAnimal(id),
PRIMARYKEY(zkid,aid)
);

Note:Ifwecoulddoitoveragain,itwouldhavebeenbettertojustaskforthetableschemasinstead
ofthefullCREATETABLESQLstatementsinordertocutdownontheamountofwritingneeded.

CSE444Midterm,July28,2010SampleSolution Page5of8
Question3.BCNF(16points)SupposewehavearelationalschemaR(A,B,C,D,E)withthefollowing
functionaldependencies:

A>E
C>D
A,B>C,D

Decomposethisrelation,ifneeded,intocollectionsofrelationsthatareinBCNF.Ateachstep,show
yourworkandexplainwhichdependencyviolation(s)youarecorrecting.Besurethestepsinthe
decompositionareclearandthatitisclearwhichtablesarethefinalones.Also,identifythekeysof
eachtablebyunderlyingtheattribute(s)thatmakeupthekey.

Hint:theremaybemorethanonecorrectsolutiontotheproblem.

Theclosuresofthevariousdependenciesare:

{AB}+={ABCDE}
A+={AE}
C+={CD}

Thefirstoneisnotaproblem,theothertwoviolateBCNF.

SolutionI.UseA>Etodecomposethetableinto

R1(A,E)
R2(A,B,C,D)

R1isinBCNF.R2hasabaddependencyC>D.Usethattodecomposeandweget

R21(C,D)
R22(A,B,C)

ThefinaltablesareR1,R21,andR22,whichareinBCNF.

SolutionII.IfweuseC>Dforthefirstdecompositionweget

R1(C,D)
R2(A,B,C,E)

R1isinBCNF,R2hasabaddependencyA>E.DecomposeR2toget

R21(A,E)
R22(A,B,C)

ThefinaltablesareR1,R21,andR22.

CSE444Midterm,July28,2010SampleSolution Page6of8
Question4.Serialization(20points).Foreachofthefollowingschedules,

i. Drawtheprecedencegraphfortheschedule.
ii. Ifthescheduleisconflictserializable,givetheequivalentserialschedule.Ifthescheduleis
notconflictserializable,explainwhynot.
iii. Ifthescheduleisnotconflictserializable,buttherestillisanequivalentserialschedule,give
thatscheduleandexplainwhyitisequivalent.

(a)r2(X)r1(X)r2(Z)w2(Z)w2(X)r1(Z)w1(X)

1 2

Thisisnotconflictserializablebecausethereisacycleintheprecedencegraph.Further,thereisno
equivalentserialschedule,sinceT1mustreadXbeforeT2writesit,butT2mustwriteZbeforeT1
readsit.

(b)r2(X)r3(Y)w3(X)r1(Y)w2(X)w1(Y)w1(X)

2 3

Thisisnotconflictserializablebecausethereisacycleinthegraph.

However,thescheduler2(X)w2(X)r3(Y)w3(X)r1(Y)w1(Y)w1(X)isserialandisviewequivalentto
theoriginalschedule.ThewritestoXbyT2andT3aresupersededbyw1(X)attheendofthe
schedulebeforeanyothertransactionsreadX.

CSE444Midterm,July28,2010SampleSolution Page7of8
Question5.(16points)Assortedshortquestions.

(a)Inasystemwithasimpleundolog,whenatransactionwantstocommititmustfirstwaituntilallof
itsdatapageshavebeenwrittentodisk. Trueorfalse?___true______

(b)Inasystemwithasimpleredolog,changestothetransactionsdatapagescanbewrittenbeforeor
aftertheyarewrittentothelog. Trueorfalse?___false______
(Inaredolog,outputsmustbedoneaftertheyarelogged)

(c)inasystemwithasimpleredologusingnonquiescentcheckpointing,an<ENDCKPT>recordinthe
logindicatesthatalltransactionsidentifiedinthecorresponding<STARTCKPT>recordhaveeither
committedoraborted. Trueorfalse?___false______
(ENDCKPTonlyindicatesthatalldirtypagesbelongingtotransactionsthatcommittedbeforethe
<STARTCKPT>arenowondisk)

(d)IntheARIESrecoveryprotocol,afteracrash,theanalysispassexaminestheloganddeterminestwo
things.Oneisthelistofactivetransactionsthatdidnotfinishatthetimeofthecrashandwillneedto
beundone.TheotherisanumberknownasFirstLSNthatidentifiesanentry(LSN)inthelog.Whatis
thesignificanceofthisnumber?

Thisidentifiestheearliestentryinthelogthatmustbeexaminedontheredopass.(i.e.,thefirstlog
entrywhosechangestothedatabasemighthavebeenlostinthecrash)

(e)IntheARIESrecoveryprotocol,ifacrashoccursduringtheundophaseoftherecovery,thenaftera
restart,alloftheundooperationsfrombeforethecrashwillberepeatedbecausetheyareidempotent.
Trueorfalse?___false_______
(EachARIESundooperationisloggedwithaCLR.TheCLRwillberedoneifthereisacrashbeforethe
undophasefinishes;noundooperationhappensmorethanonce.)

(f)InasystemusingtheARIESrecoveryprotocol,changesmadetotransactiondatapagesmaybe
writtentodiskbeforeorafterthetransactionscommitrecordiswrittentothelog.
Trueorfalse?___true_______

(g)Inaschedulerthatusestimestampsforconcurrencycontrol,eachdatabaseelementXhasaread
timestampRT(X).WheneveratransactionreadsadatabaseelementX,theelementsRT(X)timestamp
isupdatedbyrecordingthetransactionstimestampinRT(X)forthatdatabaseelement.
Trueorfalse?___false_______
(RT(X)=max(oldRT(X)value,timestamponcurrenttransaction))

(h)Inaschedulerthatusesvalidationforconcurrencycontrol,thecommittedtransactionshavethe
sameeffectastheywouldinaserialschedulewherethetransactionsareexecutedintheorderinwhich
theystarted(i.e.,transactionstarttimesdeterminetheserializationorder).
Trueorfalse?___false_______
(Serializationorder=transactionvalidationorder)

CSE444Midterm,July28,2010SampleSolution Page8of8

S-ar putea să vă placă și