You are on page 1of 20

Adv

ancedDB
CH1
Conceptf
orOOD
Dat
a➛i
sar
awf
actf
igur
esy
mbol
repr
esent
ati
on
I
nfor
mat
ion➛i
tisapr
ocesseddat
a
➛i
tisusedt
odeci
sionmake
➛i
tisagui
dli
nesf
ordeci
sionmaki
ng
DB➛i
tisal
ogi
cal
rel
ateddat
a
➛i
tisal
ogi
cal
rel
atedcol
l
ect
ionofdat
a
➛anorgani
zedcoll
ecti
onofst
oredr
elat
eddat
a,w/
cis
desi
gnedtobeaccessi
bleinv
ari
ousway
DBMS➛isaSW designedtoasistuser
's&appl
i
cat
ion'
s,ut
il
izi
ng
&mai
ntai
ningl
argecol
lect
ionofdata
Eg✥SQL
✥My
SQL
✥Or
acl
e
Tr
adi
ti
onal
DB➛or
gani
zedbyf
il
eds,
recor
ds&f
il
es.

AFi
l
ed➛i
sasi
ngl
epi
eceofi
nfor
mat
ion

ARecor
d➛i
sonecompl
etef
il
eds

AFi
l
e➛i
sacol
l
ect
ionofr
ecor
ds

@y
aredaa ki
myar
ed330@gmai
l
.com 1
Tr
adi
ti
onal
DBs➛ar
eusedt
ost
oredat
athat
:
➢hassi
mpl
eobj
ectst
ruct
ure
➢hasshor
tdur
ati
onTr
➢hasst
andar
d(common)
dat
aty
pe

Adv
ancedDB
OODB➛I
tisdesi
gnf
or

➢hav
emor
ecompl
exobj
ectst
ruct
ure
➢hav
elongdur
ati
onTr
➢suppor
tnewdat
aty
pe
➢supportt
heneedt
odef
inenon-
standar
dappl
i
cat
ion
speci
fi
coperat
ion

OOP➛appr
oachesof
fer
sfl
exi
blet
ohandl
edsomer
equi
rement
dat
aty
pes,
quer
ylanguage

OODB➛hel
pst
odesi
gnert
ospeci
fybot
hst
ruct
ure&compl
ex
obj
ect
Ov
erv
iewofOOconcept
OO➛conceptareappl
iedi
nareaofDBs,SW
engi
neer
ing,
knowl
edgebase,
Art
if
ici
ali
ntel
l
igence&comput
er
sci
encei
ngeneral
ly.
➢Abst
ractdat
aty
pes

Obj
ectI
dent
if
y,Obj
ectSt
ruct
ure&Ty
pesofConst
ruct
or
@y
aredaa ki
myar
ed330@gmai
l
.com 2
Obj
ectI
dent
if
y(I
OD)
➢i
tisuni
quel
yident
if
yeachi
ndependentobj
ect
Ty
pesofconst
ruct
or&St
ruct
ure
✦inOODB➛t hest ate(
currentv
alue)ofcomplexobjectmay
beconstr
uctedf rom anotherobject(ot
herval
ue)byone
for
malwayofr epresenti
ngsuchobj ecti
stovieweach
obj
ecttr
ipl
e(I,C,V)
➢Wher
e I
➛isauni
queofOI
D
C➛i
sty
peofconst
ruct
or
V➛i
sty
peobj
ectst
ate(
cur
rentv
alue)
✦t
het
hreebasi
cconst
ruct
ors
✥at
om
✥t
upl
e
✥set
Encapsul
ati
onofoper
ati
onsMet
hod&per
sist
ence
Encapsul
ati
on➛oneofmai
nchar
act
eri
sti
csOOL&sy
stem
➢relat
edtoconceptofabst
ractdat
aty
pe&i
nfor
mat
ion
hi
dingprogr
am
✦speci
fyi
ngobj
ectbehav
iorofcl
assoper
ati
on

@y
aredaa ki
myar
ed330@gmai
l
.com 3
Per
sist
ence➛per
manentst
orageofDB.
Ty
peHi
erar
chi
es&i
nher
it
ance
✦Therear
eobject
sw/chavet
hesamety
peorclass
t
heref
oret
oclassi
fyt
heseobj
ect
sOODBprov
ides:
➢defini
ti
onofnewty
pesbasedont heot
herpr
edef
ined
t
ypes,
l
eadingt
oat y
pe(cl
ass)
hier
archy
CH2
2.
1.Tr
ansl
ati
ngSQLQuer
iesi
ntoRel
ati
onal
Algebr
a

•Everydat
abasemanagementsyst
em mustdef
ineaquer
ylanguaget
oal
l
owuser
s
toaccessthedat
ast
oredinthedat
abase.

✦Quer
yist
hepr
ocessofdi
spl
ayr
esul
tsi
nput
/out
put

