Upload
fazal-mahar
View
217
Download
0
Embed Size (px)
Citation preview
8/13/2019 Sheet 3 Model Answer (1)
1/12
Assignment 2Advanced Database Management (CP3020)
1. Consider the SQL !er"#
SELECT$.%name& $.Lname& S.%name& S.Lname
FROM $MPL'$$ AS $& $MPL'$$ AS S
WHERE
$.S!er*ssn + S.Ssnin ,hich& -or each emo"ee (-rom the coman" schema given in
"o!r te/tboo)& retrieves the emo"ees -irst and ast name and
the -irst and ast name o- his or her immediate s!ervisor.
Ass!ming that the $MPL'$$ reation is#
$MPL'$$ (%name#string& Lname#string& Ssn#string&
date#date& Address#string& Se/#char& Saar"#rea&
S!er*ssn#string& Dno#integer) and the sie o- each -ied is as
-oo,s#
%name 20 b"tes
Lname 20 b"tes
Ssn 10 b"tes
date 4 b"tes
Address 50 b"tes
Se/ 1 b"te
1
8/13/2019 Sheet 3 Model Answer (1)
2/12
Saar" 5 b"tes
S!er*ssn 10 b"tes
Dno 1 b"te
6hat is& records are -i/ed and each record contains 115 b"tes.
(a)Dra, t,o !er" trees that can reresent this !er". 7nder ,hat
circ!mstances ,o!d "o! !se each o- "o!r !er" trees8
(b)Dra, the initia (canonica) !er" tree -or this !er"& and then
sho, (ste b" ste& ,ith some 9!sti-ications:e/anations) ho,
the !er" tree is otimied b" the agorithm o!tined in Chater
1;.
(c) Comare (in terms o- the n!mber o- b"tes that m!st be
trans-ered) "o!r o,n !er" trees o- art (a) and the initia and -ina
!er" trees o- art (b).
2. Consider schedules S1, S2, S3, and S4 belo.
S1 ! r1"#$, r2"%$,1"#$, r3"#$, c1,2"%$, r2"& $,3"#$,2"& $, r3"& $, c2,3"& $, c3'
S2 ! r1"#$, r2"%$, r2"& $,1"#$, r3"#$, c1,2"& $,3"#$, c3, r2"#$,2"%$,2"#$, c2'
S3 ! r1"#$, r2"%$,1"#$, r3"#$,2"%$, r2"& $,3"#$,2"& $, r3"& $,3"& $'
S4 ! r1"#$, r2"%$, r2"& $,1"#$, r3"#$,2"& $,3"#$, r2"#$,2"%$,2"#$'
"a$ (e)er*ine he)her each schedule S1 and S2 is s)ric), cascadeless, reco+erable,
or nonreco+erable.
2
8/13/2019 Sheet 3 Model Answer (1)
3/12
Solu)ion!
S)ric)ness is a s)roner re-uire*en) )han cascadeless, because
addi)ional li*i)a)ions on )he ri)in beha+ior are i*osed. S)ric)ness
i*lies cascadeless. Casacdeless i*lies reco+erabili)/.
The schedules o0 S1 and S2 are as 0ollos!
3
S1 S2
T1 T2 T3 T1 T2 T3
r"#$ r"#$
r"%$ r"%$
"#$ r"&$
r"#$ "#$
c1 r"#$
"%$ c1
r"&$ "&$
"#$ "#$
"&$ c3
r"&$ r"#$
c2 "%$
"&$ "#$
c3 c2
8/13/2019 Sheet 3 Model Answer (1)
4/12
Schedule S1 is recoverable.
Since there is no such a situation that one transaction reads a valuewritten by another, but commits before that one. Its recoverable.Since r(Y) in T3 is deendent on w(Y) in T! and before it committed.Its not cascadeless. Thus its not strict.
Schedule S! is strict"#nly T! reads a value (r($)) written by one of the other transactions(w($)), namely T3. This value has already been committed. ScheduleS! therefore is casacdeless, and is therefore also recoverable. S! is
also strict, because no ob%ect is read or written, that has beenudated by a transaction that has not committed or aborted yet.n shor
Schedule Reco+erable Cascadeless S)ric)
S1 &es o o
S2 &es &es &es
"b$ (e)er*ine he)her or no) each schedule S3 and S4 is con0lic) serialiable. lso
0or each serialiable schedule, de)er*ine )he e-ui+alen) serial schedule.
The schedules S3 is as 0ollo!
4
8/13/2019 Sheet 3 Model Answer (1)
5/12
5
S3
T1 T2 T3
r"#$
r"%$
"#$
r"#$
"%$
r"&$
"#$
"&$
r"&$
"&$
8/13/2019 Sheet 3 Model Answer (1)
6/12
S3 is con0lic) serialiable.
T1 T2 E-ui+alen) serial schedules
T3
The schedules S4 is as 0ollo!
6
S4
T1 T2 T3
r"#$
r"%$
r"&$
"#$
r"#$
"&$
"#$
r"#$
"%$
"#$
T1&&&&T3T!&&&&T3
8/13/2019 Sheet 3 Model Answer (1)
7/12
S3 is con0lic) serialiable.
T1 T2 E-ui+alen) serial schedules
T3
"c$ l/ )he basic )i*es)a* orderin alori)h* )o
7
T1&&&&T3&&&T!T1&&&&T!
8/13/2019 Sheet 3 Model Answer (1)
8/12
schedules S3 and S4. (e)er*ine he)her or no) )he alori)h*
allos )he e5ecu)ion o0 )he schedules, and discuss cascadin
rollbac6 "i0 an/$.
Hin)s! each oera)ion )a6es one )i*e uni), and )i*es)a* o0
each )ransac)ion is )he
)i*e associa)ed )o i)s 0irs) oera)ion. For e5a*le,
)i*es)a*s o0 )ransac)ions T1, T2,
and T3 in schedule S4 are 1, 2, and 7 "resec)i+el/$.
S3! Ti*es)a*s T181, T282, T384.
8
8/13/2019 Sheet 3 Model Answer (1)
9/12
9
S3
T1 T2 T3
r"#$
r"%$
"#$
r"#$
"%$
r"&$
"#$
"&$
r"&$
"&$
Set '×tam($) 1
Set '×tam () !
Set *×tam ($) 1
Set '×tam ($) +
Set *×tam () !
Set '×tam (Y) !
Set *×tam ($) +
Set *×tam (Y) !
Set '×tam (Y) +
Set *×tam (Y) +
8/13/2019 Sheet 3 Model Answer (1)
10/12
A transactions are e/ec!ted s!ccess-!" b" the timestam
ordering agorithm.
S3! Ti*es)a*s T181, T282, T387.
10
S4
T1 T2 T3
r"#$
r"%$
r"&$
"#$
r"#$
"&$
"#$
r"#$"abor)$
"%$
"#$
Set '×tam($) 1
Set '×tam () !
Set '×tam (Y) !
Set *×tam ($) 1
Set '×tam ($)
Set *×tam (Y) !
Set *×tam ($)
Set '×tam ($) !(cascadin- rollbac)
8/13/2019 Sheet 3 Model Answer (1)
11/12
Since r(X) in T2 reads X written by T3, T3 is abort.
And there is a chain rollback.
11
8/13/2019 Sheet 3 Model Answer (1)
12/12
12