You are on page 1of 17

Jotnss

croSS- Preduct
as a
Cam be dettmed
A jotn
folloed by selecttoy a d projectto).
the follang
though
mplemented
Jotns can be

9ethcls

1 Simple Nested LeopJoLn

. Block Nested Loop Jot).

8. Index Nested Loop Jocn

4 Sovt- Mewae Jot).

SimpleNested Lcop JoL


tupe-at-d~
is a
jolo.algasitHm
* he Stmplest
evaluatto).
ttme e s t e d tcops

Algovithm

tuple e R do
do
for each

se S do
each tupe
for
the

add A,S > to TesuE


Block Nested lcop Joi
Nested lcop Joindces e t ettectiPly
The Simple

utilize bufter pdaes


memoTy
to ho te
we
haYe enougb
Suppose
ntH atleas t o
extra bu for
Say R,
SmclleY T e l a t t o m ,

Pages teft cves


e
read the Smalles zeIattonas
We caD
Tedic)
one of the extra.buHfer Paqes to Scan t h e lTaEr

and outPL
Se 5, he check R
fox each tupe
atuple 2i,s> for aualttving tupleso
s used anautpul
secome)
extra buffer page
The

buffOs

Algovithm

B -2 pages of R do
fov each bleck of
S do
foreach.page C

fov al.maichng
in-emoty tuNOS
Te R-bloce am SE S-

add <T, 5> to yasuE


T fisst tuple in
R,
T fxst tuple in S,
s fes tuple t n s ,

do
shile T+ec a G T
while s do

aftey 7a
Ta e 1t tudein R

while ;
Cas do

atler 9s
Gs-Deat tuple in S

T s
a0
kobiie T 9s;

ohile Ts. T,. do


do

add 4T,T> to Teut


, s n e a t tuple in S afta t
3,A 14 next tuple .tn R atter Ts
Indexed Nested Loep

is
a l e y cn ene ot the elatrcs5
thee
If
JOin athibutet6),
ttel6), we cor tCKe odvoytof*
on the
3mari9
toBENed Teatton bet e
the index by
er dNS
pos Ne have a Guitoble

DnY elatto). supp

AlgovitHm

each uple Ae R do
for
whee sS
each tuple s e S
fov
add A,6> to TeSu

Sovt Mexqe Join


jo)
behind h e sest-merqe
The basic idea
Onthe joU)
both v e l a t t a n s
algorithm is t o Sert
Y ER
tupaS
10ok for oyualitYing
attruto a nd t h e n

aro sES by eseenttally mappin9neho TAatreG

Alacrithm:

Scst merge join K,S)

on
atrdbu
be , Sostt .
7ot Sosted
If S at t
on
attrubU e J,
sorted
t S is t
fapao
a k o d u a )
ooholusa
nooV| 3aban
nuruDo
AaMÓuoq)
amoD
AanGQDO) a s n ) PaSno
posaasnD)
unou auhad) aA)
daao aamsno )
o R q u a u s h a l )
AeqLof uanboga d-a
estios
Quey optimi2attc)
frCCOSS 4
cverall
the
is
uesy ptimizatrem
T c a n S o e o l u t i r g

choosÜg the most ettiient

SQL StatameN optirmi


20tto)
in queoy
The compoments ivolVed

ase
ueTy Parsos
.QueTy Optcmi2Er
.3. ueY Plan Evatuatoo -
iOY
the gtven
Tt
Puesy pavses -
parses

cesmpcrS
tuo
comp+Ses of
It
-
uesy opttmizos
uesy plan GeTOTatos

EStJats
ccet Gee
uesy plan

uesy PlaD Generator:


p a n s f¢
ditfevent
t g e m e r a t e S .

exectton ot tHe OYLOTY

ccet Eetiya tor"


uesy PlaS

the COBtef e a h
t o s t l n a t o s

t e yuOsy.
e x e t i o n plCDAL
8. ueTY Plan Evaluato
evaluartt9
the best plam teT
Tt select

the uOTY

ueTy

uesy Pase

Porsec uesy

u e T y optimicOO.

ueTY catalcg
Ques plaxnccest
Pam
Estimatoo|| maroggs
Generator

Evaluaticn pa)

Quey pan EVa{uao

Quesy porsing.optim2atiorm oaTd E&ecttoo)

u e r y Evaluation PlanD-

plam
cocmSists of a n extenmkd
e v a l Uaticn
A yueTy
amDotations
addittoal

Telattonal algebra tree withb toOHO


Tethds
aceeS
irdicattmth9
t each de. vsai to
i m p i o r m e n t a t t oo
ech tabie and the

uch 7alatoral opeattt


SQL Que
SELECTT S.6Tame
FROM Reseves S
R 6alo
HERE R-sid s.cid ano

a S ratirg >
bd tco

Receves DKi Saia


sid SiH
bid =loco ottrg>5
SnantE
Relatioal alge bra expveeACn.

Samee

bid = tcOATattng>5

Relatioal

algebra-tKO

A (Sinple Nesled

sidsid tcopji

ScaTlor
Rese Ves

Quesy Evaluatton plaD-|


Sname

Sost- Mev joir)

Sid 6 d

atig5

ReseveS SlorS

QuoTy EVaLuatior plm-2

Sname

atim >S

Ilea esledtcops
Stl Sid

sotxsHashinreon
bid =1co
sid

PeseeS

uey ENaluation Na-3.


Ccet of a plam

Sum a} C otsS
COstS
Surr a
The ccet oi a
the
plan te

fos the tors it ContaisS