✦ Ther
ear
etwof
ormsofquer
ylanguages:

r
elat
ional
algebr
aand

r
elat
ional
cal
cul
us.

✦Relati
onal
calcul
usi
saconcept
ual
non-
procedur
alquer
ylanguageusedon
r
elat
ionalmodel.

✦ Relat
ional
algebr
aisaproceduralquer
ylanguage,whi
chtakesi
nst
ancesof
r
elat
ionsasinputandgi
vesinstancesofnewr el
ati
onsasoutput
.

✦ Rel
ati
onalalgebr
ausesvar
iousoper
ati
onst
oper
for
mthi
sact
ion.Anoper
atorcan
beeit
herunaryorbinar
y.

✦Rel
ati
onal
Algebr
aconsi
stsofsev
eral
groupsofoper
ati
ons

1.Unar
yRel
ati
onal
Oper
ati
ons

SELECT(
symbol
:σ(
sigma)
)

PROJECT(
symbol
:π(
pi)
)

@y
aredaa ki
myar
ed330@gmai
l
.com 4
RENAME(
symbol
:ρ(
rho)
)

2.Rel
ati
onal
Algebr
aOper
ati
onsFr
om Set
Theor
y

UNI
ON(∪)

I
NTERSECTI
ON(∩)

DI
FFERENCE(
orMI
NUS,
–)

CARTESI
ANPRODUCT(x)

3.Bi
nar
yRel
ati
onal
Oper
ati
ons

JOI
N(sev
eral
var
iat
ionsofJOI
Nexi
st)

DI
VISI
ON

4.Addi
ti
onal
Rel
ati
onal
Oper
ati
ons
SUM,

COUNT

AVG,

MI
N,

MAX

Sel
ectOper
ati
on(
σ)
✦I
tisusedt
osel
ectr
ows(
tupl
es)f
rom t
abl
e(r
elat
ion)whi
chsat
isf
iesagi
vencondi
ti
on.

➢σ:
(si
gma)
:repr
esent
sthepr
edi
cat
e

Pr
ojectOper
ati
on(
∏)
✦Pr
ojectoper
ati
oni
susedt
opr
ojectonl
yacer
tai
nsetofat
tr
ibut
esofar
elat
ion.

✦ Thepr
oject
ionmet
hoddef
inesar
elat
iont
hatcont
ainsav
ert
ical
subsetofRel
ati
on.

✦Itwi
llonl
yproj
ectorshowt
hecol
umnsorat
tri
but
esaskedf
or,
andwi
l
lal
sor
emov
edupl
i
cat
e
dat
afr
om thecol
umns.

✦Inotherwor
ds,I
fyouwanttoseeonl
ythenamesal
loft
hest
udent
sint
heSt
udentt
abl
e,t
hen
youcanuseProj
ectOper
ati
on.
@y
aredaa ki
myar
ed330@gmai
l
.com 5
Sy
ntax:
∏A1,
A2.
..
(r
)

wher
e

➢ (
pi):
usedt
ochooseat
tri
but
esf
rom ar
elat
ion.

➢A1,
A2,
An:
areat
tri
but
enames

➢r
:denot
esr
elat
ion

Not
ethat
:Sel
ect
ionoper
ati
onSel
ect
sRowswhi
l
ePr
oject
ionOper
ati
onSel
ect
sCol
umns.whati
f
weneedt
osel
ectsomeoft
heRowsandsomeoft
hecol
umnsatt
hesamet
ime.

Exampl
e:I
fweneedt
osel
ectI
D,Fi
rstNameoft
hest
udent
swhohav
ecommul
ati
veGPAgr
eat
er
t
han3.
25

➢ SQLSt
atement
:sel
ectSt
udI
D,Fnamef
rom st
udentwher
eGPA>3.
25;

➢ Rel
ati
onal
Algebr
aExpr
essi
onwi
l
lbe:
∏St
udI
D,Fname(
σGPA>3.
25St
udent
)

•wecanal
sowri
teinthef
oll
owingmanner:
σGPA>3. 25(∏St
udID,FnameSt
udent
)Togener
ali
ze
youcanwr
it
eσCondit
ion(
Expir
ati
on)or∏Li
stofat
tr
ibut
e(Expi
rati
on)

RenameOper
ati
on(
ρ)
✦ Thi
soper
ati
oni
susedt
orenamet
heout
putr
elat
ionf
oranyquer
yoper
ati
onwhi
chr
etur
ns

r
esul
tli
keSel
ect
,Pr
ojectet
c.Ort
osi
mpl
yrenamear
elat
ion(
tabl
e)

➢Sy
ntax:
ρ(NewRel
ati
on,
OldRel
ati
on)

Uni
onOper
ati
on(
∪)

