صفحه 1:
صفحه 2:
Traswirw :098 مان
wo
ان مس
متس
مه موی
طسب
QRevovercbtiyy
0 ا
ماه( متسه kt GOL
‘Deore Por Gertckzabliy.
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08.
صفحه 3:
پوس ی و
© 0 rewwton & 9 vail prog execuivg hot uccesses od possibly
updates various data tec.
© 0 لول موه و و ام
© Ort مس exevuiiog he dotcbuse wey be tewporady tacveststiect.
مح لیب وا سپس اوه بو بج مسجو لجل سنا
bene,
۲ Pero rensuivs cows, the chooges it has wade iy he dotabuse persist,
euro there ore spstew .وس اننا
۱ طسو و و وی اون لو(
© Pw wa eves ty deol with
۶ اه یلو vatour bods, suck os horde Polures ond syoteu
اه
© Cowered exevutiod oP ول tronartiods
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. wo ©Sbervehnts, Cork ced Cnakershe
صفحه 4:
2010 Properties
وی ond possibly updates یه اب ماج مس و لس د دا وماصحصز 09
of dota the database sysiew oust rou! فيج جا رم وه مد
© @wrty. Ciker dl ppercicgs of the trowsuctiva ore propery reAeried ia the
database و وه مه
۲ ماه و قح مین fa مت preserves the coca of
بو _
Beckton. Dlhougs cults tracsurtiois way exevute coorurrediy, euck مه
واه ۴اه نوی سا عم coazunreuly executes لصا شم
trocsuntica results o7ust be kiddeo Proow ober ocacurredly executed trocrarivc.
© بط ts, Por every par oP مس Ton 7, toppeas io Phot ether T,
Priched executod bere “P started, or “T) started exertion Pier “?) Praisked.
۲ اون و و ۳( ی( survesshuly, the choayes it has wade to
the database persist, eved P there ore systew Pobures.
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. we ©Sbervehnts, Cork ced Cnakershe
صفحه 5:
+ (Backopls OP and Tractor
rexePer $60 Proc wernt Dy aorant @: ام الا
vee) .0
0-0 :0 ,6
wrte() .9
(0 )سر .6
۵+۵۵ :0 ,9
(© )سم .©
,6 وه ما لمی 6 هط مسا بط مور روموت 19
ore opt rePered tothe daubase, ebro لین با فا مه لاه مره بل
0
© Onwstewy requrewed — he sav of @ ocd © is varhooged by شحو
OP the troceruntion.
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. wo ©Sbervehnts, Cork ced Cnakershe
صفحه 6:
+ Oxo oP Pund TraePer (Ova)
Beckton requrewed — Fbetwera eps O ond O, caker raat i
sho epee hee pach پم Heder idk ene on مسجم عجوم her
(he sco + Pail be bros trom t shoal be).
© ecktioc mac be peured irundy by nenicny inneucioas serklly, teat is oe
Hee ert
© Ahowever, exeruien, wulipie تنیز سا راو موه
] biter.
۲ سا مج نم ات ما ماج و مور رای
وین (ie., he rceber of te SOO hor theo pice), fhe updos to the
ای by the traxmurtioa cant pero سج واي موس
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. wo ©Sbervehnts, Cork ced Cnakershe
صفحه 7:
Traswird Onde
ove — the Rad ste) fee وممصم stave fa ier ste whe fer exert
arty courted - «Pier ihe Phd stata har bee exerted.
Oded — Per he devovery ha word exer ica mn oo baer proceed.
bored — Pier he weneurtins hos bert red back oud he dace rested
اماد جا جا prior 7 he stort oP ike trceuton. Tuan optocs Per i har bee
تم
و اما لیوا مه ۳ cou be dow ool راما ما مس ©
صمحم (hil the
Bl Opwtted — Per sucess mxopleton.
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. wor ©Sbervehnts, Cork ced Cnakershe
صفحه 8:
Treenivd Orie (Ovc.)
Pe
“ye
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. ~ i
صفحه 9:
+ ‘koplewweciaiod oP Biowiiy wad Ourablliy
a ۲ لول وه موه syetew اوه
the support Por لجی روت durcbiliy.
ل لا
و و سره سا مت و رای نما مج ۶
۰
موه مه اه سا خر ور odled db_potcier ور ور
سیب بر
© dhe oe wae oo a shack copy oF he dacbose, ord
لاه ای سا ما مور و عمج اسر بل copy ody Pier her
سس
ایا با och,
ارو copy potted ty by موه همم بت
pent be sed, ood the shabu copy oor be dotted.
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. wo ©Sbervehnts, Cork ced Cnakershe
صفحه 10:
+ Choplercition oP Brwty wed Durdbity (Ova.)
‘db-pointer
سس
old copy of
database
(to be deleted)
new copy of
database
Dke shadou-dotobase schewe:
db-pointer
53
old copy of
database
© Qssanves disks do wt Pal
B OsePu Por tent echiors, but
© exrewel ke Pitot Por haw chtcbares (uty?)
مس
© Oves wi kane cared
۲ Oil study beter schewes ta Chopter 17.
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08.
صفحه 11:
+ Oowured Creviow
Bl Dukpe rocsunioce ore dlewed i rus poscurreaiy fa he syetew.
م0 ore:
© erewed provessor oad deh uiizaia, leudoy to better trocsurtion
troup oe ieeurion rat be usiog the CPO utile rather ie ready
Pro or write ty the choke
© rekord were resp koe Por irexewizes: shen rerio ceed
wot ura behind br oer.
© Opwwrewy cours! svhewes — wechodisws tp achieve tsvhiiod; thot ts, 17
او ها و و سس موه سا روت موه با ایو
thew Prow desiroying the صلاخان ری
© Olean is Chapter (0, Per stain seta of porreviiess oF
شوه سور
سا0 لح 0 لا سواه 1 موه ۱
صفحه 12:
ی +
۲ امن با رتاو ناوخا سم و - سل order ict
hick اجه جوا موی تن وا
© ached Por o set of اس ust oposite of oll etruniizes oP those
سس
© wet preserve the order in which the اف ای و و
مسر
BO trenton hd success Ruy cowpbtes tis اوه سم رت مج
جما جد جملا اص ket stalewedt (wll be occted a te obvi)
BO tnrewoioa ot Paks ty surcessPMy omopket ts exert wll have or bert
جما جب جات اص ket stalewedt (wll be occited Ft te obvi)
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. 10.00 ©Sbervehnts, Cork ced Cnakershe
صفحه 13:
+ Ookerhis 1
B Let Ty ام 160 Prow Pio B, امه Ty trcePer (D% of he
beknee Prine 9 0
B® veri ات ia which T, ts Polowed by To:
read(A)
AzA—50
write (A)
read(B)
B:=B+50
write(B)
read(A)
temp := A *0.1
A:=A- temp
write(A)
read(B)
B:=B+temp
write(B) Ez
Oeadrwr Gyetrer Ovcwptr- O* Brame, Gey ©, 2008.
صفحه 14:
© ط یی +
+ sernd schekie where Ti Polowed برط 10
read(A)
temp :=A*0.1
A:=A-— temp
write(A)
read(B)
B:=B+ temp
write(B)
read(A)
A:=A-50
write(A)
read(B)
B:=B+50
write(B.
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. 16.00
صفحه 15:
+ یی O
19 Let Ty ocd 7, be be inxeantions dePed previa. Phe Policy
sohede toot a serid sokedle, but itis eguivaialte Ockedve ۰
read(A)
A=A-50
write(A)
read(A)
temp :- ل * 1
A
A- temp
write(A)
read(B)
B:=B+50
write(B)
read(B)
B:=B+temp
write(B)
410 Gokeddes (, O und 8, he une + @ preserved. Ez
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. 10.00 ©Sbervehnts, Cork ced Cnakershe
صفحه 16:
@ یی +
18 Dh Polowiey ooourred schedde does ot preserve the vue خام ))©
+O).
read(A)
temp :=A*0.1
A:=A — temp
write(A)
read(B)
write (A)
read(B)
B:=B+50
write (B)
B:=B+ temp
write(B) ka
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. 16.00 ©Sbervehnts, Cork ced Cnakershe
صفحه 17:
Gorichabity
© یدوجو موه rie
“Dhue gerd executog of a get of ره سل مرو موم
او و ها افو بت ها ره مه (poeebly ۲
يخم مجهي جما صر صم سق سترفوت مایت تن sukecle. OP Perea Poros
ون ی ٩
© Oe kewre اجه ,و نمب كحت لمج حكا عجكات ممصت we osu
thot وه تمه موم رو وس oo dota لیا و buPPers ke
ای دوه لاه )ات له و ما oP ody read ord
ری ات رن
۱ 10.0? ©Sbervehnts, Cork ced Cnakershe
صفحه 18:
هس سره | بو زو( و
را له سای هل 7 مس [oP ام | ما ۳
these و اه لو | لو سا روا له 0 ما مه سوه سا
0
vead(Q), | =read(@). اد ام
rew(Q), |= urte(Q). Phey coh.
wrte(Q), | =rea(Q). اه بو
wrte(Q), | = wrte(Q). ممت و۳
18 لحب | موا سناجت د ,باعش [Porces « (locied) tewopord order beter
tow.
4B fod fore coweenuive اه و و ond they do oot رت rede
key hud bevu rizrckuuued inhe scbedvie. من سوت بط من لت
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. 16.00 ©Sbervehnts, Cork ced Cnakershe
صفحه 19:
راب6 بزیین +
۲ اه G voc be trensPorwed toto 0 scheduie 6۵ by a sertes oP swaps
مومس خر Retrunions, we say thot G ont Gore ooh equided.
© We sw that a schedule Gis vodPlet sertatzable Pitts ی equivdedt 7 seridl
shed
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. 16.00 ©Sbervehnts, Cork ced Cnakershe
صفحه 20:
+ OvdMtt Osridtrbity (Ova)
Bl Ocherki 0 van be inxePorned tay Oohedde O, 9 sertd sohechle
where 1, Polaws Py, by eres oP swape oF ueoosP ry
032000
© DherePory Ooheckle © ts out sertakzable.
read(A)
write(A)
write(A)
read(B)
write(B)
read(B)
write(B)
Gckedue D
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08.
صفحه 21:
+ OvdMtt Osridtrbity (Ova)
اه fri oot cob او و و ۴
14
write(Q)
Be ae unbe sup ketrtoas ta he chove sched to obtaia ther the seid
ocherhie <T,, Tig >, o the gertd جامد < Ty, TD >.
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. 16.00 ©Sbervehnts, Cork ced Cnakershe
صفحه 22:
رسب سل +
Bl Let Gord 6’ be tu aches wih he save واه بو Gord GO”
ae Vew equivdedt Phe مت سبط مر( ore wet
(. Por pack dota tw Q, P iroceurton 7, reads the rtd ude of Gis
مس ما ,۵ طساو 1 met, tr sched © قحم سا ام و
سس of Q.
©. Por cock data tow GP rxearton 7) executes read(Q) it ochechie G,
cen hot vk wor prockerd by inneurion 7) (Poy), hea inxeurtion
4 اس roche (G سای سا ام of G trot war produced by
ی
9. Por اس chia tew Q, the trout (Pony) that اس وت
جا موه( رن sched G cust perPorer the Pred wrte(@)
اه ما من &
Os coo be sero, view equivdeare is dev based purely oo reads ات اج
dow.
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. سا0 لح 0 لا سواه 1 موی
صفحه 23:
+ و (Ovw.)
© O sthedle Gis vew vertdbrabl itis view equivdedt ty 0 serial schedule.
۱ ری رای الا تور ts uv view sericizabe.
© یاه بای بت ها طورش ع امان طللاه وج تلد(
qe
write(Q)
write(Q)
a write(Q)
© vey view seridizable schedule thot is ot cooPict seriakzoble has bled writes.
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. 20 ©Sbervehnts, Cork ced Cnakershe
صفحه 24:
+ Ober Ovtow oP Oeridtzdbity
Bl Dhe ochedde below prodces suwe pure ar the serid schedle <
Dy Po, >, ves coh oobi و مرهج تسه مهوت
read(A)
A:=A-50
write(A)
read(B)
B:=B-10
write(B)
read(B)
B:=B+50
write(B)
read(A)
A:=A+10
write(A)
B Ort oraiey suck equideure requires univets oP pperdicas اه
read ord rite.
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. سا0 لح 0 لا سواه 1 ممه
صفحه 25:
+ Testy Por Ovrickrbily
© Oousider sowe schedule of a set oP اس 1 7,
Pores با
Bl Prevebwe graph و drent wok where he vertoes ore the
wearer (sxe).
B We draw wor Pow Tp 7B ke اجه رات مس مس 7,
تخس fhe da few va heb the ou لماعب ميمت
۴ We coay kabel he ory by the te thot woes orvessed.
0
<a
5 SS)
v
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. سا0 لح 0 لا سواه 1 موص
صفحه 26:
+ @xavple Ootedue (Gvbedue ®) + Prevedewe Brak
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. سا0 لح 0 لا سواه 1 وهم
صفحه 27:
0
.تاسوه حا عامسو prevedeure
11 ف لسن حجان جأسجانن اعقب جص اجا باس سا0
koe, where ois he oneber of vertices ia he
soph.
© (eter cherie take order 0+ e where oi
the nncber of eckes.)
BOP precede wroph te cts, the sertokzcbliy
order oa be جما خاب متحت اسح اجوز و بالات
اي
مس ما و و wih he porta
order of the raph.
© Por طسو و ی order Por
Goheddle B wokd be
Ratatat
۱ @re tere vers?
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. جوصه
صفحه 28:
مطاح دهن 5) ببد2) عروذا زوع
ص تصحف 1 b بقام احا جد نمست عوذا دجا عوسي صاصم 21157 1
یاه تن سوا
]۱ Por view sertakrobliy hes oot expooruitd ia the size oP the
prevedeuce yruph.
BL Dhe problew of chevhiog Po sokedle view seridkable Pols to the ches of
OP-axmpet: probes.
ای سوه ها منوا مه مد خا مه عط ©
رش ۲ لین موی وروی اه اس ما واه امش و 18
sertakzdbliy coc sill be weed.
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. سا0 لح 0 لا سواه 1 وهم
صفحه 29:
QRevovervbls Ookeduss
ره مه یط مج اه ای با سای وا لو(
تس مت
۳
هجو مه مهم 1 ماه
11 خأ مس
و عم بسح (10 )اه پا ۱ ۲
senha cae bert
To
read(A)
write(A)
read(A)
read(B)
BP Ty shod obo, 7, would we edd (ued possibly shows ty the veer) oo
inoousistedt dutcbosr state. Weare, dotcbosr wut eusure thot schedules ore
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. سا0 لح 0 لا سواه 1 موه
صفحه 30:
+ Owen Rolohs
Bl Ocenudos rolbuck — a sine haxeuriva Baki buds to seven of
fexeurion rolbacks. Onvekder fe Polpuien schedde where ace of he
resect bee pet و میور بط ایا ی اس
read(A)
read(B)
write(A)
read(A)
write(A)
B Oca مه وتو و اه موی سا نا لا oP words
سا0 لح 0 لا سواه 1 همه ۱
صفحه 31:
Ovscadeless Ovlhedules
Bl Ocevadeles sheddes — cucu rolbucks came pozur; Por euch pur of
مسر Tod Puck tet Prensa cata few previnwly writen by Tbe
maxima operates oP P oppeurs before ber read operive of P.
۴ Cie ewnleben sched & dou ترا رم
۳ تا ما تا w resin he ی مر سم با ورن ewrnbboe
۱ 16.00 ©Sbervehnts, Cork ced Cnakershe
صفحه 32:
Cowurrewwy اهبوهن)
و دوه وم و ما عمجت نب ام و database wet provide 0 ©
اه تاه رت و ی ی ۴
عولط موی لام لو مرس و ۶
او yeueriies دوجو و موس امن مایت و و ۵ ها
مه ۴اه صرح عجوم د دسلتصصم الجا روعت ل صداوه
© Ore seri schedles revovercblelrosradeless?
۲ Desay a schedule Por و تلو it hos executed ts o hie tov kt!
© od - بت tevebp cowerewy ood protools thet wil assure ,اوه
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. 00 ©Sbervehnts, Cork ced Cnakershe
صفحه 33:
+ راوس و ریق eer
ما یحو نها امه لوج ممجممه وله مر او تروص ول ۲
ued are recoverable oad vases. اوه تیالو و امد
raph طلسم ها عم بت ول اي وم امه جوز
we tis been created
© Vestecd 0 protocol koposes 0 derighor thot avoids omeercizable svhethies.
© We shady suck protons to Chupter 10.
© OPPercot ام روصم protools provide dPPered iradevPPs betwerd the
nt oP له سطاه وروی ۷ nn oP overkead thot they tamu.
Vests Por sertatzabtiy help ue voderstond why ج اسصو اوه تمحصجوه و
ات
۱
صفحه 34:
+ Oak eee tt ون
© Gowe uppicuives ore wiles to hve wih weds levels oP شاه ,موی
schedules thot are ant sertatzable
© Gx). بوحصم م romsoriva thot wets fo get oo opprontcrate total bokrare oP
أن corns
© Cy, chtcbwse stutoins copied Por query opikoizaioa oe be upproiocte
(ary?)
مهو اس ved ont be sertdkzuble wik respent ip سوه مان
ل ا Por perPorwone
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. woe ©Sbervehnts, Cork ced Cnakershe
صفحه 35:
00 ۰ رین و مرا +
ميك — Bl Gericke
اه وم او ام records io be و را Repeokbl: read ۲
0
ام bat ot ماه رو او لاجو جور و لت رو ۱ باصا مم
ات
recs مود بط ام can be و لو را لس 0
(but cowed) vokes. سل ما رو لو خر
ام ع9 رو ور امس Red woowwited — even ©
مرو رو خی موی اه و Bo bower
about the database ماو
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. سا0 لح 0 لا سواه 1 66م
صفحه 36:
اوقت مج +
خم اه سا ره 3 اس ه ust fochide مها مومت میا ۲
ircesariioc. و موی ۳ موم
ان ما شوه د , ب[ ©) 115 0
treceutivs is QL cade by: 0 19
وه سوه و لكك trocsutica ی اروت Cnet work ©
اه 0 متس مه موه اون اوق ۶
:اه روا لام رم beveb of ©
لو ت۱۹
لس ادوس ۶
لام لد ©
مص لد«
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. سا0 لح 0 لا سواه 1 وهم
صفحه 37:
Gad oP Okaper
صفحه 38:
read(A)
write(A)
read(B)
write(B)
read(A)
write(A)
read(B)
write(B)
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. سا0 لح 0 لا سواه 1 موم
صفحه 39:
read(A)
write(A)
read(A)
read(B)
write(A)
write(B)
read(B)
write(B)
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. 666 1 سا0 لح 0 لا سواه
صفحه 40:
write(Q)
read(Q)
write(Q)
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08.
صفحه 41:
+ (a) Gokedule ( acd (b) Goleedule O
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. سا0 لح 0 لا سواه 1 موم
صفحه 42:
۱
صفحه 43:
صفحه 44:
۱
صفحه 45:
oP Isvkica سسوم
© Gokedues worst be vehi or view seridtzoble, ood recoverable, Por the
she oP dotabuse ooesistieuy, und prePerably msradeless.
© 0 potty is whick oly coe trocsurtivg coo exer جد جبفمصص وكا د ل
sokedues, but provides 3 poor deqrer oP موجه
© Cowurew-coutdl schewes tradePP between the omni oP
واه نصا مج ced te oeut oP pverkead thot they tamu.
© Gowe schewes dow oly codPictsertaizuble schedules to be yecercied,
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08. wero ©Sbervehnts, Cork ced Cnakershe
صفحه 46:
read(A)
temp := A* 0.1
A:=A - رسع
write(A)
read(B)
B:=B + temp
wre
read(A)
A:=A-50
write (A)
read(B)
B:=B+50
write (B)
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08.
صفحه 47:
write(Q)
write(Q)
read(Q)
write(Q)
Ceadrwe Gyetrer Ovcwptr- O* Brame, Gey ©, O08.
Chapter 15: Transactions
Database System Concepts, 5th Ed.
©Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
Chapter 15: Transactions
Transaction Concept
Transaction State
Concurrent Executions
Serializability
Recoverability
Implementation of Isolation
Transaction Definition in SQL
Testing for Serializability.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.2
©Silberschatz, Korth and Sudarshan
Transaction Concept
A transaction is a unit of program execution that accesses and possibly
updates various data items.
A transaction must see a consistent database.
During transaction execution the database may be temporarily inconsistent.
When the transaction completes successfully (is committed), the database must
be consistent.
After a transaction commits, the changes it has made to the database persist,
even if there are system failures.
Multiple transactions can execute in parallel.
Two main issues to deal with:
Failures of various kinds, such as hardware failures and system
crashes
Concurrent execution of multiple transactions
Database System Concepts - 5th Edition, Sep 10, 2005.
15.3
©Silberschatz, Korth and Sudarshan
ACID Properties
A transaction is a unit of program execution that accesses and possibly updates various
data items.To preserve the integrity of data the database system must ensure:
Atomicity. Either all operations of the transaction are properly reflected in the
database or none are.
Consistency. Execution of a transaction in isolation preserves the consistency of
the database.
Isolation. Although multiple transactions may execute concurrently, each transaction
must be unaware of other concurrently executing transactions. Intermediate
transaction results must be hidden from other concurrently executed transactions.
That is, for every pair of transactions Ti and Tj, it appears to Ti that either Tj,
finished execution before Ti started, or Tj started execution after Ti finished.
Durability. After a transaction completes successfully, the changes it has made to
the database persist, even if there are system failures.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.4
©Silberschatz, Korth and Sudarshan
Example of Fund Transfer
Transaction to transfer $50 from account A to account B:
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
Atomicity requirement — if the transaction fails after step 3 and before step 6,
the system should ensure that its updates are not reflected in the database, else an
inconsistency will result.
Consistency requirement – the sum of A and B is unchanged by the execution
of the transaction.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.5
©Silberschatz, Korth and Sudarshan
Example of Fund Transfer (Cont.)
Isolation requirement — if between steps 3 and 6, another transaction is
allowed to access the partially updated database, it will see an inconsistent database
(the sum A + B will be less than it should be).
Isolation can be ensured trivially by running transactions serially, that is one
after the other.
However, executing multiple transactions concurrently has significant
benefits, as we will see later.
Durability requirement — once the user has been notified that the transaction has
completed (i.e., the transfer of the $50 has taken place), the updates to the
database by the transaction must persist despite failures.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.6
©Silberschatz, Korth and Sudarshan
Transaction State
Active – the initial state; the transaction stays in this state while it is executing
Partially committed – after the final statement has been executed.
Failed -- after the discovery that normal execution can no longer proceed.
Aborted – after the transaction has been rolled back and the database restored
to its state prior to the start of the transaction. Two options after it has been
aborted:
restart the transaction; can be done only if no internal logical error
kill the transaction
Committed – after successful completion.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.7
©Silberschatz, Korth and Sudarshan
Transaction State (Cont.)
Database System Concepts - 5th Edition, Sep 10, 2005.
15.8
©Silberschatz, Korth and Sudarshan
Implementation of Atomicity and Durability
The recovery-management component of a database system implements
the support for atomicity and durability.
The shadow-database scheme:
assume that only one transaction is active at a time.
a pointer called db_pointer always points to the current consistent copy
of the database.
all updates are made on a shadow copy of the database, and
db_pointer is made to point to the updated shadow copy only after the
transaction reaches partial commit and all updated pages have been
flushed to disk.
in case transaction fails, old consistent copy pointed to by db_pointer
can be used, and the shadow copy can be deleted.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.9
©Silberschatz, Korth and Sudarshan
Implementation of Atomicity and Durability (Cont.)
The shadow-database scheme:
Assumes disks do not fail
Useful for text editors, but
extremely inefficient for large databases (why?)
Does not handle concurrent transactions
Will study better schemes in Chapter 17.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.10
©Silberschatz, Korth and Sudarshan
Concurrent Executions
Multiple transactions are allowed to run concurrently in the system.
Advantages are:
increased processor and disk utilization, leading to better transaction
throughput: one transaction can be using the CPU while another is reading
from or writing to the disk
reduced average response time for transactions: short transactions need
not wait behind long ones.
Concurrency control schemes – mechanisms to achieve isolation; that is, to
control the interaction among the concurrent transactions in order to prevent
them from destroying the consistency of the database
Will study in Chapter 16, after studying notion of correctness of
concurrent executions.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.11
©Silberschatz, Korth and Sudarshan
Schedules
Schedule – a sequences of instructions that specify the chronological order in
which instructions of concurrent transactions are executed
a schedule for a set of transactions must consist of all instructions of those
transactions
must preserve the order in which the instructions appear in each individual
transaction.
A transaction that successfully completes its execution will have a commit
instructions as the last statement (will be omitted if it is obvious)
A transaction that fails to successfully complete its execution will have an abort
instructions as the last statement (will be omitted if it is obvious)
Database System Concepts - 5th Edition, Sep 10, 2005.
15.12
©Silberschatz, Korth and Sudarshan
Schedule 1
Let T transfer $50 from A to B, and T transfer 10% of the
1
2
balance from A to B.
A serial schedule in which T is followed by T :
1
2
Database System Concepts - 5th Edition, Sep 10, 2005.
15.13
©Silberschatz, Korth and Sudarshan
Schedule 2
• A serial schedule where T2 is followed by T1
Database System Concepts - 5th Edition, Sep 10, 2005.
15.14
©Silberschatz, Korth and Sudarshan
Schedule 3
Let T1 and T2 be the transactions defined previously. The following
schedule is not a serial schedule, but it is equivalent to Schedule 1.
In Schedules 1, 2 and 3, the sum A + B is preserved.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.15
©Silberschatz, Korth and Sudarshan
Schedule 4
The following concurrent schedule does not preserve the value of ( A
+ B).
Database System Concepts - 5th Edition, Sep 10, 2005.
15.16
©Silberschatz, Korth and Sudarshan
Serializability
Basic Assumption – Each transaction preserves database consistency.
Thus serial execution of a set of transactions preserves database consistency.
A (possibly concurrent) schedule is serializable if it is equivalent to a serial
schedule. Different forms of schedule equivalence give rise to the notions of:
1. conflict serializability
2. view serializability
We ignore operations other than read and write instructions, and we assume
that transactions may perform arbitrary computations on data in local buffers in
between reads and writes. Our simplified schedules consist of only read and
write instructions.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.17
©Silberschatz, Korth and Sudarshan
Conflicting Instructions
Instructions li and lj of transactions Ti and Tj respectively, conflict if and only if
there exists some item Q accessed by both li and lj, and at least one of these
instructions wrote Q.
1. li = read(Q), lj = read(Q). li and lj don’t conflict.
2. li = read(Q), lj = write(Q). They conflict.
3. li = write(Q), lj = read(Q). They conflict
4. li = write(Q), lj = write(Q). They conflict
Intuitively, a conflict between li and lj forces a (logical) temporal order between
them.
If li and lj are consecutive in a schedule and they do not conflict, their results
would remain the same even if they had been interchanged in the schedule.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.18
©Silberschatz, Korth and Sudarshan
Conflict Serializability
If a schedule S can be transformed into a schedule S´ by a series of swaps
of non-conflicting instructions, we say that S and S´ are conflict equivalent.
We say that a schedule S is conflict serializable if it is conflict equivalent to a serial
schedule
Database System Concepts - 5th Edition, Sep 10, 2005.
15.19
©Silberschatz, Korth and Sudarshan
Conflict Serializability (Cont.)
Schedule 3 can be transformed into Schedule 6, a serial schedule
where T2 follows T1, by series of swaps of non-conflicting
instructions.
Therefore Schedule 3 is conflict serializable.
Schedule 6
Schedule 3
Database System Concepts - 5th Edition, Sep 10, 2005.
15.20
©Silberschatz, Korth and Sudarshan
Conflict Serializability (Cont.)
Example of a schedule that is not conflict serializable:
We are unable to swap instructions in the above schedule to obtain either the serial
schedule < T3, T4 >, or the serial schedule < T4, T3 >.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.21
©Silberschatz, Korth and Sudarshan
View Serializability
Let S and S´ be two schedules with the same set of transactions. S and S´
are view equivalent if the following three conditions are met:
1. For each data item Q, if transaction Ti reads the initial value of Q in
schedule S, then transaction Ti must, in schedule S´, also read the initial
value of Q.
2. For each data item Q if transaction Ti executes read(Q) in schedule S,
and that value was produced by transaction Tj (if any), then transaction
Ti must in schedule S´ also read the value of Q that was produced by
transaction Tj .
3. For each data item Q, the transaction (if any) that performs the final
write(Q) operation in schedule S must perform the final write(Q)
operation in schedule S´.
As can be seen, view equivalence is also based purely on reads and writes
alone.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.22
©Silberschatz, Korth and Sudarshan
View Serializability (Cont.)
A schedule S is view serializable it is view equivalent to a serial schedule.
Every conflict serializable schedule is also view serializable.
Below is a schedule which is view-serializable but not conflict serializable.
What serial schedule is above equivalent to?
Every view serializable schedule that is not conflict serializable has blind writes.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.23
©Silberschatz, Korth and Sudarshan
Other Notions of Serializability
The schedule below produces same outcome as the serial schedule <
T1, T5 >, yet is not conflict equivalent or view equivalent to it.
Determining such equivalence requires analysis of operations other than
read and write.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.24
©Silberschatz, Korth and Sudarshan
Testing for Serializability
Consider some schedule of a set of transactions T1, T2, ..., Tn
Precedence graph — a direct graph where the vertices are the
transactions (names).
We draw an arc from Ti to Tj if the two transaction conflict, and Ti
accessed the data item on which the conflict arose earlier.
We may label the arc by the item that was accessed.
Example 1
x
y
Database System Concepts - 5th Edition, Sep 10, 2005.
15.25
©Silberschatz, Korth and Sudarshan
Example Schedule (Schedule A) + Precedence Graph
T1
T2
read(X)
read(Y)
read(Z)
read(V)
read(W)
read(W)
read(Y)
write(Y)
write(Z)
read(U)
read(Y)
write(Y)
read(Z)
write(Z)
T3
T4
T5
T
1
2
T
3
read(U)
write(U)
Database System Concepts - 5th Edition, Sep 10, 2005.
T
15.26
T
4
©Silberschatz, Korth and Sudarshan
Test for Conflict Serializability
A schedule is conflict serializable if and only if its
precedence graph is acyclic.
Cycle-detection algorithms exist which take order n2
time, where n is the number of vertices in the
graph.
(Better algorithms take order n + e where e is
the number of edges.)
If precedence graph is acyclic, the serializability
order can be obtained by a topological sorting of the
graph.
This is a linear order consistent with the partial
order of the graph.
For example, a serializability order for
Schedule A would be
T5 T1 T3 T2 T4
Are there others?
Database System Concepts - 5th Edition, Sep 10, 2005.
15.27
©Silberschatz, Korth and Sudarshan
Test for View Serializability
The precedence graph test for conflict serializability cannot be used directly to test
for view serializability.
The problem of checking if a schedule is view serializable falls in the class of
NP-complete problems.
Extension to test for view serializability has cost exponential in the size of the
precedence graph.
Thus existence of an efficient algorithm is extremely unlikely.
However practical algorithms that just check some sufficient conditions for view
serializability can still be used.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.28
©Silberschatz, Korth and Sudarshan
Recoverable Schedules
Need to address the effect of transaction failures on concurrently
running transactions.
Recoverable schedule — if a transaction Tj reads a data item previously written by
a transaction Ti , then the commit operation of Ti appears before the commit
operation of Tj.
The following schedule (Schedule 11) is not recoverable if T9 commits
immediately after the read
If T8 should abort, T9 would have read (and possibly shown to the user) an
inconsistent database state. Hence, database must ensure that schedules are
recoverable.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.29
©Silberschatz, Korth and Sudarshan
Cascading Rollbacks
Cascading rollback – a single transaction failure leads to a series of
transaction rollbacks. Consider the following schedule where none of the
transactions has yet committed (so the schedule is recoverable)
If T10 fails, T11 and T12 must also be rolled back.
Can lead to the undoing of a significant amount of work
Database System Concepts - 5th Edition, Sep 10, 2005.
15.30
©Silberschatz, Korth and Sudarshan
Cascadeless Schedules
Cascadeless schedules — cascading rollbacks cannot occur; for each pair of
transactions Ti and Tj such that Tj reads a data item previously written by Ti, the
commit operation of Ti appears before the read operation of Tj.
Every cascadeless schedule is also recoverable
It is desirable to restrict the schedules to those that are cascadeless
Database System Concepts - 5th Edition, Sep 10, 2005.
15.31
©Silberschatz, Korth and Sudarshan
Concurrency Control
A database must provide a mechanism that will ensure that all possible schedules are
either conflict or view serializable, and
are recoverable and preferably cascadeless
A policy in which only one transaction can execute at a time generates serial
schedules, but provides a poor degree of concurrency
Are serial schedules recoverable/cascadeless?
Testing a schedule for serializability after it has executed is a little too late!
Goal – to develop concurrency control protocols that will assure serializability.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.32
©Silberschatz, Korth and Sudarshan
Concurrency Control vs. Serializability Tests
Concurrency-control protocols allow concurrent schedules, but ensure that the
schedules are conflict/view serializable, and are recoverable and cascadeless.
Concurrency control protocols generally do not examine the precedence graph
as it is being created
Instead a protocol imposes a discipline that avoids nonseralizable schedules.
We study such protocols in Chapter 16.
Different concurrency control protocols provide different tradeoffs between the
amount of concurrency they allow and the amount of overhead that they incur.
Tests for serializability help us understand why a concurrency control protocol is
correct.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.33
©Silberschatz, Korth and Sudarshan
Weak Levels of Consistency
Some applications are willing to live with weak levels of consistency, allowing
schedules that are not serializable
E.g. a read-only transaction that wants to get an approximate total balance of
all accounts
E.g. database statistics computed for query optimization can be approximate
(why?)
Such transactions need not be serializable with respect to other transactions
Tradeoff accuracy for performance
Database System Concepts - 5th Edition, Sep 10, 2005.
15.34
©Silberschatz, Korth and Sudarshan
Levels of Consistency in SQL-92
Serializable — default
Repeatable read — only committed records to be read, repeated reads of same
record must return same value. However, a transaction may not be
serializable – it may find some records inserted by a transaction but not find
others.
Read committed — only committed records can be read, but successive reads
of record may return different (but committed) values.
Read uncommitted — even uncommitted records may be read.
Lower degrees of consistency useful for gathering approximate
information about the database
Database System Concepts - 5th Edition, Sep 10, 2005.
15.35
©Silberschatz, Korth and Sudarshan
Transaction Definition in SQL
Data manipulation language must include a construct for specifying the set of
actions that comprise a transaction.
In SQL, a transaction begins implicitly.
A transaction in SQL ends by:
Commit work commits current transaction and begins a new one.
Rollback work causes current transaction to abort.
Levels of consistency specified by SQL-92:
Serializable — default
Repeatable read
Read committed
Read uncommitted
Database System Concepts - 5th Edition, Sep 10, 2005.
15.36
©Silberschatz, Korth and Sudarshan
End of Chapter
Database System Concepts, 5th Ed.
©Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
Database System Concepts - 5th Edition, Sep 10, 2005.
15.38
©Silberschatz, Korth and Sudarshan
Database System Concepts - 5th Edition, Sep 10, 2005.
15.39
©Silberschatz, Korth and Sudarshan
Schedule 7
Database System Concepts - 5th Edition, Sep 10, 2005.
15.40
©Silberschatz, Korth and Sudarshan
Precedence Graph for
(a) Schedule 1 and (b) Schedule 2
Database System Concepts - 5th Edition, Sep 10, 2005.
15.41
©Silberschatz, Korth and Sudarshan
Illustration of Topological Sorting
Database System Concepts - 5th Edition, Sep 10, 2005.
15.42
©Silberschatz, Korth and Sudarshan
Precedence Graph
Database System Concepts - 5th Edition, Sep 10, 2005.
15.43
©Silberschatz, Korth and Sudarshan
fig. 15.21
Database System Concepts - 5th Edition, Sep 10, 2005.
15.44
©Silberschatz, Korth and Sudarshan
Implementation of Isolation
Schedules must be conflict or view serializable, and recoverable, for the
sake of database consistency, and preferably cascadeless.
A policy in which only one transaction can execute at a time generates serial
schedules, but provides a poor degree of concurrency.
Concurrency-control schemes tradeoff between the amount of
concurrency they allow and the amount of overhead that they incur.
Some schemes allow only conflict-serializable schedules to be generated,
while others allow view-serializable schedules that are not conflict-serializable.
Database System Concepts - 5th Edition, Sep 10, 2005.
15.45
©Silberschatz, Korth and Sudarshan
Figure 15.6
Database System Concepts - 5th Edition, Sep 10, 2005.
15.46
©Silberschatz, Korth and Sudarshan
Figure 15.12
Database System Concepts - 5th Edition, Sep 10, 2005.
15.47
©Silberschatz, Korth and Sudarshan