i s tteo
broto) dan 2 o
daan
BTOKON

be
The Cost e a a plam coan

tmsee pasts
tades
Readtg the Imat
tobes
iate
. IteT ryed
3. Sosttmg tho tenal TOSU
Eauivalence Rules

t h a t exproS[ONs
Am eauivalence rule says

two forms are eouvalenE.

E)= (%,(¬))

E ) ) - (o,(E))
3 TT (TT Lo . CE))-) T(e)
LI

5 E ) =
E, D4E

E, E

(A E ) E E,M (ED4 E )

E, U E E0 E

E,0 E , 5, 1E

(E 0E ) VE
=
E, U(EUEz

Eo,0 E3) , EE)


1. E,U E)
=
EU (E)
T,EU Ea) E) U TLE)
Cstimating Statisttcs of Expression Results
on t h e sL2e
The coSE OF an operatiom deperds
StatiStics of lts inputS.
and oheY

DBMS Catalo

Stat+sttcal
The DEBMS catalog Stcres the followinq
relations
about database
infomation
A
The number ot tupleS in the r e l a t C

containing tuples
of relabio)
The number of bicckS

& in bybeS
Aa- Tthe size of a tuple ot relatton
that fit rto
relation s
The n m b e r of tuples of
+
one b l .

distinct values trat appear in the


V(A,A)
-
The mumber of
relattom A for attrtbue A

Selecticm Size Estimatiom

() LEquality predêcate
A a

unitorm
dtsbibution
of valuoS,the
assume
If We
estimated
t o ave
resut can
be
Selection

tupes
V(A4)
attribute A ot
value a aPPeas n
t h a t the
assuming

Some secod G .
A ) L Single Comparison preliccre
A
min(A,A)- lowest valuo of

max( A, A) -

hiqhest valuo A
tut
relos
numbox ot
T V min[ A, 4) then the

Satiefy E e
coelttto) is o
tatE
T e c o r d s

t h e number ofi
Tf V max( A,«) them
c o n d i t i o n is n
SatistY h e

T e s u l t tS
Then the selection

i o t O Y COSOs
V- min(A,A)

max (A, 6)- minlA,C)

Conjunctive selection
is a selectton ci t h
Select+cn
A Coniunctive

fosm
A)
, AO, A - O
- -

s
Selectton .) s;
for each O;, the si2e of

tD tHe full
Selectton ts esttmatey
The number o tuples

as
Disjunctiye Selection:

A dsjuctuve Selection is a select+on tre os

vO,v -V,
tull Seloctton is esti0te
The umbey Of tuples in he

as

(S
- ()*(1-
5 Nogattor

-(
Join Si2e Estimatio0

be relations.
Let TR) and s(S)

estimatton
s s0O
k ' S

=9
then the joisn size
ie.
d6 C a t e s i a m pracduct
umber Of t
then tne
Tf ROS is a key tor R

tupleS in S5.
nRM S is tne nu mber
numberet
tuplS
hen the
is a key for S,
tRns
)*.
uplos
number of
RDA 5 is t h e
3
R ad s e).
to
a key for
ROS is neithe
8 nR DM S ts
tuplos
the
umbOr o
s

minimum
VCA,S vlA,K)
Roectio:
The b2e ofa pnejectiom T (4) s VA, ¢ )
A

Set cperat+ons:

is tne Sum 4
US
The estima bed si2e cf

ad s.
the s i z e s of s minimu
s is t h e
eStümated size of
The

t h e si20S of R ad s.
a toSi2e94

s eorial
The e6timated si2e o t - s

Let ouHer joun


sizeli
Si2e AS) = ods) +
Sce

Right Cuter Join

= Size( A AS) + st2els


DES)
size

full outer Jo)

Size(A WS)
+ Szel1) t S2e Cs)
Siae (A I S)
u e y Optimiaatior

the
Quey optismiaation te the prece6s otchoosing
most efilient oyueTy evaluaticm plans for exeæuti9

the yuesy

There are t o o methods of Quesy ©ptimi2atio.

I Cost-based uesy optimizatton. CcB)


. Rule-based Quesy optit2atton .( RBo

Cost components of quesy Executton:-

Access coSt to seconday Storoge


Seachêng,eading
bis can be t h e ccst of
c)
data blocks t n a t ave originally fond
Wsttin9
o n h e dise
Secodary Storaqe especially
CoSE
. Memory Usage
can b e Calcultted
T h e coSt smemory usage
of
of memory BufOrS that
the mumbe
Simply by usnq
seneecle or the
execution of theyueTy

8. Storage CoSSt
inbersediatottles

I t is the cost of Stort ng any

ave qenerated by tDe


that
FProcessim the iopuE
Osy
Stategy GtHe
.

ekecution

Computatiomal Cc
tho 7emosY
t S the coet of pe7for ming
a e avaulable od
Ee Tecord otthia
operations t h a t hin
t h edata b4faS
Cosmuneat+on
coSt -
5.

T ts the ccet aeeee tated oith Sending O

Communicatl3 the Yuesy and tts resultS trom One


place t o a n o t h o s

Cost-based qptismizev-

A Cost-based optimiz generates a 7ang

Yueoy-evaluatton plans from the given qucTy bY using

the eayuivaleco sules

Rule-basel optümcze

t S e l e c t s the etiuent aucay eValuattoM pla)


based on sules .

Rule-l pexfov Selectton operatton eorsy.

Pestonm pgecticm oparatton


aATly.
Rule-9:

Cartesian paccUCt
Rule-3 : Avoid

You might also like