✦Thi
soper
ati
oni
susedt
osel
ectdat
afr
om t
wor
elat
ions(
tabl
es)ort
empor
aryr
elat
ion(
resul
tof
anot
heroper
ati
on)
.

✦Itper
formsbinar
yuni
onbet
weentwogivenr
elat
ionsandi
sdef
inedas:
A∪B={t|
t∈Aort

B}
Forthisoper
ati
ontowor
k,t
herel
ati
ons

➢Musthav
ethesamenumberofat
tri
but
es.

➢At
tri
but
edomai
nsneedt
obecompat
ibl
e.

➢Dupl
i
cat
etupl
esshoul
dbeaut
omat
ical
l
yremov
ed.

Sy
ntax:
A∪B

Exampl
e:

@y
aredaa ki
myar
ed330@gmai
l
.com 6
➢ifwehavetwot abl
esRegul
arCl
assandExtensi
onCl
ass,bothhaveacolumnFnamet
osav
e
nameofstudent
,then,
∏Fname(Regul
arCl
ass)∪ Fname(Extensi
onClass)

SetDi
ff
erence(
-)

✦Thi
soper
ati
oni
susedt
ofi
nddat
apr
esenti
noner
elat
ionandnotpr
esenti
nthesecondr
elat
ion.

✦Thi
soper
ati
oni
sal
soappl
i
cabl
eont
wor
elat
ions,
justl
i
keUni
onoper
ati
on.

✦Ther
esul
tofA-B,
isar
elat
ionwhi
chi
ncl
udesal
ltupl
est
hatar
einAbutnoti
nB.

➢Theat
tr
ibut
enameofAhast
omat
chwi
tht
heat
tr
ibut
enamei
nB.

➢Thet
wo-
oper
andr
elat
ionsAandBshoul
dbeei
thercompat
ibl
eorUni
oncompat
ibl
e.

➢I
tshoul
dbedef
inedr
elat
ionconsi
sti
ngoft
het
upl
est
hatar
einr
elat
ionA,
butnoti
nB.

Sy
ntax:
A-B

Exampl
e:

•I
fwewanttof
indnameofstudent
swhoat
tendt
her
egul
arcl
assbutnott
heext
ensi
oncl
ass,
then,
wecanuset
hebelowoper
ati
on:

∏Fname(
Regul
arCl
ass)-∏Fname(
Ext
ent
ionCl
ass)

Car
tesi
anPr
oduct(
X)

✦ Thi
sisusedt
ocombi
nedat
afr
om t
wodi
ff
erentr
elat
ions(
tabl
es)i
ntooneandsel
ectdat
afr
om
t
hecombi
nedr
elat
ion.

✦ACar
tesi
anpr
oductbecomesmeani
ngf
ulwheni
tisf
oll
owedbyot
heroper
ati
ons.

Sy
ntax:
AXB

➛Canbedef
inedas:
AΧB={qt|
q∈Aandt
∈B}

Exampl
e

•Ifwewantt
ofi
ndtheinf
ormat
ionf
orRegul
arCl
assandExt
ent
ionCl
asswhi
char
econduct
ed
duri
ngmorni
ng,
then,
wecanusethefol
l
owingoper
ati
on:

σt
ime='
mor
ning'
(Regul
arCl
assXExt
ent
ionCl
ass)

I
nter
sect
ion(
∩)

✦Def
inesar
elat
ionconsi
sti
ngofasetofal
ltupl
ethatar
einbot
hAandB.Howev
er,
AandBmust
beuni
on-
compat
ibl
e.

@y
aredaa ki
myar
ed330@gmai
l
.com 7
Sy
ntax:
A∩B

Joi
nOper
ati
ons(
⋈)
✦ Joi
noper
ati
oni
sessent
ial
l
yacar
tesi
anpr
oductf
oll
owedbyasel
ect
ioncr
it
eri
on.

➢Joi
noper
ati
ondenot
edby⋈.

✦Joi
noper
ati
onal
soal
l
owsj
oini
ngv
ari
ousl
yrel
atedt
upl
esf
rom di
ff
erentr
elat
ions.

➢Ty
pesofJoi
n:

➛I
nnerJoi
ns: Out
erj
oin

➛Thet
ajoi
n ➛ Lef
tOut
erJoi
n

➛EQUIj
oin ➛ Ful
lOut
erJoi
n

➛Nat
ural
joi
n ➛Ri
ghtOut
erJoi
n

✦Inaninnerj
oin,
onl
ythoset
upl
est
hatsat
isf
ythemat
chi
ngcr
it
eri
aar
eincl
uded,
whi
l
ether
estar
e
excl
uded.

Addi
ti
onal
Rel
ati
onal
Oper
ati
ons
✦Commonfunct
ionsappl
i
edt
ocol
l
ect
ionsofnumer
icv
aluesi
ncl
udeSUM,
AVERAGE,
MAXI
MUM,
andMI
NIMUM.

