Tuning: Overview: Leccotech

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 29

Tuning: overview

Rewrite SQL (Leccotech) Create Index Redefine Main memory tructure (S!" in #rac$e) Change the %$oc& Si'e Materia$i'ed (iew ) *enorma$i'ation +x,ort-Im,ort (dro, indexe ): defragment Chec& Loc& Se,arate data .y category in ,ro,er ta.$e ,ace /artition *ata.a e Redundant "rray of Inex,en ive *i & (R"I*) Redefining C$ient0Server "rchitecture %uy 1ardware

2hen to Index
Large ta.$e " fie$d that you 3uery .y fre3uent$y 4ie$d with high cardina$ity (not ex where card5 I on$y 6) Sma$$er 4ie$d and 4ixed $ength are ,referred5 (#. :Mo t *%MS automatica$$y index /7)

*ifferent Ty,e of Indexe


%0Tree (traditiona$) indexe 1a h0c$u ter %itma, indexe Index0#rgani'ed Ta.$e Rever e07ey Indexe

Create Index command


Create index 8i9ame: on 8tname: (8co$;name:)< Create index cidx on order (cid)<

2hy do we create an index = (#LT/ x *ata 2arehou e)


") To ,eed u, 3uery (S+L+CT) = %) To ,eed u, data entry (in ert-u,date-de$ete) = C) "$$ of the a.ove =

Indexe (*efau$t )
"nytime a /7 i created) an index i automatica$$y created5 "nytime when the ty,e of index i not ,ecificied) the ty,e of index created i a %0Tree 5

%0Tree (%a$anced Tree)


Mo t ,o,u$ar ty,e of index tructure for any ,rogramming $anguage or data.a e5 2hen you don>t &now what to do) the .e t o,tion i u ua$$y a %0Tree5 They are f$exi.$e and ,erform we$$ (not very we$$) in evera$ cenario 5 It i rea$$y the %? tree or %@ tree

%0Tree (continued)
#ne node corre ,ond to one .$oc&-,age (minimum di & I0#)5 9on0Leaf node (n &ey ) n?A ,ointer ) Leaf09ode (contain n entrie ) where each entry ha an index and a ,ointer to a data .$oc&)5 "$ o) each node ha a ,ointer to next node5 "$$ $eave are at the ame height5

!ood Indexing (%0Tree) Candidate


Ta.$e mu t .e rea ona.$y $arge 4ie$d i 3ueried .y fre3uent$y 4ie$d ha a high cardina$ity (don>t index .y ex) where the cardina$ity i 6BB)5 %ad$y .a$anced tree may inhi.it ,erformance5 *e troying and re0creating index may im,rove ,erformance5

%itma, Index
%itma, indexe contain the &ey va$ue and a .itma, $i ting the va$ue of C or A (ye -no) for each row indicating whether the row contain that va$ue or not5 May .e a good o,tion for indexing fie$d that have $ow cardina$ity (o,,o ite of %0 tree )5

%itma, Index (cont5)


Syntax: Create Bitmap index . %itma, index wor& .etter with e3ua$ity te t = or in (not with < or > ) %itma, index maintenance can .e ex,en ive< an individua$ .it may not .e $oc&ed< a ing$e u,date $oc& a $arge ,ortion of index5 %itma, indexe are .e t in read0on$y datawarehou e ituation

1a h Indexing
%0tree and %itma, index &ey are u ed to find row re3uiring I-# to ,roce index 1a h get row with a &ey .a ed a$gorithm Row are tored .a ed on a ha hed va$ue Index i'e hou$d .e &nown at index creation +xam,$e:
D create index cidx on order (cid) ha hed<

1a h Index wor& .e t with


(ery0high cardina$ity co$umn #n$y e3ua$ (E) te t are u ed Index va$ue do not change 9um.er of row are &nown ahead of time

Index0#rgani'ed Ta.$e
Ta.$e data i incor,orated into the %0Tree u ing the /7 a the index5 Ta.$e data i a$way in order of /75 Many ort can .e avoided5 + ,ecia$$y u efu$ for F$oo&u,G ty,e ta.$e Index wor& .e t when there are few (and ma$$) co$umn in your ta.$e other than the /75

Rever e 7ey Indexe


7ey HA6IJ> .ecome HJI6A>) etc5 #n$y efficient for few cenario envo$ving ,ara$$e$ ,roce ing and a hughe amount of data5 %y rever ing &ey va$ue ) index .$oc& might .e more even$y di tri.uted reducing the $i&e$ihood of den e$y or ,ar e$y ,o,u$ated indexe 5

