Sheet 3 Model Answer
Sheet 3 Model Answer
1. Consider the SQL !er"# SELECT $.%name& $.Lname& S.%name& S.Lname FROM $MPL'($$ AS $& $MPL'($$ AS S WHERE
$.S!)er*ssn + S.Ssn
in ,hich& -or each em).o"ee (-rom the com)an" schema given in "o!r te/tboo0)& retrieves the em).o"ee1s -irst and .ast name and the -irst and .ast name o- his or her immediate s!)ervisor. Ass!ming that the $MPL'($$ re.ation is# $MPL'($$ (%name#string& Lname#string& Ssn#string& 2date#date& Address#string& Se/#char& Sa.ar"#rea.& S!)er*ssn#string& Dno#integer) and the si3e o- each -ie.d is as -o..o,s# %name 20 b"tes Lname 20 b"tes Ssn 10 b"tes 2date 4 b"tes Address 50 b"tes Se/ 1 b"te
Sa.ar" 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 re)resent 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 o)timi3ed b" the a.gorithm o!t.ined in Cha)ter 1;. (c) Com)are (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
Solu)ion!
S)ric)ness is a s)ron,er 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 0ollo s! S1 T1 r"#$ r"%$ "#$ r"#$ c1 "%$ r"&$ "#$ "&$ r"&$ c2 "&$ c3 r"#$ "%$ "#$ c2 c1 "&$ "#$ c3 "#$ r"#$ T2 T3 S2 T1 r"#$ r"%$ r"&$ T2 T3
Schedule S1 is recoverable. Since there is no such a situation that one transaction reads a value written by another, but commits before that one. Its recoverable. Since r(Y) in T3 is de endent 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. Schedule S! therefore is casacdeless, and is therefore also recoverable. S! is also strict, because no ob%ect is read or written, that has been u dated by a transaction that has not committed or aborted yet.
1n shor
Schedule S1 S2
Cascadeless 2o &es
S)ric) 2o &es
"b$ (e)er*ine he)her or no) each schedule S3 and S4 is con0lic) seriali3able. 4lso 0or each seriali3able schedule, de)er*ine )he e-ui+alen) serial schedule. The schedules S3 is as 0ollo !
S3 T1 r"#$ r"%$ "#$ r"#$ "%$ r"&$ "#$ "&$ r"&$ "&$ T2 T3
T3
allo s )he e5ecu)ion o0 )he schedules, and discuss cascadin, rollbac6 "i0 an/$. Hin)s! each o.era)ion )a6es one )i*e uni), and )i*es)a*. o0 each )ransac)ion is )he )i*e associa)ed )o i)s 0irs) o.era)ion. For e5a*.le, )i*es)a*.s o0 )ransac)ions T1, T2, and T3 in schedule S4 are 1, 2, and 7 "res.ec)i+el/$.
S3 T1 r"#$ r"%$ "#$ r"#$ "%$ r"&$ "#$ "&$ r"&$ "&$ T2 T3
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) (+
ordering a.gorithm.
S4 T1 r"#$ r"%$ r"&$ "#$ r"#$ "&$ "#$ r"#$"abor)$ "%$ "#$
10
T2
T3
Set '×tam ($) (1 Set '×tam ()) (! Set '×tam (Y) (! Set *×tam ($) (1 Set '×tam ($) (, Set *×tam (Y) (! Set *×tam ($) (, Set '×tam ($) (! (cascadin- rollbac.)
Since r(X) in T2 reads X written by T3, T3 is abort. And there is a chain rollback.
11
12