➢TheCOUNTf
unct
ioni
susedf
orcount
ingt
upl
esorv
alues.

Useoft
heFunct
ional
oper
atorF

➢ FMAXSal
ary
(Empl
oyee)
ret
ri
evest
hemaxi
mum sal
aryv
aluef
rom t
heEmpl
oyeer
elat
ion

➢ FMI
NSal
ary
(Empl
oyee)
ret
ri
evest
hemi
nimum Sal
aryv
aluef
rom t
heEmpl
oyeer
elat
ion

➢FSUMSal
ary
(Empl
oyee)
ret
ri
evest
hesum oft
heSal
aryf
rom t
heEmpl
oyeer
elat
ion

Quer
yPr
ocessi
ng
✦ Quer
yPr
ocessi
ngi
sat
ransl
ati
onofhi
gh-
lev
elquer
iesi
ntol
ow-
lev
elexpr
essi
on.

✦Itisthestepbyst
epprocessofbr
eaki
ngthehi
ghlevell
anguagei
ntol
owl
evel
languagewhi
chmachi
ne
canunderst
andandper
formt her
equest
edact
ionforuser
.

✦I
trequi
rest
hebasi
cconcept
sofr
elat
ional
algebr
aandf
il
est
ruct
ure.

✦Quer
ypr
ocessori
ntheDBMSper
for
mst
hef
oll
owi
ngt
ask.

Quer
ypr
ocessi
ngi
sdonei
nthef
oll
owi
ngst
eps:

@y
aredaa ki
myar
ed330@gmai
l
.com 8
Par
ser

Dur
ingpar
secal
l
,thedat
abaseper
for
mst
hef
oll
owi
ngchecks

1.Sy
ntaxcheck:concl
udesSQLsy
ntact
icv
ali
dit
y.

Ex
ampl
e:SELECT*FORM empl
oyee

Her
eer
rorofwr
ongspel
l
ingofFROM i
sgi
venbyt
hischeck.

2.Semant
iccheck:
det
ermi
neswhet
hert
hest
atementi
smeani
ngf
ulornot
.

Ex
ampl
e:quer
ycont
ainsat
abl
enamewhi
chdoesnotexi
sti
scheckedbyt
hischeck.

3.Shar
edPool
check:Ever
yquer
ypossessahashcodedur
ingi
tsexecut
ion.

Opt
imi
zer
:
Fi
ndi
ngt
hecheapestev
aluat
ionpl
anf
oraquer
y.

➢Gi
venr
elat
ional
algebr
aexpr
essi
onmayhav
emanyequi
val
entexpr
essi
ons

Ex
ampl
e:σbal
ance<2500(
Πbal
ance(
account
))i
sequi
val
entt
oΠbal
ance(
σbal
ance<2500(
account
))

•Amongstal
lequi
val
entexpr
essi
ons,
tryt
ochooset
heonewi
thcheapestpossi
bleev
aluat
ion-
plan.

Cat
alogI
nfor
mat
ionf
orCostEst
imat
ion

➢ nr
:numberoft
upl
esi
nrel
ati
on

➢ br
:numberofbl
ockscont
aini
ngt
upl
esofr
.

➢ sr
:si
zeofat
upl
eofri
nby
tes.

@y
aredaa ki
myar
ed330@gmai
l
.com 9
➢f
r:bl
ocki
ngf
act
orof

Twomai
nTechni
quesf
orQuer
yOpt
imi
zat
ion

➢1.Heur
ist
icRul
es:
Rul
esf
oror
der
ingt
heoper
ati
onsi
nquer
yopt
imi
zat
ion.

➢2.Sy st
emat
icalest
imat
ion:I
testi
matescostofdi
ff
erentexecut
ionst
rat
egi
esandchoosest
he
execut
ionpl
anwit
hlowestexecut
ioncost.

CHAPTER3

Tr
ansact
ion

✦Tr
ansact
ioni
sapr
ogr
am uni
twhoseexecut
ionmayormaynotchanget
hecont
entoft
he

dat
abase.

➛ Exampl
e:sel
ect
,inser
t,updat
e.

✦ At
ransact
ioncanbedef
inedasagr
oupoft
asks.

✦Ifthedat
abaseoper
ati
onsdonotupdat
ethedat
abasebutonl
yret
ri
evedat
a,t
hist
ypeoft
ransact
ioni
s
cal
ledaread-
onlytr
ansacti
on.

✦Ift
hedatabasewereinaninconsi
stentst
atebef
oreat
ransact
ion,
itwoul
dremai
nint
hei
nconsi
stent
st
ateaf
terthetr
ansact
ion.

✦ Adat
abasei
sashar
edr
esour
ceaccessed.

➛I
tisusedbymanyuser
sandpr
ocessesconcur
rent
ly.

✥ Forexampl
e,t
hebanki
ngsy
stem,
rai
l
way
,et
c.

✦ Notmanagi
ngconcur
rentaccessmaycr
eat
eissuesl
i
ke:

➢Har
dwar
efai
l
ureandsy
stem cr
ashes

➢Concur
rentexecut
ionoft
hesamet
ransact
ion,
deadl
ock,
orsl
owper
for
mance

Concur
rency

I
nter
leav
edpr
ocessi
ng:

•Concur
rentexecut
ionofpr
ocessesi
sint
erl
eav
edi
nasi
ngl
eCPUusi
ngf
orexampl
e,r
oundr
obi
nal
gor
it
hm

Par
all
elpr
ocessi
ng:

•I
fPr
ocessesar
econcur
rent
lyexecut
edi
nmul
ti
pleCPUs.

✦Eachhi
ghl
evel
oper
ati
oncanbedi
vi
dedi
ntoanumberofl
owl
evel
tasksoroper
ati
ons.For

exampl
e,adat
aupdat
eoper
ati
oncanbedi
vi
dedi
ntot
hreet
asks:

➢r
ead_
item(
):r
eadsdat
ait
em fr
om st
oraget
omai
nmemory
.
@yar
edaa ki
my ar
ed330@gmai
l
.com 10
➢ modi
fy_
item(
):changev
alueofi
tem i
nthemai
nmemor
y.

➢ wr
it
e_i
tem(
):wr
it
ethemodi
fi
edv
aluef
rom mai
nmemor
ytost
orage.

✦Dat
abaseaccessi
srest
ri
ctedt
oread_
item(
)andwr
it
e_i
tem(
)oper
ati
ons.

➢f
oral
ltr
ansact
ions,
readandwr
it
efor
mst
hebasi
cdat
abaseoper
ati
ons.

✦ Dat
abaseshoul
dbei
naconsi
stentst
ateaf
terandbef
oret
ransact
ion.

Tr
ansact
ionandSy
stem Concept
s

➢Tr
ansact
ionscanbecat
egor
izedasf
oll
ows:

A.
BasedonAppl
i
cat
ionar
eas

✥Non-
dist
ri
but
edv
s.di
str
ibut
ed

✥ Compensat
ingt
ransact
ions

✥Tr
ansact
ionsTi
ming

✥ On-
li
nev
s.bat
ch

B.
BasedonAct
ions

✥Two-
step

✥Rest
ri
cted

✥ Act
ionmodel

C.
BasedonSt
ruct
ure

✥Fl
atorsi
mpl
etr
ansact
ions

✥ Nest
edt
ransact
ions

✥ Wor
kfl
ow

D.
Singl
e-UserSy
stem

✥Atmostoneuseratat
imecanuset
hedat
abasemanagementsy
stem.

➛Eg.Per
sonal
comput
ersy
stem.

E.
Mul
ti
-userSy
stem

✥Manyuser
scanaccesst
heDBMSconcur
rent
ly.

➛ Eg.Ai
rl
iner
eser
vat
ion,
Bank

@y
aredaa ki
myar
ed330@gmai
l
.com 11
Tr
ansact
ionboundar
ies

✦ Anysi
ngl
etr
ansact
ioni
nanappl
i
cat
ionpr
ogr
am i
sboundedwi
thBegi
nandEndst
atement
s.

✦Anappl i
cati
onpr
ogr
am maycont
ainsev
eral
transact
ionssepar
atedbyt
heBegi
nandEndt
ransact
ion
boundar
ies..

Pr
oper
ti
esofTr
ansact
ion
✦ACIDProperties
✦At
ransact
ioni
sav
erysmal
luni
tofapr
ogr
am andi
tmaycont
ainsev
eral
lowl
evel
tasks.

✦ At
ransact
ioni
nadat
abasesy
stem mustmai
nt nAt
ai omi
cit
y,Consi
stency
,Isol
ati
on,
andDur
abi
l
ity
yknownasACI
commonl Dpr
oper
ti
esi
nor
dert
oensur
eaccur
acy
,compl
eteness,
anddat
aint
egr
it
y.

1.At
omi
cit
y:

➢Thispropert
ystatesthatat
ransact
ionmustbet
reat
edasanat
omi
cuni
t,t
hati
s,ei
theral
lofi
ts
oper
ati
onsareexecutedornone.

➢Ther
emustbenost
atei
nadat
abasewher
eat
ransact
ioni
slef
tpar
ti
all
ycompl
eted.

➢St at
esshoul
dbedefinedei
therbeforetheexecut
ionoft
het
ransact
ionoraf
tert
he
executi
on/
abort
ion/
fai
l
ureofthetransacti
on.

2•Consi
stency

➢Thedat
abasemustr
emai
ninaconsi
stentst
ateaf
teranyt
ransact
ion.

➢Not
ransact
ionshoul
dhav
eanyadv
erseef
fectont
hedat
aresi
dingi
nthedat
abase.