Conc$u ion on Indexe


4or high0cardina$ity &ey va$ue ) %0Tree indexe are u ua$$y .e t5 %0Tree wor& with a$$ ty,e of com,ari on and gracefu$$y hrin& and grow a ta.$e change 5 4or $ow cardina$ity read0on$y environment ) %itma, may .e a good o,tion5

Query #,timi'er
" 3uery o,timi'er ,ar er your SQL-Query into a e3uence of re$ationa$ a$ge.ra o,eration ) determining an execution ,$an5 The 3uery o,timi'er figure out the .e t execution ,$an .a ed on ru$e of thum. and information ,rovided in the *ata *ictionary (Sy tem cata$og)5

#rac$e Query #,timi'er


K, to ver ion L) #rac$e K ed a Ru$e %a ed #,timi'er5 "fter ver ion L) #rac$e offered the Co t %a ed and the Ru$e %a ed #,timi'er5 The defau$t i now the Co t %a ed #,timi'er5

Query #,timi'er
To view how the 3uery ,$an you mu t u e either set autotrace on or explain plan5 Set autotrace on i much im,$er5 +x,$ain ,$an i a $itt$e .it more efficient) .ut more com,$icated5

Ty,ica$ SQL o,eration (re u$t of autotrace)


T"%L+ "CC+SS 4KLL T"%L+ "CC+SS %M R#2I* I9*+N R"9!+ SC"9 I9*+N K9IQK+ SC"9 9+ST+* L##/S

TABLE ACCESS FULL ( ull ta!le scan"# #rac$e wi$$ $oo& at every row in the ta.$e to find the re3ue ted information5 Thi i u ua$$y the $owe t way to acce a ta.$e5

TABLE ACCESS B$ %&'() #rac$e wi$$ u e the R#2I* method to find a row in the ta.$e5 R#2I* i a ,ecia$ co$umn detai$ing an exact #rac$e .$oc& where the row can .e found5 Thi i the fa te t way to acce a ta.$e (fa ter than any index5 Le f$exi.$e than any index)5

(*)E+ %A*,E SCA* #rac$e wi$$ earch an index for a range of va$ue 5 K ua$$y) thi even occur when a range or .etween o,eration i ,ecified .y the 3uery or when on$y the $eading co$umn in a com,o ite index are ,ecified .y the where c$au e5 Can ,erform we$$ or ,oor$y) .a ed on the i'e of the range and the fragmentation of the index5)5

(*)E+ U*(-UE SCA* #rac$e wi$$ ,erform thi o,eration when the ta.$e> ,rimary &ey or a uni3ue &ey i ,art of the where c$au e5 Thi i the mo t efficient way to earch an index5

*ESTE) L&&.S Indicate that a Ooin o,eration i occurring5 Can ,erform we$$ or ,oor$y) de,ending on ,erformance on the index and ta.$e o,eration of the individua$ ta.$e .eing Ooined5

Tuning SQL and /L-SQL Querie


Sometime ) Same Query written more than ACCC way 5 !enerating more than ACC execution ,$an 5 Some firm have ,roduct that re0write correct$y written SQL 3uerie automatica$$y5

R#2I*
S+L+CT R#2I*) P I9T# :+M/;R#2I*) P 4R#M +M/ 21+R+ +M/5+M/;9# E QLR66 4#R K/*"T+< K/*"T+ +M/ S+T +M/59"M+ E P 21+R+ R#2I* E :+M/;R#2I*<

R#2I* (cont5)
4a te t Le 4$exi.$e "re very u efu$ for removing du,$icate of row

S+L+CT ST"T+M+9T
9ot exi t in ,$ace of 9#T I9 Soin in ,$ace of +xi t "void u.0 e$ect +xi t in ,$ace of di tinct K9I#9 in ,$ace of #R on an index co$umn 21+R+ in tead of #R*+R %M

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy