0% found this document useful (0 votes)
60 views12 pages

Sheet 3 Model Answer

This document contains two assignments related to database management. The first assignment asks students to draw tree representations of a database schema and analyze how the trees are optimized. The second assignment asks students to analyze transaction schedules to determine serializability and equivalence. It also applies a timestamp ordering algorithm to determine if the schedules can be executed.

Uploaded by

Fazal Mahar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views12 pages

Sheet 3 Model Answer

This document contains two assignments related to database management. The first assignment asks students to draw tree representations of a database schema and analyze how the trees are optimized. The second assignment asks students to analyze transaction schedules to determine serializability and equivalence. It also applies a timestamp ordering algorithm to determine if the schedules can be executed.

Uploaded by

Fazal Mahar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 12

Assignment 2

Advanced 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.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

Reco+erable &es &es

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

S3 is con0lic) seriali3able. T1 T2 E-ui+alen) serial schedules


T1&&&& T3 T!&&&& T3

T3 The schedules S4 is as 0ollo !


S4 T1 r"#$ r"%$ r"&$ "#$ r"#$ "&$ "#$ r"#$ "%$ "#$ T2 T3

S3 is con0lic) seriali3able. T1 T2 E-ui+alen) serial schedules


T1&&&& T3&&& T! T1&&&& T!

T3

"c$ 4..l/ )he basic )i*es)a*. orderin, al,ori)h* )o


7

schedules S3 and S4. (e)er*ine

he)her or no) )he al,ori)h*

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! Ti*es)a*.s T181, T282, T384.

S3 T1 r"#$ r"%$ "#$ r"#$ "%$ r"&$ "#$ "&$ r"&$ "&$ T2 T3
Set '&timestam ($) (1 Set '&timestam ()) (! Set *&timestam ($) (1 Set '&timestam ($) (+ Set *&timestam ()) (! Set '&timestam (Y) (! Set *&timestam ($) (+ Set *&timestam (Y) (! Set '&timestam (Y) (+ Set *&timestam (Y) (+

A.. transactions are e/ec!ted s!ccess-!.." b" the timestam)

ordering a.gorithm.

S3! Ti*es)a*.s T181, T282, T387.

S4 T1 r"#$ r"%$ r"&$ "#$ r"#$ "&$ "#$ r"#$"abor)$ "%$ "#$
10

T2

T3

Set '&timestam ($) (1 Set '&timestam ()) (! Set '&timestam (Y) (! Set *&timestam ($) (1 Set '&timestam ($) (, Set *&timestam (Y) (! Set *&timestam ($) (, Set '&timestam ($) (! (cascadin- rollbac.)

Since r(X) in T2 reads X written by T3, T3 is abort. And there is a chain rollback.

11

12

You might also like