➢I fthedatabasewasinaconsist
entstatebef
oret
heexecut
ionofat
ransact
ion,
itmustr
emai
n
consi
stentaf
tertheexecut
ionoft
hetransacti
onaswell
.

3•Dur
abi
l
ity

➢Thedat
abaseshoul
dbedur
abl
eenought
ohol
dal
li
tsl
atestupdat
esev
eni
fthesy
stem f
ail
sorr
est
art
s.

➢Ifatransact
ionupdat
esachunkofdat
ainadat
abaseandcommi
ts,
thent
hedat
abasewi
l
lhol
dthe
modif
ieddata.

➢Ifat
ransact
ioncommit
sbutthesystem f
ail
sbef
orethedatacoul
dbewr
it
tenont
othedi
sk,
thent
hat
dat
awil
lbeupdatedoncet
hesystem spri
ngsbacki
ntoact
ion.

4•I
sol
ati
on

✦Inadat abasesystem wheremorethanonetransact


ionarebei
ngexecut
edsimultaneousl
yandinparal
lel
,
t
hepr opert
yofisolati
onstat
esthatal
lthet
ransacti
onswill
becarri
edoutandexecutedasifiti
stheonly
t
ransacti
oninthesy stem.

@y
aredaa ki
myar
ed330@gmai
l
.com 12
➢Not
ransact
ionwi
l
laf
fectt
heexi
stenceofanyot
hert
ransact
ion

Tr
ansact
ionOper
ati
ons
✦Thel
owl
evel
oper
ati
onsper
for
medi
nat
ransact
ionar
e:

➢begi
n_t
ransact
ion:
Amar
kert
hatspeci
fi
esst
artoft
ransact
ionexecut
ion.

➢read_
item orwrit
e_i
tem:
Dat
abaseoper
ati
onst
hatmaybei
nter
leav
edwi
thmai
nmemor
yoper
ati
ons
asapar
toftransact
ion.

➢end_
transact
ion:
Amar
kert
hatspeci
fi
esendoft
ransact
ion.

➢commit:Asignal
tospeci
fyt
hatt
het
ransact
ionhasbeensuccessf
ull
ycompl
etedi
nit
sent
ir
etyand
wi
l
lnotbeundone.

➢r ol
l
back: Asi
gnal
tospeci
fythatt
hetr
ansacti
onhasbeenunsuccessf
ulandsoal
ltempor
arychanges
i
nthedatabasear
eundone.Acommi t
tedt
ransact
ioncannotber
oll
edback.

Tr
ansact
ionSt
ates

✦At
ransact
ionmaygot
hroughasubsetofdi
ff
erentst
ates,
act
ive,
par
ti
all
ycommi
tt
ed,
commi
tt
ed,
fai
l
ed
andabor
ted.

Act
ive:

➢Thi
sist
hef
ir
stst
atei
nthel
i
fecy
cleofat
ransact
ion.

➢ At
ransact
ioni
scal
l
edi
nanact
ivest
ateasl
ongasi
tsi
nst
ruct
ionsar
eget
ti
ngexecut
ed.

➢ Al
lthechangesmadebyt
het
ransact
ionnowar
est
oredi
nthebuf
feri
nmai
nmemor
y.

Par
ti
all
yCommi
tt
ed:

✦TheTrent
erst
hisst
ateaf
tert
hel
astst
atementoft
heTrhasbeenexecut
ed.

✦Iti
snotconsi
der
edf
ull
ycommi
tt
edbecauseal
lthechangesmadebyt
het
ransact
ionar
est
il
lst
oredi
n
t
hebuff
eri
nmainmemory.

Commi
tt
ed:
✦Aft
eral
lthechangesmadebyt
het
ransact
ionhav
ebeensuccessf
ull
yst
oredi
ntot
hedat
abase,
itent
ers
i
ntoacommitt
edstate.

✦Now,
thet
ransact
ioni
sconsi
der
edt
obef
ull
ycommi
tt
ed.

•Af
terat
ransact
ionhasent
eredt
hecommi
tt
edst
ate,
iti
snotpossi
blet
orol
lbackt
het
ransact
ion.

•Theonlywayt
oundothechangesi
sbycarr
yingoutanot
hert
ransact
ioncal
l
edascompensat
ing
tr
ansact
iont
hatper
for
mstherever
seoper
ati
ons.

@y
aredaa ki
myar
ed330@gmai
l
.com 13
Fai
l
ed:
✦ Thet
ransacti
ongoesfrom par
ti
all
ycommi t
tedstat
eoractivest
atet
ofail
edstat
ewhenitisdi
scov
ered
t
hatnor
mal execut
ioncannolongerproceedorsy
stem checksfai
li
tent
ersint
oafail
edst
ate.

