0% found this document useful (0 votes)
55 views7 pages

SQL - Improvement Guide

SQL - Improvement Guide
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
0% found this document useful (0 votes)
55 views7 pages

SQL - Improvement Guide

SQL - Improvement Guide
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 7

Improvement Guide

Improve Stored Procedure Performance


Improvement Guide
Revision History
Author Revision Number Date
TCSASSEMBER 1.0 22/06/2014
Improvement Guide TopCoder, Inc. 2014 !"e 1 o# $
Improvement Guide
Improvement In%truction%
1. &r"!ni'!tion o# Su(mi%%ion
2. Improvement Tip%
). Re%ource Cont!ct *i%t
Improvement Guide TopCoder, Inc. 2014 !"e 2 o# $
Improvement Guide
1. Improvement Instructions
2. r!ani"ation of Submission
T+e %u(mi%%ion #o,,o-% director. %tructure provided (e,o-/
###R$AD%$###.t&t
Re!d #ir%t #i,e.
S'( ) Improvement Guide.doc
T+i% "uide t+!t .ou !re re!din"
S'($&ecutionP*an$&port.csv
S0* Server 2001 E2ecution ,!n e2port -+o% e%tim!te% !re (!%ed on %m!,, d!t!3#i,e -e +!d.
spSearchAna*yses+i&ed.s,*
Stored rocedure -it+ minor #i2e% unre,!ted to improvement o# per#orm!nce
-. Improvement .ips
Since t+ere i% not ! "ood te%t3d!t! c!%e to te%t m. !%%umption% 4%ince d!t! i% needed (. S0* E2ecution
,!nner to m!5e prediction% !(out +o- ,on" -i,, e2ecution o# %peci#ic t!%5% ,!%t6, +ere !re coup,e o# +int%
to t+e c,ient t+!t c!n +e,p t+em %o,ve t+eir pro(,em.
0.
T+e provided procedure +!% mi%t!5e% in it -+en !pp,ied to e2i%tin" code !nd -i,, not -or5 -it+ -+!t -e
-ere provided. I7ve m!de %ome minor correction% to #i2 t+i% !nd t+e %cript i% ,oc!ted/
spSearchAnalysesFixed.sql
1.
Inde2e% !re ver. import!nt 3 t+ere i% po%%i(i,it. t+!t %omet+in" i% not inde2ed !nd c!u%e% t+e e2ecution to
(e %,o-.
2.
T+i% ,oo5% %,o-/
AND (@invoice IS NU !" #$IS%S(S##&% ('( F"!) Invoice *+#"#
,Invoice-.,.ro/ect- 0 ,.ro/ect-.,.ro/ect- AND
,Invoice-.,&lient- 0 ,.ro/ect-.,&lient- AND
,Invoice-.,a1ID- 0 ,.ro/ect-.,a1ID- AND
,Invoice-.,Invoice- I2# 343 5 @invoice 5 343((
AND (@method IS NU !" @method 0 ,"#.SA).#ANA6SIS'-.,Speci7ic)ethod-(
3 It pro(!(,. -on7t u%e !n. inde2 (ec!u%e o# t+e &R !nd m!.(e t+e d.n!mic 8invoice !nd 8met+od !nd
it m!. (e runnin" t+e SE*ECT %t!tement repe!ted,. intern!,,. -it+ t+e 9oin. It i% !t ,e!%t comp,ic!ted !nd
,i5e,. to con#u%e .our ,o"ic no- or in #uture modi#ic!tion%. T+!t i%, (ot+ .our o-n de%i"n, !nd t+e ,o"ic o#
t+e :uer. p,!nner.
3 ;ou !re puttin" t+i% ,o"ic o# @varia1le IS NU into t+e :uer. it%e,#. I -ou,d (ui,d t+e :uer. d.n!mic!,,.,
c+ec5in" -+et+er @varia1le IS NU out%ide o# t+e :uer..
Improvement Guide TopCoder, Inc. 2014 !"e ) o# $
Improvement Guide
).
A,, ,i5e% -it+ pre#i2ed < !re %,o-.
4.
=+en e2ecutin" t+e procedure/
exec spSearchAnalyses
@pageNumber=1,@pageSize=10,@sortColumn=N'SampleDate',@sortAscening=N'N',@user
name=N'as!as!@test"com',@is#ecent=N'$',@%ey&or=N'((,@sampleDescription=N'((
,@sample)=N'((,@&or%*rer=N'((,@in+oice=N'((,@location)=N'((,@metho=N'((,@s
ampleDateStart=N'((,@sampleDate,n=N'((
-*
;ou c!n ri"+t c,ic5 in%ide t+e :uer. -indo- o# -+ere .ou !re e2ecutin" t+e procedure !nd c+o%e
Inc,ude Actu!, E2ecution ,!n !nd t+!n >i%p,!. E%tim!ted E2ecution ,!n/
Improvement Guide TopCoder, Inc. 2014 !"e 4 o# $
Improvement Guide
=+en .ou "et t+e e2ecution p,!n, .ou c!n +over over individu!, o(9ect%. !. !ttention to ?E%tim!ted
Su(tree Co%t@
A.
;ou c!n u%e t+i% :uer. to e2ecute t+e procedure !nd to "et co%t o# e2ecution p,!n in t!(,e #orm/
S,. S/*01(AN2A(( *N
-*
33 45.*N($ &ill not exec store proc
S,. 45.*N($ *N
-*
exec spSearchAnalyses
@pageNumber=1,@pageSize=10,@sortColumn=N'SampleDate',@sortAscening=N'N',@user
name=N'as!as!@test"com',@is#ecent=N'$',@%ey&or=N'((,@sampleDescription=N'((
,@sample)=N'((,@&or%*rer=N'((,@in+oice=N'((,@location)=N'((,@metho=N'((,@s
ampleDateStart=N'((,@sampleDate,n=N'((
-*
S,. 45.*N($ *44
-*
S,. S/*01(AN2A(( *44
-*
It -i,, ,oo5 ,i5e t+i% once e2ecuted 4p!. !ttention to t+e co,umn Tot!,Su(treCo%t6/
Improvement Guide TopCoder, Inc. 2014 !"e A o# $
Improvement Guide
And, !"!in, ! 5e. t+in" to c!,, out +ere i% t+!t t+e%e co%t% 4e%tim!ted or ot+er-i%e6 !re (!%ed on S0*
ServerB% 5no-,ed"e o# t+e %i'e o# .our t!(,e% !% -e,, !% t+e c!rdin!,it. !nd di%tri(ution o# .our d!t!. &r, in
ot+er -ord%, t+e%e co%t% !re (!%ed upon %t!ti%tic% !(out .our d!t!. T+e.Bre not, t+ere#ore, %omet+in"
Ct!n"i(,eB ,i5e t+e num(er o# mi,,i%econd% !%%oci!ted -it+ !n oper!tion. A% %uc+, t+e (e%t -!. to t+in5 o#
t+em i% t+!t ,o-er num(er% !re (etter D un,e%% .ou -!nt to tr. !nd "et into %ome o# t+e nitt.3"ritt. det!i,%
!(out +o- t+e%e co%t% !re c!,cu,!ted 4-+ic+, !"!in, i% propriet!r. in#orm!tion or p!rt o# S0* ServerB%
C%ecret %!uceB6.
=it+ t+!t %!id, t+ereB% %ti,, ! -!. to C#r!meB t+e%e co%t% D to provide !n ide! o# -+!t co%t% rou"+,. me!n in
t+e Cre!,B -or,d.
.//-. Co%t% o# .00) !re !(out !% optimi'ed !% .ouBre "oin" to "et -+en inter!ctin" -it+ t+e
%tor!"e en"ine 4e2ecutin" %ome #unction% or oper!tion% c!n/-i,, come in !t c+e!per co%t%, (ut IBm
t!,5in" +ere !(out #u,,3(,o-n d!t!3retriev!, oper!tion%6.
./-. &(viou%,., co%t% o# .0) !re ! #u,, order o# m!"nitude "re!ter t+!n %omet+in" -it+ ! co%t o# .
00) D (ut even t+e%e :uerie% !re t.pic!,,. "oin" to (e EER; e##icient !nd :uic5 D e2ecutin" in
,e%% t+!n ! %econd in t+e v!%t m!9orit. o# c!%e%.
0uerie% -it+ ! co%t o# 1 !renBt e2!ct,. u",. or p!in#u,, 4nece%%!ri,.6 !nd -i,, t.pic!,,. t!5e !
%econd or ,e%% to e2ecute. T+e.Bre not (urnin" up ,ot% o# re%ource%, (ut t+e.Bre !,%o t.pic!,,. not
!% optimi'ed !% t+e. cou,d (e 4or t+e. !re optimi'ed D (ut t+e.Bre pu,,in" (!c5 +u"e !mount% o#
d!t! or #i,terin" !"!in%t ver. ,!r"e t!(,e%6.
0. 0uerie% -it+ ! co%t "re!ter t+!n A, (. de#!u,t, -i,, (e e2ecuted -it+ ! p!r!,,e, p,!n D me!nin"
t+!t S0* Server %ee% t+e%e :uerie% !% (ein" ,!r"e enou"+ to t+ro- mu,tip,e
proce%%or%/core%/t+e!d%3o#3e2ecution !t D in order to %peed up e2ecution. And, i# .ouBve "ot !
Improvement Guide TopCoder, Inc. 2014 !"e 6 o# $
Improvement Guide
-e( %ite t+!tB% #irin" o## ! :uer. -it+ ! co%t o# A or more per ever. p!"e ,o!d, #or e2!mp,e, .ouB,,
pro(!(,. notice t+!t t+e p!"e C#ee,%B ! (it %,u""i%+ ,o!din" D m!.(e (. ! %econd or t-o D !%
comp!red to ! p!"e t+!t -ou,d C%prin" upB i# it -!% runnin" ! :uer. -it+ ! co%t o#, %!., .2 or ,o-er.
So, in ot+er -ord%, :uerie% up in t+i% r!n"e %t!rt +!vin" ! notice!(,e or !ppreci!(,e Cco%tB.
2/. 0uerie% in t+i% r!n"e !re T;ICA**; "oin" to (e %omet+in" .ou c!n notice t!5in" ! %econd
or %o. 4T+ou"+, on decent +!rd-!re, t+e. c!n %ti,, end up (ein" in%t!nt!neou% !% -e,, D %o even
!t t+i% point, t+in"% %ti,, depend on ! ,ot o# #!ctor%6.
2//. 0uerie% -it+ t+i% 5ind o# co%t %+ou,d re!,,. on,. (e #or ,!r"er report% !nd in#re:uent,.
e2ecuted oper!tion%. &r, t+e. mi"+t (e %eriou% c!ndid!te% #or t+e u%e o# !ddition!, tunin" !nd
t-e!5in" 4in term% o# code !nd/or inde2e%6.
1///. 0uerie% up in t+i% r!n"e !re -+!t >BA% %t!rt to ,ovin",. c!,, C:uerie% #rom +e,,B D t+ou"+ itB%
po%%i(,e to (ump into :uerie% -it+ co%t% in t+e 10% o# t+ou%!nd% or even more D dependin" upon
t+e oper!tion% (ein" e2ecuted !nd t+e !mount o# d!t! (ein" poured over.
1. Resource 2ontact (ist
Name Resource $mai*
TCSASSEMBER
Improvement Guide TopCoder, Inc. 2014 !"e $ o# $

You might also like