Abor
ted:
✦ Aft
erthet
ransact
ionhasf
ail
edandent
eredi
ntoaf
ail
edst
ate,
all
thechangesmadebyi
thav
etobe
undone.

✦ Aft
erthet
ransact
ionhasrol
ledbackcompl
etel
yandthedatabasehasbeenr
est
oredt
oit
sst
atet
hatwas
bef
orethetr
ansacti
onbegan,i
tenter
sint
oanabortedst
ate.

Ter
minat
edSt
ate:

✦Thi
sist
hel
astst
atei
nthel
i
fecy
cleofat
ransact
ion.

✦ Af
terent
eri
ngthecommit
tedst
ateorabor
tedst
ate,
thet
ransact
ionf
inal
l
yent
ersi
ntoat
ermi
nat
edst
ate
wher
eitsli
fecycl
efi
nal
l
ycomestoanend.

Schedul
esandRecov
erabi
l
ity

Schedul
e

✦ ASchedul
eisapr
ocesscr
eat
ingasi
ngl
egr
oupoft
hemul
ti
plepar
all
elt
ransact
ionsandexecut
ingt
hem
onebyone.

➢Ift
wot
ransact
ionsar
eexecut
edatt
hesamet
ime,
ther
esul
tofonet
ransact
ionmayaf
fectt
heout
putof
ot
her
.

✦Paral
l
elexecut
ioni
nadatabaseisi
nevi
tabl
e.But
,Paral
lel
executionisper
mit
tedwhent
her
eisan
equi
val
encerel
ati
onamongstthesi
mult
aneousl
yexecuti
ngtransacti
ons.

Thi
sequi
val
encei
sof3Ty
pes.

1.Resul
tEqui
val
ence
@y
aredaa ki
myar
ed330@gmai
l
.com 14
➢I
ftwoschedul
esdi
spl
ayt
hesamer
esul
taf
terexecut
ion,
iti
scal
l
edr
esul
tequi
val
entschedul
e.

2.
ViewEqui
val
ence

➢Vi
ewEqui
val
enceoccur
swhent
het
ransact
ioni
nbot
htheschedul
eper
for
msasi
mil
aract
ion.

➢ Thet
ransact
ioni
sthesame,
butt
het
abl
esar
edi
ff
erent
.

3.
Conf
li
ctEqui
val
ence

➢I
nthi
scase,
twot
ransact
ionsupdat
e/v
iewt
hesamesetofdat
a.

➢Ther
eisaconf
li
ctamongstt
ransact
ionast
heor
derofexecut
ionwi
l
laf
fectt
heout
put
.

Ty
pesofSchedul
es

@y
aredaa ki
myar
ed330@gmai
l
.com 15
1.Ser
ial
Schedul
es:

➢Schedul
esinwhi cht
hetransacti
onsareexecut
ednon-i
nter
leav
ed,i
.e.
,aseri
alschedul
eisonei
n
whi
chnotransact
ionstar
tsuntilarunni
ngtr
ansacti
onhasendedarecal
ledseri
alschedul
es.

T1 T2

R(
A)

W(
A)

R(
B)

W(
B)

R(
A)

R(
B)

2.Non-
Ser
ial
Schedul
e:

✦ Thi
sisat
ypeofSchedul
i
ngwher
etheoper
ati
onsofmul
ti
plet
ransact
ionsar
eint
erl
eav
ed.

✦Thi
smi
ghtl
eadt
oar
isei
ntheconcur
rencypr
obl
em.

✦ Thi
ssor
tofschedul
edoesnotpr
ovi
deanybenef
itoft
heconcur
rentt
ransact
ion.

✦TheNon-
Ser
ial
Schedul
ecanbedi
vi
dedf
urt
heri
ntoSer
ial
i
zabl
eandNon-
Ser
ial
i
zabl
e.

A.Ser
ial
i
zabl
e:

➢ Thi
sisusedt
omai
ntai
ntheconsi
stencyoft
hedat
abase.

➢Itismainlyusedi
ntheNon-
Ser
ial
schedul
i
ngt
over
if
ywhet
hert
heschedul
i
ngwi
l
lleadt
oany
i
nconsi
stencyornot
.

➢ Ont heot
herhand,
aserialschedul
edoesnotneedt
heserial
i
zabi
l
itybecausei
tfol
l
owsa
t
ransacti
ononl
ywhent heprevi
oustransact
ioni
scompl
ete.

➢Thenon-ser
ial
schedul
eissai
dtobeinaserial
i
zabl
eschedul
eonl
ywheni
tisequi
val
entt
othe
ser
ial
schedul
es,f
orannnumberoftr
ansact
ions.

➢ Aser
ial
i
zabl
eschedul
ehel
psi
nimpr
ovi
ngbot
hresour
ceut
il
izat
ionandCPUt
hroughput
.

Thesear
eoft
wot
ypes:
1.Conf
li
ctSer
ial
i
zabl
e:

@y
aredaa ki
myar
ed330@gmai
l
.com 16
✦Aschedul
eiscal
l
edconfl
ictseri
ali
zabl
eifi
tcanbet
ransf
ormedi
ntoaser
ial
schedul
eby
swappi
ngnon-
conf
li
cti
ngoperati
ons.

✦Twooper
ati
onsar
esai
dtobeconf
li
cti
ngi
fal
lcondi
ti
onssat
isf
y:

➢ Theybel
ongt
odi
ff
erentt
ransact
ions

➢Theyoper
ateont
hesamedat
ait
em

➢AtLeastoneoft
hem i
sawr
it
eoper
ati
on

2.Vi
ewSer
ial
i
zabl
e:
✦ASchedul ei
scal
l
edv
iewser
ial
i
zabl
eifi
tisv
iewequal
toaser
ial
schedul
e(noov
erl
appi
ng
t
ransact
ions).

✦Aconf
lictschedul
eisaviewseri
ali
zablebuti
ftheser
ial
i
zabi
l
itycont
ainsbl
i
ndwr
it
es,
thent
he
vi
ewser
iali
zabledoesnotconf
li
ctseri
ali
zabl
e.

B.Non-
Ser
ial
i
zabl
e:
✦ Thenon-
ser
ial
i
zabl
eschedul
eisdi
vi
dedi
ntot
wot
ypes,

✥ Recov
erabl
eand

✥Non-
recov
erabl
eSchedul
e.

1.Recov
erabl
eSchedul
e:
•Schedulesinwhichtransact
ionscommitonl
yaf
teral
ltr
ansact
ionswhosechangest
heyr
ead
commi tarecal
ledrecoverabl
eschedul
es.

T1 T2

R(
A)

W(
A)

W(
A)

R(
A)

Commi
t

Commi
t

Ther
ecanbet
hreet
ypesofr
ecov
erabl
eschedul
e:

A.Cascadi
ngSchedul
e:

@y
aredaa ki
myar
ed330@gmai
l
.com 17
➢Al
socal
l
edAv
oidscascadi
ngabor
ts/
rol
l
backs(
ACA)
.

➢ Whent herei
safailur
ei nonetr
ansacti
onandthi
sleadstother
oll
ingbackorabor
ti
ngot her
dependenttr
ansact
ions,thensuchscheduli
ngi
sref
erredtoasCascadi
ngroll
backorcascading
abort
.

T1 T2 T3

R(
A)

W(
A)

R(
A)

W(
A)

R(
A)

W(
A)

Abor
t Abor
t Abor
t

B.Cascadel
essSchedul
e:

➢Schedul
esi
nwhi
cht
ransact
ionsr
eadv
aluesonl
yaf
teral
ltr
ansact
ionswhosechangest
heyar
e
goi
ngt
oreadcommi
tar
ecal
l
edcascadel
essschedul
es.

➢Av
oidst
hatasi
ngl
etr
ansact
ionabor
tleadst
oaser
iesoft
ransact
ionr
oll
backs.

➢Ast rat
egytopr eventcascadi
ngabort
sistodi
sall
owatransact
ionf
rom r
eadi
nguncommi
tt
ed
changesfrom anothertr
ansacti
oninthesameschedul
e.

T1 T2

R(
A)

W(
A)

W(
A)

Commi
t

R(
A)

Commi
t

@y
aredaa ki
myar
ed330@gmai
l
.com 18
C.St
ri
ctSchedul
e:
•Ascheduleisstr
icti
fforanytwotransact
ionsTi,Tj
,ifawr
it
eoperat
ionofTiprecedesa
confl
ict
ingoper
ati
onofTj (ei
therr
eadorwr i
te)
,thenthecommitorabor
teventofTi al
sopr
ecedes
thatconfl
i
cti
ngoperati
onofTj .

T1 T2

R(
A)

W(
A)

W(
A)

R(
A)

Abor
t

Abor
t

2.Non-
Recov
erabl
eSchedul
e:

T1 T2

R(
A)

W(
A)

W(
A)

R(
A)

Commi
t

Abor
t

Not
e:I
tcanbeseent
hat
:

➛1.Cascadel
essschedul
esar
est
ri
ctert
hanr
ecov
erabl
eschedul
esorar
easubsetofr
ecov
erabl
e
schedul
es.

➛2.St r
ictschedulesar
est
ri
ctert
hancascadel
essschedul
esorar
easubsetof
cascadelessschedul
es.

➛3.Serialsati
sfyconst
rai
ntsofal
lrecov
erabl
e,cascadel
essandst
ri
ctschedul
esandhencei
sa
subsetofstri
ctschedul
es.

@y
aredaa ki
myar
ed330@gmai
l
.com 19
ReadMor
e

@y
aredaa ki
myar
ed330@gmai
l
.com 20

You might also like