You are on page 1of 43

SybaseASE15BestPractices:

QueryProcessing&Optimization
TECHNI CAL WHI TE PAPER
www.sybase.com

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
1

Contents
ExecutiveSummary...................................................................................................................................3
HistoricalOverview................................................................................................................................................3
What'sNewwiththeASE15OptimizerandQueryProcessingEngine.................................................................4
UnderstandingASE15'sQueryProcessing...............................................................................................5
Whatisanoptimizationgoal?...............................................................................................................................5
Optimizationcriteria..............................................................................................................................................6
Choosingthebestoptimizationgoalforyourapplication....................................................................................6
Experimentingwithoptimizationgoals.................................................................................................................7
Howtosetsessionleveloptimizationgoals..........................................................................................................8
ParallelqueryprocessinginASE15.......................................................................................................................8
Performancemonitoringtips................................................................................................................................9
Troubleshootingtips..............................................................................................................................................9
Using'CompatibilityMode'inASE15.0.3ESD#1................................................................................................12
Ifallelsefails.....................................................................................................................................................12
ObsoleteoptimizationcommandsinASE15.......................................................................................................13
ResourceRecommendationsforASE15.................................................................................................14
Procedurecache..................................................................................................................................................14
Procedurecacheusagelimitationin15.0.2ESD#2.............................................................................................14
OtherresourceusageaspectsofASE15.............................................................................................................15
StatisticsInASE15..................................................................................................................................16
WhystatisticsmatterespeciallyinASE15........................................................................................................16
Recommendation:runupdateindexstatistics....................................................................................................16
Using'sampling'withupdateindexstatistics......................................................................................................16
Speedingupupdatestatisticswithparallelism...................................................................................................17
Whentorunupdatestatistics?...........................................................................................................................17
Howmanyhistogramsteps?...............................................................................................................................18
Identifyingmissingstatistics................................................................................................................................20
OldstatisticsandupgradingtoASE15................................................................................................................20
Summaryofrecommendationsforstatistics.......................................................................................................21
RecommendedTestingBeforeUpgradingToASE15.............................................................................22
Whyshouldyoutest?..........................................................................................................................................22
Pleasenote.......................................................................................................................................................23
UsingCompatibilityMode...................................................................................................................................23
Identifyingqueriesthatrunslower.....................................................................................................................23
AnalyzingperformancedifferencesbetweenASE12.xandASE15....................................................................23
Analyzingshortdurationqueries........................................................................................................................26
Serverlevelperformanceaspects.......................................................................................................................26
ExampleOfASE15QueryPlanAndLavaTree........................................................................................27
ASE15QueryPlans..............................................................................................................................................27
Example:setshowplan........................................................................................................................................27
Example:plancostandLavaTree........................................................................................................................30
CapturingApplicationSQL.......................................................................................................................32

2
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

Auditing...............................................................................................................................................................32
MDAtables(12.5.0.3)..........................................................................................................................................32
ApplicationTracing(15.0.2).................................................................................................................................33
AbstractPlanCapture/QueryMetricsCapture...................................................................................................34
InformationToCaptureBeforeContactingSybaseTechSupport...........................................................35
701Errors............................................................................................................................................................35
PerformanceProblemwithaLimitedNumberofQueries..................................................................................36
SystemWidePerformanceProblemsorHighCPUUsage:step1.......................................................................37
SystemWidePerformanceProblemsorHighCPUUsage:step2.......................................................................38
UploadingdiagnosticstoSybaseTechSupportthroughFTP...............................................................................39
ConclusionsAndRecommendations.......................................................................................................40
ReferenceDocuments.............................................................................................................................41

Principalauthor
RobVerschoor

Contributingauthors
SudiptoChowdhuri
BillCox
MarkKusma
NitinSadalgekar
PeterThawley
RaymundoTorres
NingzhenZhu

RevisionHistory
Version1.0 February2008 Firstversion
Version1.1 May2009 CoverCompatibilityModein15.0.3ESD#1;also,minorediting.

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
3

ExecutiveSummary

HistoricalOverview
WhenSybasefirstbegantodesignitsrelationaldatabasemanagementsystemin1984,theworldofInformation
Technology(IT)wasradicallydifferentapplicationsweremonolithicwithdataaccesscodeandbusinesslogic
tightlybound;transactionprocessing(OLTP)waspredominatelyabatchprocess;anddecisionsupport(DSS)
reportingnever,ever,ranatthesametimeastransactionprocessing.Sybase'spioneeringconceptofclient/server
computingwasbasedontwosimpleideas.First,manybusinessescouldofferbetterserviceandvaluetotheir
customersiftransactionprocessingweredone"online".Second,businessescouldservicetheircustomersbetter,
andthereforegrowfaster,bydecentralizingapplicationdevelopmentandnotusingthemainframe.Toenablethis
radicalapproach,Sybasehadtodesignandbuildasubstantiallydifferenttypeofdatabasekerneltosupportthis
new"onlineenterprise".
SybaseAdaptiveServerEnterprise(i.e.,theproductformerlyknownastheSybaseSQLServer)becametheleading
RDBMSproductforhighperformancetransactionprocessingsupportinglargenumbersofclientapplication
connectionsonrelativelysmall,inexpensivehardware.Tobesuccessfulinthisdemandingarea,Sybasefocused
heavilytooptimizeandstreamlineallthelayersofourdatabaseenginefortransactionprocessingworkloads.
WhilethisfocusturnedouttobetheassetthatcatapultedSybasetoadominantpositioninhighendOLTP
applicationsduringthe1990's,itincreasinglybecamealiabilityinsomeenvironmentsasapplicationworkloads
havechangedandhardwareperformancehasincreased.
Withmoreandmoreenterprisesrequiringamixtureofbothtransactionprocessingandoperationaldecision
supportreportingonthesamedataatthesametime,itbecameclearthatSybaseneededtorearchitectitsquery
processinglayerforthefuture.Sybasebegantheprocessinthe11.9.2releasewhenwerearchitectedthe
"bottomhalf"ofthequeryoptimizerthatdealtwiththestatisticsandalgorithmsthatdrivequerycosting.We
thenembarkeduponasignificantefforttoreplacethetophalfoftheoptimizerandthequeryexecutionlayerwith
onethatcouldmeetthenextgenerationofapplicationrequirements.Equallyimportant,weneededittobemore
extensiblesothatinthefuture,wecouldaddsupportfornewindextypesornewjoinstrategiestomorequickly
respondtotheneedsofourcustomers.WithASE15,Sybasehasdeliveredthis.
Withthishistoricalcontextinmind,itisimportantforcustomersandpartnerswhoarelookingtoleveragethe
manybenefitsofASE15.0.xunderstandthesignificanceofthesechanges.Agoodanalogyforhowtoapproach
thiseffortisjustlikebreakingintheengineonyournewcar.Shouldyouwinduptheengine'sRPMstothatred
lineandcruiseyourfavoritewindingbackroadat100mph?Asmuchassomeofuswouldliketosayyes,Isuspect
mostofusknowtherightanswer.Well,usingthenewASE15queryoptimizerandqueryexecutionissimilargo
slowerthanyou(oryourboss)wants,learntheimportantcharacteristicsofthesystem,andknowwhattodoin
casetheredlightcomeson.Thisdocumentismeanttohelpyouwiththeselasttwo!

4
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

What'sNewwiththeASE15OptimizerandQueryProcessingEngine
ThefirstandmostimportantthingtoknowaboutASE15'squeryoptimizerandqueryexecutionengineisthatit's
basicallytotallynew.Theshiftinrequirementsovertheyearstowardsmixedworkloads(i.e.,concurrentOLTPand
DSSapplicationprofiles)stretchedourtraditionalrelationalprocessingmethodsof"nestedloop"joinstotheir
breakingpoint.Ifyouconsiderthefactthatitisnowcommontoseequeriesjoiningten'softableswithmany
complexsearchargumentsand/oraggregation,itwasclearthatboththequeryoptimizerandthequeryexecution
engineneededamajoroverhaul.Moreimportantly,weneededtodesignasolutiontoensureboththeoptimizer
andexecutionenginewouldbeextensible.Thisallowsustoaddnewandinnovativealgorithms(forjoining,
grouping,union,etc)andstoragestructures(e.g.indextypes)moreeasilywithoutkludgingexistingcodeand
makingitunmanageableorerrorprone.Tofacilitatethemodularityandextensibilityofthequeryexecution
engine,wehaverebuilttheexecutionengineusingamoremodern,consumerdriven,iteratorbasedexecution
model.Thismodelimplementsrelationaloperatorsasprimitivebuildingblocksandprovidesboththeabilityto
easilysolvenagginglimitationsaswellasaddimportantnewjoinstrategiesandoptimizations.Beforewegetinto
thedetailsofhowtouseandtroubleshootthenewoptimizerandqueryprocessingengine,let'sfirstgainan
understandingofthemajorchangeswhichaffectbothapplicationsandoperations.
LongtimeASEcustomerswillappreciatetheeliminationoflimitationswhichallofushavesufferedthrough.Over
theyears,Sybasehassteadilybeenreducingtheoccurrenceswhendatatypemismatcheswouldpreventa
predicatefrombeingconsideredduringoptimization.Unfortunately,oureffortswere"hardwired"sowehadto
addspecialcasecodeforeachandeverycase.Althoughnot"rocketscience",itwasaresourceintensive
approachthatdidnotscaleasweaddednewdatatypes.Moreinterestingly,howmanytimeshaveyouwished
theoptimizerandQPenginecouldusemultipleindexesonatablethroughindex"union"or"intersection"
operations?Well,wishnomore!Now,querieswithANDand/orORpredicatescanpotentiallyusemultiple
differentindexesbasedondatadistributionstatistics'estimatedselectivityforeachpredicate.
Howaboutthedilemmawefacedinthepastwithoptimizationofqueriesthatjoinedlargenumbersoftables
resultedina"lessthanstellar"queryplanduetojoincostingthatdidnotuserealdatadistributionstatistics
(histograms)butrather"magicnumbers"fromourengineer'sheads?Now,statisticsforjoins,bothtoderivejoin
orderaswellastofeedmoreaccuraterowestimatesintocostingofinnertablesofthejoinorder,shouldbemore
accuratebecausewedynamicallycreatejoinhistogramsatoptimizationtime.
Whyisallthisimportant?Well,franklyspeaking,it'stoensurethatyoudon'ttreatASE15as"justanother
release".Asmuchaswewouldliketosaythatyoucouldsimplyupgradeandpointyourapplicationsatthe
upgradedservers,thedepthandbreadthofchangeinoneofthemostfundamentalareasofadatabase,query
execution,necessitatesamorefocusedtestingregimen.Thispaperismeanttoprovideyouwiththeclearfacts
andbestpracticestoreducethiseffortasmuchaspracticallypossible.

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
5

UnderstandingASE15'sQueryProcessing

Whatisanoptimizationgoal?
AcentralconceptofASE15'snewqueryprocessingengineisthe'optimizationgoal'.Inessence,thiscanbeseen
asahinttotheASEqueryoptimizer,providinganindicationofthenatureofthequerybeingoptimized.To
illustratetheunderlyingidea,atypicalOLTPqueryandatypicalDSSquerywillnormallyendupwithverydifferent
queryplansduetothedifferentdataaccesspatternsusedbythesequeries.OLTPqueriestendtohitoneorjust
veryfewrows,andjoinonlyafewwellindexedtables;DSStypicallyhitsmanyrowsbutreturnsjustafew,andcan
joinalargenumberoftables.
Becauseoftheirdifferentaccesspatterns,OLTPquerieswilloftenperformbestwhentheyuseaclassicnested
loopjoinwhereasaDSSqueryismorelikelytorunfasterwithahashjoin.ByindicatingthataqueryisforOLTPor
DSSpurposes,theoptimizermaysaveitselfalotofwork(time,memory,CPU)whengeneratingaqueryplan.
ASE15providesthreeoptimizationgoals(orderedfrom'narrow'to'wide',correspondingtothenumberofoptions
andstrategiestheyallowtheoptimizertoconsider):
allrows_oltp (bestforOLTPqueries)
allrows_mix (defaultafterupgradingtoASE15)
allrows_dss (bestforDSSqueries)

ThedifferentoptimizationgoalshavethefollowingeffectontheASEqueryoptimizer:
allrows_oltpoffersthenarrowestselectionofjoinmethods:thequeryoptimizerisallowedtoconsider
nestedloopjoinsonly
allrows_mixallowsalsomergejoinstobeconsideredbytheoptimizer,aswellasparallelplans(iftheASE
serverisconfiguredforparallelism).
allrows_dssoffersthewidestselectionofjoinmethods:alsohashjoinsmaybeconsideredbythe
optimizer

Forallrows_mixandallrows_dss,additionallowlevelprocessingalgorithmsareenabledwhicharedisabledfor
allrows_oltp.
Itshouldbenotedthatwhentheoptimizationgoaliswidened,thequeryoptimizermightusesignificantlymore
resources(timeandprocedurecache)togenerateaqueryplan.Iftheoptimizergeneratesthesamequeryplan,
withonlynestedloopjoins,underallrows_dssandallrows_oltp,youshouldexpecttheoptimizationunder
allrows_dsstotakemoretimeandprocedurecachethanunderallrows_oltp.
TheoptimizationgoalcanbedefinedontheleveloftheASEserver,sessionorindividualquery:

- - ser ver - wi de def aul t :
sp_conf i gur e ' opt i mi zat i on goal ' , 0, ' al l r ows_dss'

- - sessi on- l evel set t i ng ( over r i des ser ver - wi de set t i ng) :
set pl an opt goal al l r ows_dss

- - quer y- l evel set t i ng ( over r i des ser ver - wi de and
- - sessi on- l evel set t i ngs) :
sel ect * f r omT1, T2 wher e T1. a = T2. b

6
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

pl an ' ( use opt goal al l r ows_dss) '



Thesessionleveloptimizationgoalcanalsobesetinalogintrigger;seepage8formoreinformation.
Optimizationcriteria
Anoptimizationgoalisactuallyshorthandforacollectionofon/offsettingsforaseriesofpropertiesknownas
'optimizationcriteria'.Individually,anoptimizationcriterionallows(whenitisenabled)ordisallows(when
disabled)theoptimizertoconsideraparticularalgorithm(asforaccessmethods,forjoins,forgrouping,sorting,
etc.).Someexamplesofoptimizationcriteriaare:

set hash_j oi n on - - enabl es hash j oi ns


set st or e_i ndex of f - - di sabl es r ef or mat t i ng

NotethatSybasedoesnotrecommendusingexplicitsettingsforoptimizationcriteriaunlessadvisedbySybase
TechnicalSupport,oraspartofatroubleshootingprocess.Inproductioncode,Sybaserecommendsusing
optimizationgoalsinsteadunlessadviseddifferentlybyTechnicalSupport.
Choosingthebestoptimizationgoalforyourapplication
Thechoiceofoptimizationgoalcanhaveabigimpactontheperformanceofyourqueries.Therefore,two
importantquestionsmustbeansweredwhenupgradingtoASE15:
1. Whichoptimizationgoalshouldbesetserverwide?
2. Isitnecessarytospecifysessionorqueryleveloptimizationgoalsthataredifferentfromtheserverwide
setting?
Sinceitshouldbeconsideredunfeasibletoanalyzeallqueriesinyoursystem,apragmaticapproachshouldbe
takentowardstheseissues.Pleasenotethatblindlysettingtheserverwideoptimizationgoaltoal l r ows_dss
(sinceitisthewidestoptimizationgoal)isnotrecommendsincethismayconsumemoreresources,including
compilationtime,thanneeded.Itisworthtryingtodetermineifanarroweroptimizationgoalwilldo.
Asforthechoiceoftheserverwideoptimizationgoal,twoapproachescanbedistinguished:
A. Picktheoptimizationgoalthatprovidesthebestoverallperformanceforyoursystem.
Thisshouldbesetsothatitmatchesthetypeofworkloadofthemajorityofyourqueries.Ifyouhavea
pureOLTPorpureDSSsystem,thenitisobviouswhichoptimizationgoaltopick.
Ideally,youshouldexperimentwiththedifferentoptimizationgoalstoseewhichoneprovidesbest
resultsforyourmixofapplicationsandqueries.Seethesection"Experimentingwithoptimizationgoals"
forsomesuggestions.

B. Justsettheserverwideoptimizationgoaltoal l r ows_ol t pforthesimplereasonthatthis


optimizationgoalresemblesthebehaviourofASE12.xmostclosely.Thiswillreducethepossibilityof
runningintounexpectedqueryplanissuesafterupgradingtoASE15,butmayalsonotletyoubenefit
fromthefullpotentialofASE15'scapabilities.

Thesecondissue(theneedforsessionorqueryspecificoptimizationgoalsettings)mayrequiremorework.
Whenyouknowthatcertainapplicationshavedifferentworkloadcharacteristicsthantherestofyoursystem,for
example,someOLTPworkloadinamostlyDSSsystem,thenitmaybeagoodideatosettheappropriatesession
leveloptimizationgoalforthatapplication.Inthisexample,thatwouldmeantheserverwideoptimizationgoal
wouldbesettoal l r ows_dsswhilethesessionleveloptimizationgoalwouldbesettoal l r ows_ol t p.

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
7

Notethatthiscanquicklybecomeanopenendedundertaking:thereisalmostnolimitontheamountofeffort
youcanspendonanalyzingyourqueriesandderivingthebestoptimizationgoalsettingforasessionoran
individualquery.Asalways,youhavetostrikeabalancebetweenperformancegainsandeffortspentwhen
engaginginperformancetuning.
Experimentingwithoptimizationgoals
Asexplainedabove,youneedtopickanoptimizationgoaltosetasyourserverwidedefault.Theeasiestapproach
isjusttopickone,seehowthingsbehaveoverall,andtryanotheronetoseeifthat'sanybetter.Whenusing
storedprocedures,makesuretorunsp_r ecompi l eonalltables,orrebootASE,afterchangingtheserverwide
optimizationgoalinordertomakeittakeeffectbyrecompilingexistingplans.Also,makesurethestatement
cacheisdisabledtogetagoodcomparison.
Whilethisapproachmaywork,itisperhapsagoodideatomakeamoreinformeddecisionabouttheoptimization
goaltouse.Fortunately,thisisnottoodifficult.First,youneedtocollectorcapturearepresentativesetofreal
lifeSQLqueries,forexample,throughtheMDAtables,orwithauditingorMonitorServer(forsomesuggestions,
seepage32).Putallthesequeriesinafileasseparatebatches,with'go'toterminateeverybatch,justasyou'ddo
whenusingi sql .Then,putthefollowingatthestartofthefile:

set pl an opt goal al l r ows_ol t p


go
set showpl an on
set st at i st i cs t i me, i o on
go
r est of f i l e

Nowrunthisfilethroughisqlandcapturetheoutputinanotherfile:

i sql - U user name - P passwd - S YOUR_15_SERVER - e - i your _f i l e > out put _f i l e

Timehowlongittakesbeforetherunhascompleted.
Repeatthiswiththeoptimizationgoalabovechangedtoal l r ows_mi xandal l r ows_dss,sothatyouhave
threeoutputfilesofqueryplanoutput.
Fromthecompletiontimesofthedifferentruns,itmaybeimmediatelyapparentwhichoptimizationgoalprovides
thebestresultoverall,andthatmightbeacandidatefortheserverwideoptimizationgoalsetting.
However,itwillbeinterestingtocounthowmanytimeseachjointypehasbeenchosen.Thiscanbedonequickly
withgr epforeachoftheoutputfiles:

gr ep - c " NESTED LOOP J OI N" <f i l ename>


gr ep - c " MERGE J OI N" <f i l ename>
gr ep - c " HASH J OI N" <f i l ename>

Supposethereappeartobejustafewhashjoinsusedwhentheoptimizationgoalwassettoal l r ows_dss.For
thequeriesusingahashjoin,itwouldbeworthcheckingiftheyranmuchslowerwiththeotheroptimization
goals.Withtheapproachabove,thiswillberelativelyeasytocomparesinceset st at i st i cs t i mewas
enabled,theelapsedtimeforeachquerywillbeintheoutputfile.Ifitturnsoutthat,forthosespecificqueries,

8
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

hashjoinsmakeabigdifferenceindeed,youcouldconsidersettingthesessionspecific,orevenqueryspecific,
optimizationgoalforthosequeriestoal l r ows_dss.If,ontheotherhand,thereappeartobemanyqueries
usingahashjoin,andallrows_dssturnsouttoprovideverygoodperformanceoverall,perhapsitisbettertoset
theserverwidegoaltoal l r ows_dssinstead.
Withthisapproach,itisrelativelyeasytogetanideaoftheimpactofusingdifferentoptimizationgoals.Ofcourse,
thequalityoftheresultsdependsonhowrepresentativethesampledqueriesare.
Whenrunningtestslikethese,makesurethestatementcacheisdisabled(eitherbysettingtheconfiguration
parameter" st at ement cache si ze" to0,orbyrunningset st at ement _cache of f atthestartof
yoursession).Also,whenusingstoredproceduresbeforererunningwithadifferentoptimizationgoal,run
sp_r ecompi l eonalltables,orrebootASE,afterchangingtheserverwideoptimizationgoalsoastomakesure
thenewgoaltakeseffect.
Whencomparingperformanceofqueriesunderdifferentoptimizationgoals,especiallywhenarebootisinvolved,
makesuretotestundercomparablesituationswithrespecttodatacacheusage.Itdoesnotmakesenseto
compareaquerywheremostdataneedstobereadfromdisk,withaquerywheremostdataisalreadyinthedata
cache.Ingeneral,itisbesttocomparequerieswitha'warmcache',wherebythequeryisrunonceortwice
withoutmeasuringitsperformance,followedbythefinalmeasurementrun.
Howtosetsessionleveloptimizationgoals
Let'sassumeyouhavedeterminedthataparticularapplicationwouldbenefitfromusingal l r ows_mi xwhile
theserverwidegoalissettoal l r ows_ol t p.Howdoyouimplementthis?Initssimplestform,youmodifythe
applicationtomakeitexecutethestatementset pl an opt goal al l r ows_mi xbeforesubmittingany
otherstatements.However,itmaynotbepossible,orimpractical,tomodifytheSQLcodesubmittedbyan
existingapplication.
Fortunately,thereisaneasysolution:youcansetthesessionleveloptimizationgoalinalogintriggerwithset
pl an opt goal .Thisway,theoptimizationgoalforasessioncanbesetasdesired,withoutchangingany
existingapplicationcode.PleaserefertotheASESystemAdministrationGuideformoreinformationaboutlogin
triggers:chapter"ManagingUserPermissions",section"Rowlevelaccesscontrol",subsection"Usinglogin
triggers"(thoughpleasenotethatlogintriggerscanbeandusuallyareusedindependentlyofrowlevelaccess
control,asisindeedthecaseforsettingsessionleveloptimizationgoalasdescribedabove).
ParallelqueryprocessinginASE15
Sinceversion11.5,ASEhassupportedintraqueryparallelism,wherebyasinglequeryisprocessedbymultiple
workerprocesses.ManySybasecustomershaveusedparallelism,usuallytoimproveresponsetimesforDSStype
queries.Forthistypeofquery,wherealargenumberofrowsareaccessedbutonlyasmallresultsetisreturned,
parallelismtendstobemostefficientinpre15.0.Parallelqueryprocessingtendstorequiresignificantlymore
resources(CPU,memory,diskI/O)thanserialprocessing,butwhensuchresourcesareavailableparallelismmay
deliverbetterperformanceforspecificqueries.
ASE15alsosupportsparallelism,butinadifferentwaythanpre15versions.Withoutgoingintotoomanydetails
thatwouldexceedthescopeofthisdocument,insummarywecansaythatparallelisminASE15canoccurat
morelevelsinsideaquerythaninpre15.Inaddition,parallelisminASE15isdesignedforuseinconjunctionwith
semanticallypartitionedtables,whichpre15didnotsupport.
SincethenewqueryprocessingfeaturesofASE15offerpotentialperformancebenefitsforDSStypequeriesin
particular,SybaserecommendstoinitiallynotuseparallelprocessingwhenupgradingtoASE15,evenwhen
parallelismwasusedinASE12.x.Sinceserialprocessingismoreresourceefficientthanparallelprocessing,
avoidingparallelismmayallowyoutodeliverbetteroverallperformancewiththesamehardware.Itmaywellbe,
andhasindeedbeenobservedbycustomers,thatASE15inserialmoderunsqueriesfasterthanASE12.xwith

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
9

parallelism.Forthesereasons,bestexploreASE15'scapabilitiesinserialmodefirstbeforelookinginto
parallelism.ForDSStypequeries,whereparallelismwasoftendeployedinASE12.x,itisspecificallysuggestedto
lookintotheeffectsoftheoptimizationgoalal l r ows_dss.
Parallelismmaydeliverbetterresponsetimesthanserialprocessingforqueriesusingsemantictablepartitioningin
ASE15,orforDDLcommands(likecr eat e i ndex).Forsuchcases,itmaybeworthwhiletoexploretheimpact
ofparallelisminASE15.
Performancemonitoringtips
Thissectioncontainssomesuggestionsformonitoringperformanceaspectsofyourqueries.Theserequirethe
MDAtablestobeinstalledandenabled.
TodetermineifanysessionsarecurrentlyexecutingqueriesthatconsumealotofdiskI/O,use
sp_moni t or :

sp_moni t or " connect i on" , " di ski o"

Tofindsessionswithlongrunningqueries,replace" di ski o" by" el apsed t i me" .TofindCPU


intensivequeries,replace" di ski o" by"cpu" .Notethatsp_moni t or hasmanyotherhandy
options;usesp_moni t or " hel p" ,andseetheASEdocumentationfordetails.

Toidentifythetop20ofrecentlyexecutedstatementswithrespecttoLogicalI/O,usethisquery:

sel ect t op 20
SPI D, CpuTi me, Logi cal Reads, Physi cal Reads,
Pr ocName=obj ect _name( Pr ocedur eI D, DBI D) ,
MemUsageKB, St ar t Ti me, EndTi me,
Dur at i onSecs = dat edi f f ( ss, St ar t Ti me, EndTi me) ,
KPI D, Bat chI D
f r ommast er . . monSysSt at ement
or der by Logi cal Reads desc

Tofindthetop20queriesforCPUconsumption,changetheorderbyclausetosortonCpuTi meinstead.
Tofindthetop20longrunningqueries,sortontheduration("or der by 9 desc").
TofindtheSQLtextcorrespondingtothesestatements,usetheKPI DandBat chI Dcolumnstoquery
themonSysSQLText table.NotethatmonSysSQLText ,likemonSysSt at ement ,isasocalled
"historical"MDAtable,meaningthatitcontainsonlyalimitedamountofhistory.Tocaptureinformation
fromthesetablesoverlongerperiodsoftime,youshouldfrequentlyselectfromtheseMDAtablesand
storetheresultsetinapermanenttable.
Troubleshootingtips
ASE15wasdesignedtoofferagreatlyimprovedqueryprocessingenvironment.Intherareeventthatqueryplans
orqueryperformancearenotwhatyouexpect,herearesomethingstotrytoisolatetheproblem.
Whenexperimentingwithdifferentoptimizationgoals,makesurenocachedplansareused:changingthe
sessionlevelorserverwideoptimizationgoalwillnotcausecachedplanstoberecompiled.
Forstoredprocedures,eitherexecutethemwi t h r ecompi l e,orrunsp_r ecompi l eononeofthe

10
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

tablesbeingaccessed.Forbatches,makesurethestatementcacheisdisabledbyrunningset
st at ement _cache of f first.

Whenusingdifferentsessionleveloptimizationgoalsinasinglebatchorstoredprocedure(i.e.set
pl an opt goal statements),ensuretoberunning15.0.2ESD#2orlater.Thisisrecommendedbecause
someaspectsofsessionleveloptimizationgoalswerechangedinthatrelease,makingthefeaturemore
intuitiveandeasiertouse.
Fulldetailsonthescopeandsemanticsofsessionleveloptimizationsettings,willbedescribedinanother
whitepaper,titles"ChangestoscopeandsemanticsofsessionleveloptimizationsettingsinASE15.0.2"
(seeURLonpage41).

Whenyouwanttoguaranteethatastoredprocedureisalwaysoptimizedwithaparticularoptimization
goal,irrespectiveofanyserverwideorsessionlevelsettings,putset pl an opt goal
al l r ows_xxxasthefirststatementinthebodyofthestoredprocedure.ThisrequiresASEversion
15.0.2ESD#2orlater.

Ifitissuspectedthatmergejoinsarecausingsuboptimalperformanceinyoursystem,andaserverwide
optimizationgoalisal l r ows_dss,youcouldchangethissettingtoal l r ows_ol t p.However,this
alsoimpliesthathashjoinscannolongerbeused.
In15.0.2orlater,ifyoudon'twanttolosethepossibilitytousehashjoins,youcanalsokeep
al l r ows_dssastheserverwidegoal,andsettheconfigurationparameter' enabl e mer ge j oi n'
to0;thiswilldisablemergejoinsserverwideforalloptimizationgoals.

IfyourSQLcodefromASE12.xcontainsexplicitlyforcedjoinorders(withset f or cepl an),these


forcingsshouldideallybereevaluatedwhenupgradingtoASE15(asSybasehasalwaysrecommended
whentalkingaboutsuchforcings).Ofcourse,ifyoursystemrunstofullsatisfactioninASE15,theremay
benoneedtochangeexistingforcings.However,theymayalsostopyoufromtakingfullbenefitofthe
capabilitiesofASE15.Itisthereforerecommendedtoevaluatetheimpactofremovingtheseforcings.If
thisisimpractical,in15.0.1ESD#2orlater,traceflag15307canbeenabledtonullifytheeffectofanyset
f or cepl anstatementswhenqueryplansarecompiled.
Likewise,anyexplicitforcingsforindexesorforprefetch/parallelism/bufferreplacementstrategycanbe
nullifiedbyenablingtraceflag15308.
Traceflags15307and15308canbesetatboottime.Theycanalsobeenabledwithdbcc t r aceon,but
notethattheireffectisserverwide,soallsessionsareaffected.
Notethatbothtraceflagsdonotaffectanyqueryplanpropertiesdefinedbyabstractqueryplans.

Ifyoursystemseemstobeconsuminganunreasonableamountofspaceint empdb,youcanusethe
MDAtablestoseeifoneparticularsessionconsumesalotofspaceinaworktable.
AssumingtheMDAtablesareenabled,runthefollowingquery:

sel ect SPI D, DBName, Obj ect Name, Par t i t i onSi ze


f r ommast er . . monPr ocessObj ect
wher e DBI D = t empdb_i d( SPI D)
or der by SPI D

LookforsessionsthathavealargevalueforPar t i t i onSi ze.WorktableshaveanObj ect Nameof
' t emp wor kt abl e' .Byqueryingmast er . . monPr ocessSQLText and/or
mast er . . monPr ocessSt at ement youcanfindthecorrespondingSQLstatementforthe
correspondingsessions.Tostopsessionsfromfillingupt empdb,andthusaffectingothersessionsalso
requiringt empdbspace,youcancreatearesourcelimitoftype' t empdb_space' .Anotherpossible

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
11

remedyiscreatingmultipletemporarydatabasesandassigningthesetospecificusers.SeetheASE
documentationforfurtherdetailsonthesefeatures.

Ifyouencounteraslowqueryandyoususpectthatreformattingiscausingthesuboptimalperformance,
firstfollowtherecommendationswithrespecttostatistics(seepage21).Ifthereformattingpersistsand
performanceremainsunsatisfactory,youcanverifywhetherdisablingreformattingimprovesthingsas
follows:

set st or e_i ndex of f - - di sabl es r ef or mat t i ng


go
sel ect - - your quer y
go

Or:
sel ect - - your quer y
pl an ' ( use st or e_i ndex of f ) '

Beforeusingindividualoptimizationcriteriasettingsinproductioncode,Sybaserecommendsverifying
thissolutionwithTechnicalSupport.

Underal l r ows_dss,ifyouencounteranunreasonablyslowquery,orifthequeryrunsintoa701error
duringoptimization,firstfollowtherecommendationswithrespecttostatistics(seepage21).Iftheissues
persist,tryifthefollowingsolvestheproblem:

set bushy_space_sear ch of f - - r el evant onl y under al l r ows_dss!


go
sel ect - - your quer y
go

Or:
sel ect - - your quer y
pl an ' ( use bushy_space_sear ch of f ) '

Beforeusingindividualoptimizationcriteriasettingsinproductioncode,Sybaserecommendsverifying
thissolutionwithTechnicalSupport.

WhenrunninglargenumbersofidenticalorverysimilarclientgeneratedSQLqueries(i.e.notstored
procedures,andalsonotinexecuteimmediate)wherethedifferenceliesinthesearchargument(i.e.a
differentprimarykeyvalue),andyou'rerunning15.0.1orlater,considerenablingthestatementcacheas
wellasliteralautoparameterization.Thesemaysignificantlyreducethetimeandresourcesspenton
queryoptimizationandthereforeimproveoverallperformance.
LiteralautoparameterizationisanenhancementtothestatementcacheinASE15.0.1orlater.Whenthe
statementcacheisenabled,aquery'splanwillbecachedsothatanexactlyidenticalquerydoesnotneed
tobecompiledagain,butthecachedplancanbeusedinstead,savingtimeandresources.Withliteral
autoparameterizationenabled,thiscachingisextendedtoalmostidenticalqueriesthatdifferonlyina
constantvalue.Forexample,takethesetwoqueries:

12
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

sel ect Cust Name f r omCust omer s wher e Cust I D = 123


sel ect Cust Name f r omCust omer s wher e Cust I D = 456

Thesequeriesarenotidentical,buttheyarelikelytoendupwiththesamequeryplan.Enablingliteral
autoparameterizationhastheeffectthatthestatementcachefactorsouttheconstantvalueinthe
whereclauseandcachesaplanforallquerieslookinglikethis:

sel ect Cust Name f r omCust omer s wher e Cust I D= <i nt eger - const ant >

Thismeansbothqueriesabovewouldusethesamecachedqueryplan. Literalautoparameterizationcan
greatlyimprovetheeffectivenessofthestatementcache,andthereforeitisrecommendedtoexperiment
withthisfeatureifyourapplicationsusemanyalmostidenticalSQLqueriesthatarenotpartofstored
proceduresandarenotruninexecuteimmediate.
Thestatementcacheisenabledseverwidewiththeconfigurationparameter' st at ement cache
si ze' .Onsessionlevel,thestatementcachecanbedisabledwithset st at ement _cache of f .
Literalautoparameterizationisenabledserverwidewiththeconfigurationparameter' enabl e
l i t er al aut opar am' ,andonsessionlevelwithset l i t er al _aut opar amon(orof f ).It
appliesonlywhenthestatementcacheisenabledtoo.
Using'CompatibilityMode'inASE15.0.3ESD#1
ForcustomerswhoprefertolimittherequiredtestingeffortforupgradingtoASE15,Sybasehasintroducedanew
featurenamed'CompatibilityMode'inASE15.0.3ESD#1.
CompatibilitymodeisaqueryprocessingenhancementallowingqualifyingTSQLqueriestobeprocessedwitha
methodofqueryoptimizationandqueryexecutionverysimilartothatusedinASE12.5,insteadofusingtheASE
15queryprocessingalgorithms.
Compatibilitymodeisnotanoptimizationgoal,butaqueryprocessingoptiononahigherlevelwhichdetermines
whether12.5likeoptimizerandqueryexecutionlogicwillbeused(whichexcludeallASE15features),orwhether
theASE15featuresareused;inthelattercase,theconsiderationsintherestofthisdocumentapply.
Compatibilitymodehasbeenmadeavailabletocustomerstoprovidemorecontrolovertheprecisemomentwhen
ASE15specificqueryprocessingfeaturesbecomeactiveintheirqueriesandapplications,thusallowinggradual
introductionofASE15queryprocessingaspectsaftermigratingtoASE15.Consequently,therequiredtesting
effortcanbebetterfocusedandplannedthanwhenmigratingtoASE15withoutusingcompatibilitymode.
Itshouldhoweverbenotedthat,asaconsequenceofusingcompatibilitymode,applicationsmaynotbeableto
fullybenefitfromthequeryprocessingenhancementsofASE15.Thisisaconsciouschoicethatcustomerswill
needtomakewhenusingcompatibilitymode.
Itisexpectedthatcustomers,afterhavingmigratedtoASE15,willeventuallydisablecompatibilitymodesoasto
takefulladvantageoftheperformanceimprovementsinASE15.

Forfulldetailsoncompatibilitymode,pleaserefertothewhitepaper"Using'CompatibilityMode'InASE15.0.3
ESD#1ForASE15Migration"(seeURLonpage41).
Ifallelsefails
IncasenoneofthesuggestionsinthecurrentdocumenthelpyoutoresolvequeryperformanceissuesinASE15,
SybaserecommendsthatyouupgradeyourASEinstallationtothelatestESDavailableforyourplatform.As
always,Sybaseismakingcontinuousproductimprovementsandyourissuemayalreadyhavebeenfixedinalater
ESDthanyouarecurrentlyrunning.Ifyourproblemstillpersists,youshouldopenacasewithSybaseTechnical

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
13

Support.Pleaserefertopage35forguidanceabouttheinformationtocollectbeforecontactingTechnical
Support.
ObsoleteoptimizationcommandsinASE15
Variousoptimizationrelatedsettingsfrom12.xarenolongerwhenusingtheASE15queryprocessingfeatures.
AlthoughthefollowingcommandsstillexistinASE15,theydonotperformanyfunctionanymore,andsimply
returnasuccessstatus:
set sor t _mer ge:inASE15,replacedbyset mer ge_j oi n,optimizationgoalsandthe
configurationparameter' enabl e mer ge j oi n' (in15.0.2)
set j t c:JoinTransitiveClosureisalwaysenabledinASE15
set t abl e count :nolongerappliesinASE15
Inaddition,thefollowingfeaturesnolongerapplyinASE15:
configurationparameter' enabl e sor t - mer ge j oi n and J TC' :replacedbyoptimizationgoals
andbytheconfigurationparameter' enabl e mer ge j oi n' (in15.0.2).

boottimetraceflags334and384,whichenabledmergejoinsandJTCindividually,nolongerhaveany
functioninASE15.
However,notethatwhenusingcompatibilitymode(seepage12),thenthesecommandsandfeatureswillstill
functionasinpre15.0forthosestatementsthatareprocessedinfullcompatibilitymodeorrestricted
compatibilitymode.ForstatementsthatareprocessedusingASE15mode,thesecommandsarenoopsas
describedabove.

14
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

ResourceRecommendationsforASE15

Procedurecache
OneoftheconsequencesoftheredesignedqueryprocessingengineinASE15isthatASErequiresmoreprocedure
cache.Thisincreasedmemoryrequirementappliestooptimizationandexecutionofqueries.
OnereasonforthisincreasedrequirementisthatASEhasmanymorejoinmethodsanddataaccessalgorithmsto
considerthanpriortoversion15.Thisisespeciallytrueforal l r ows_dss,whichwillgenerallytendtowards
consumingmoreprocedurecacheforqueryoptimizationthanal l r ows_mi x,whichinturnusuallyneedsmore
procedurecachethanal l r ows_ol t p.
ItisdifficulttopredictexactlyhowmuchmorememoryASE15willneedcomparedwith12.5.Asaruleofthumb,
SybaserecommendstoplanforsizingoftheprocedurecacheinASE15between2to6timeslargerthaninASE
12.5.Whenal l r ows_dssisused,itislikelythatmoreprocedurecachemaybeneededthanwhen
al l r ows_ol t pisused.Usethe'procedurecache'sectionofsp_sysmontomonitorprocedurecacheusage.

Procedurecacheusagelimitationin15.0.2ESD#2
InASE15.0.2ESD#2,alimitationwasimplementedontheamountofprocedurecachethatcanbeusedbytheASE
queryoptimizer.Thisisbasedonthesettingofconfigurationparameter' max r esour ce gr anul ar i t y'
(settableonsessionlevelwithset r esour ce_gr anul ar i t y).Thissettingisanintegerbetween1100,
reflectingapercentage.Thedefaultsettingis10.
Thisfeatureworksintwoways.First,whentheoptimizerhasconsumedmoreprocedurecachethan:

<max_r esour ce_gr anul ar i t y> 100 <conf i gur ed pr ocedur e cache si ze>

andwhenatleastonefullplanhasalreadybeengenerated,theoptimizerwilltimeoutandusethecurrentbest
planasthefinalplan.
Second,whentheoptimizerhasnotbeenabletogenerateafullplanyet,buthasalreadyconsumedanamountof
procedurecacheof:

max( 50, <max_r esour ce_gr anul ar i t y>)
100 <conf i gur ed pr ocedur e cache si ze>

thentheoptimizerabortsthequeryplangenerationtoavoidconsumingalloftheprocedurecache.Sincethe
queryhasstillnoplan,itsexecutionwillthenfail.
Thisnewbehaviourwasintroducedin15.0.2ESD#2.Itcanbedisabledwithtraceflag15380.

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
15

OtherresourceusageaspectsofASE15
OneofthenewaspectsofASE15isthefeatureoftablepartitions.Althoughsemanticdatapartitioningisan
optionallicensefeature,itmattersevenwhenyoudonotusesemanticdatapartitioning:inASE15,eachtableand
indexalwaysconsistsofatleastonepartition.Consequently,theconfigurationparameter' number of open
par t i t i ons' mustbesethighenoughtoavoidunnecessaryperformancepenalties.
Sybaserecommendsusingsp_count met adat atoestimatetherequiredsettingforthisparameter,anduse
sp_moni t or conf i gtomonitoritsusage(seepage26).

16
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

StatisticsInASE15

WhystatisticsmatterespeciallyinASE15
ASEusesacostbasedqueryoptimizertochoosethebestplanforaparticularquery.Toachievethatgoal,the
optimizerreliesonstatisticsaboutthetables,indexes,partitions,andcolumnsreferencedinaqueryforestimating
thecostintermsofI/OandCPUtimeofdifferentpossiblequeryplans.Theoptimizerthenchoosesthequery
planmethodthathasthelowestcost.However,thiscostestimatecannotbeaccurateifthestatisticsthemselves
arenotaccurate.Asaresult,inaccuratestatisticscouldleadtoasuboptimalchoiceofplansandresultinslower
performancethannecessary.
Somestatistics,suchasthenumberofpagesorrowsinatable,areupdatedautomaticallyduringqueryprocessing
(thesearestoredinsyst abst at s).Otherstatistics,notablythehistogramsoncolumns,aswellasdensity
information,(bothstoredinsysst at i st i cs),areupdatedonlywhenupdat e st at i st i csruns,orwhen
indexesarecreated.Inpractice,itiscriticalthatthehistogramsbeuptodate.ItisaDBAresponsibilityto
scheduleandrunupdat e st at i st i cs.
InASE15,havinguptodatestatisticshasbecomeevenmoreimportantthanitalreadywas.
ASE15ismoresusceptibletostatisticsissuesthanpreviousASEreleasesduetonowhavingmultiplealgorithmsfor
sorting,grouping,unions,joiningandotheroperations,thusofferingtheoptimizermanymorepossiblechoices.In
addition,ASE15usesstatisticsinmorewaysthaninASE12.x,forexamplefordeterminingthejoinorderinmulti
tablequeries.Goodstatisticsarethereforeimportanttohelpavoidgeneratingasuboptimalqueryplan.
Recommendation:runupdateindexstatistics
ItisrecommendedtomaintainuptodatehistogramsforallcolumnsreferencedinWHEREclauses,eitherasjoin
predicatesorassearcharguments.Sincethesecolumnsaretypicallypartofanindex,inpracticethismeansthat
runningupdat e i ndex st at i st i csforallusertablesislikelytodothejob.Ifsuchcolumnsarenotpartof
anindex,youshouldatleastgeneratehistogramsforthesenonindexedcolumns,orconsiderindexingthem.
Comparedwithupdat e st at i st i cs,runningupdat e i ndex st at i st i csalsogenerateshistogramsfor
thenonleadingindexcolumns,whichprovidestheoptimizerwithmoreinformationtogenerateoptimalquery
plans.However,updat e i ndex st at i st i cshassomepotentialdisadvantagescomparedwithupdat e
st at i st i cs.Sinceitneedstoperformasortoperationforeverynonleadingindexcolumn(theleadingindex
columnisalreadysortedintheindextreebydefinition),updat e i ndex st at i st i cswilltakemoretimeand
resourcestorunthanupdat e st at i st i cs.
Using'sampling'withupdateindexstatistics
Onepossibleconsequenceisthatupdat e i ndex st at i st i csmayrunintoa701errorwhenthetableistoo
largetoperformthesortforacolumnwiththeavailableamountofprocedurecache.
Whenthishappens,theremedyapartfrompossiblyincreasingthesizeoftheprocedurecacheistorun
updat e i ndex st at i st i cs withthe"sampling"option.Insteadofreadingthecolumnvaluesfortheentire
table,onlyapercentageofthetablewillberead.Thismakessensesincethefinalhistogramforalargetableis
basedonjustafractionofthecolumnvaluesread.Apositivesideeffectisalsothatupdat e i ndex
st at i st i cswithsamplingrunsfasterthanwithoutsampling,soitmayalsobeusedforlargetableswhen
updat e i ndex st at i st i cstakestoolongtorun.Notethatwhenusingsampling,thereisalwaysa

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
17

possibilitythatthehistogramcontainslessaccurateinformationthanwhenthefulltablewasread.However,this
potentialdownsideisdifficulttoquantify.
Inthefollowingexample,onlyabout5%ofthetableisreadforcreatingthehistogramsfornonleadingindex
columns:
updat e i ndex st at i st i cs bi g_t abl e wi t h sampl i ng=5

Thelowestpossiblevalueforsamplingis1%.Settingthepercentageto0isequivalentto100%.
Intheopt di agoutput,thesamplingpercentageusedisdisplayedas"SamplingPercent:"(0means:nosampling
used).
Insteadofspecifyingthesamplingpercentageexplicitly,adefaultsamplingpercentagecanalsobeconfigured
serverwide,bymeansoftheconfigurationparameter" sampl i ng per cent " .However,thissettingwillapply
toallusertablesandthatmaynotalwaysbedesirable.
Speedingupupdatestatisticswithparallelism
Itmaybepossibletospeedupupdat e st at i st i csfornonleadingindexcolumnsornonindexedcolumnsby
usingparallelism.Forsuchcolumns,histogramcreationrequiresthatallcolumnvaluesbesortedfirst.By
performingthissortoperationwithparallelworkerthreads,theruntimeofupdat e st at i st i cscanoftenbe
improved(assumingyoursystemhasenoughresourcestouseparallelism).
Touseparallelsorting,specifythewi t h consumer sclause:

updat e i ndex st at i st i cs bi g_t abl e


wi t h consumer s=20 - - use 20 wor ker pr ocesses f or t he sor t

Exactlyhowmuchimprovementcanbeachievedwithparallelism,andwhatlevelofparallelismwouldbeoptimal,
highlydependsonthespecificsystemhardware,ASEconfigurationandworkload.Youshouldexperimentto
determinewhatworksbestforyoursituation.
Notethatparallelismforupdat e st at i st i csdoesnotapplytothetablescanorindexscanwithwhichthe
columnvaluesareretrieved.
Whentorunupdatestatistics?
Statisticsshouldbeanaccuratereflectionofthedatainatable.Thisimpliesthatstatisticsmayneedtobeupdated
whendataischangedmorefrequently.Oneexampleisadat et i mecolumn,holdingthedatethatarowwas
inserted.Anotherisanidentitycolumn,whichwillcontinuouslyinserthighervalues.Forthesetypesofcolumns,
histogramswillquicklybecomeoutofdate,sinceallnewrowsbeinginsertedwillhavevalueshigherthanthe
previousmaximumvalueinthehistogram.Thismaycontributetotheoptimizergeneratingsuboptimalquery
plans.
ASE15offersanewfeaturetoassistindecidingwhetherupdat e [ i ndex] st at i st i csmaybenecessary
foratable.Thenewbuiltinfunctiondat achange( table_name, partition_name, column_name)
functionmeasurestheamountofchangeinthetable(orpartition)sincethelasttimeupdat e [ i ndex]
st at i st i cswasrun.Dependingonthispercentage,youmaydecidetor un updat e [ i ndex]
st at i st i csmore,orless,frequently.
Specifically, dat achange( ) measuresthenumberofi nser t s,updat es,anddel et esthathaveoccurred
onthegiventable,partition,orcolumn.Thisinformationhelpsyoudetermineifrunningupdat e [ i ndex]
st at i st i csmaybeneeded.

18
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

Anexampleofthedat achange( ) functionis:

1> sel ect dat achange( ' my_t abl e' , nul l , nul l )
2> go
- - - - - - - - - - - - - - - - - - - - - - - - - - -
243. 340418

Inthisoutput,thepercentageofchangestothetablemy_t abl eis243%,meaningthatthenumberofchangesis
higherthenthenumberofrowsinthetable.Thisindicatesthatitisagoodcandidatetorunupdat e [ i ndex]
st at i st i csnow.
Thedat achange( ) builtinfunctioncanalsoberunonindividualcolumns:

1> sel ect dat achange( ' my_t abl e' , nul l , ' i d_number ' )
2> go

- - - - - - - - - - - - - - - - - - - - - - - - - - -
0. 017761
Theresultof0.017%indicatesthatthei d_number columnhashadarelativelylowamountofchange,and
thereforethestatisticsforthatcolumnarestilllikelytobeaccurate.Itisgoodpracticetorundat achangeona
regularbasisagainstcommonlyusedtablesandcolumns.Thisgivesabasisfordeterminingwhenitisusefultorun
updat e [ i ndex] st at i st i cs.Lastly,byspecifyingthesecondparameterofdat achange( ) , whichisa
partitionname,onlythechangesforthatpartitionarereported.Youmayneedtousesp_hel ptodeterminea
table'spartitionnames.
ASEhasthefunctionalitytoautomaticallycheckobjectsusingdat achange( ) , andscheduleupdat e
[ i ndex] st at i st i csaccordinglyusingASE'sbuiltinjobschedulerfeature.Formoredetailsonsettingup
andusingthisfunctionality,pleaserefertothe15.xmanualtitled"PerformanceandTuningSeries:Query
ProcessingandAbstractPlans".Inchapter6,"UsingStatisticstoImprovePerformance",refertothesectiontitled
"Automaticallyupdatingstatistics".

NB.Forpartitionedtables,itispossibletorunupdat e [ i ndex] st at i st i csonanindividualpartition.


Whilethatmayallowyoudividealongrunningupdat e st at i st i csrunforalarge,partitionedtableinto
multipleshorterruns,keepinmindthatupdatingstatisticsonapartitiononlyupdateshistogramsonlocalindexes
forthatpartition:histogramsforglobalindexesonthetablewillnotbeupdated.
Howmanyhistogramsteps?
Anotherissueishowmanystepsahistogramshouldhaveinordertoprovidetheoptimizerwithanaccurate
reflectionofthedatadistributioninacolumn.Thedefaultof20histogramstepsmaybeadequateforcolumns
withasmallnumberofdistinctvalues("lowcardinality"),orfortableswithasmallnumberofrows.However,for
tableswithalargenumberofrows,havingcolumnswithmanydistinctvalues20stepsmaybeinsufficient.Thisis
especiallytruewhenacolumnhasahighdegreeofdataskew(thatis,thevaluesforthecolumnarenotevenly
distributedovertherows).
Obviously,ifyoursystemrunstofullsatisfactionwith20histogramsteps,donotchangeanything.However,ifyou
suspectsuboptimalqueryplansarebeinggenerated,youmaywanttoconsiderincreasingthegranularityof
histogramsbyincreasingtheirnumberofstepsanddeterminewhetherthathasapositiveeffect.Asalways,there
canbetoomuchofagoodthing.Increasingthenumberofhistogramstepscanleadtohigherresource
consumption,especiallyprocedurecacheusage,andlongeroptimizationtimesbeforeaqueryplanisgenerated.

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
19

DuetotheoptimizationtimeoutlimitfeatureinASE15,thiscaninturnalsoresultinsuboptimalplansbeing
generated.
Exactlyhowmanystepsahistogramshouldhaveishardtopredict.Inpractice,youneedtoseeifahighernumber
ofhistogramstepsresultsinbetterqueryplansandbetteroverallperformance.
Nevertheless,asapracticalguidelineitmaybeusefultostartbyincreasethestepcountto200.Ifthatdoesnot
havethedesiredpositiveeffect,tryahighernumber,like500.Analternativeguidelineistouseonehistogram
stepforevery10,000datapages.However,morethan10002000histogramstepsisgenerallyconsideredtoohigh
anumber:ifnopositiveeffecthasbeenachieved,thehistogramstepsmaynotcontainthesolutiontoyour
problem.
Thenumberofhistogramstepsisdeterminedwhenupdat e [ i ndex] st at i st i csisexecuted.Thisisdone
asfollows:
Theconfigurationparameter' number of hi st ogr amst eps' definesthedefaultforallcr eat e
i ndexandupdat e [ i ndex] st at i st i cscommandsfornewhistograms.Theoutofthebox
defaultis20.

Forupdat e [ i ndex] st at i st i cs,thenumberofstepscanalsobesetexplicitlywiththeclause


usi ng nnn val ues:
updat e i ndex st at i st i cs bi g_t abl e usi ng 300 val ues

Forexistinghistograms,updat e [ i ndex] st at i st i csusesthecurrentnumberofstepsinthe
existinghistogramwhengeneratinganewhistogram.Theconfigurationparameter' number of
hi st ogr amst eps' doesnotapplytoexistinghistograms.Onlywhenupdat e [ i ndex]
st at i st i cs explicitlyspecifiesusi ng nnn val ues,willthestepcountintheexistinghistogram
beoverridden,andnnnbeusedasthenumberofstepsforthenewhistogram.

Thenumberofhistogramstepsestablishedatthispointisthetargetnumberofstepsforthehistogram.
Intheoptdiagoutput,thisisdisplayedas"Requestedstepcount:".

Next,the' hi st ogr amt uni ng f act or ' comesintoplay.Thisconfigurationparametermultiplies


thenumberofstepsdeterminedaboveforthepurposeofgeneratinganinternal,intermediatehistogram
first.If100histogramstepsarechosen,and"histogramtuningfactor"issetto20,thentheintermediate
histogrammayhaveasmanyas2000steps.Thisisdonetoincreasethechanceofidentifyingsocalled
"frequencycells",whichreflectduplicatedatavalues.Ifnofrequencycellsarefound,thehistogramis
compressedbacktotheoriginalnumberofsteps;iffrequencycellsarefound,thesearekept.Theactual
numberofresultinghistogramstepsisdisplayedintheopt di agoutputas"Actualstepcount:".

Priorto15.0.1ESD#1,the" hi st ogr amt uni ng f act or " wassetto1bydefault.Asof15.0.1


ESD#1,theoutoftheboxdefaulthasbeenincreasedto20duetopositiveexperienceswiththisfeature.
Thehistogramtuningfactorcanrangefrom1to100;however,itisrecommendedtosetit(orleaveitset
at)20unlessadviseddifferentlybySybaseTechnicalSupport.Toavoidunexpectedexcessivelylargestep
counts,andcorrespondingprocedurecacheusage,whencustomersupgradefrom12.5to15,asof15.0.2
ESD#2,thefollowingformulaisusedwhenhistogramtuningfactorisstillsettothedefaultof20:

mi n( max ( 400, r equest ed_st eps) ,


hi st ogr am_t uni ng_f act or * r equest ed_st eps)

20
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

Thisformulahastheeffectofassumingthat' hi st ogr amt uni ng f act or ' issetto1(aswaslikely


thecaseforthosecustomersbeforetheyupgradedto15).
Identifyingmissingstatistics
ASE15hasanewfeaturetoflagcaseswherenostatisticsexistforcolumnswheretheoptimizerwouldhave
expectedthem.Whenrunningthecommandset opt i on show_mi ssi ng_st at s on,theoptimizerwill
printamessagewhenitencounterssuchacase.
Bydefault,theoutputiswrittentotheASEconsole(that'snotthesameastheASEerrorlog!);enabletraceflag
3604togettheoutputsenttotheclient.
Twoexamplesofthesemessagesare:

NO STATS on col umn t . col 1


NO STATS on densi t y set f or t ={col 2, col 3, col 4}

Whenseeingsuchmessages,itisrecommendedthattheDBArunupdatestatisticsforthecolumnsinvolved.The
correspondingcommandswouldbe:

updat e st at i st i cs t ( col 1)
updat e st at i st i cs t ( col 2, col 3, col 4)

Dependingonwhichindexesexistonthistable,thesameeffectmightbeachievedbyrunningupdat e i ndex
st at i st i cs t .Notethatcreatingthesestatisticsforthereportedcolumnsdoesnotguaranteethatadifferent
queryplanwillbegeneratedbytheoptimizer.However,sincetheoptimizersignalsitwouldhavelikedtoconsider
additionaloptions,itisbesttoensuretherequiredstatisticsareavailable.
Itisrecommendedtoenableset opt i on show_mi ssi ng_st at s onatleastforsometimeintheASE15
testenvironment.Thisoptioncanbesetinalogintrigger,soapplicationcodechangescanbeavoided.Please
refertotheASEdocumentationformoreinformationaboutlogintriggers.
OldstatisticsandupgradingtoASE15
BeforeorafterupgradingtoASE15,itisrecommendedtodeterminewhetherveryoldstatisticsexist.Suchold
statisticsmayexistforvariousreasons:
SinceASE11.9,whenanindexisdropped,histogramsfortheindexcolumnsarenolongerdropped
automaticallyatthesametime.Therefore,ifthesehistogramsareneverexplicitlyupdatedandthat
mayneverhappenwhenthosecolumnsarenotpartofanotherindextheoldhistogramsremain.

Ifahistogramwasevercreatedforanonindexedcolumn,itwillstillbearoundifitwasneverupdatedor
deleted.

Irrespectiveofthereasonwhytheycametoexist,oldstatisticsmaynotprovideanaccuratereflectionofthe
currentdatadistributioninthecolumn.Inrarecases,thismayresultinneedlesslyinefficientqueryplansafter
upgrading.
Todetermineifoldstatisticsexist,querythecolumnsysst at i st i cs. moddat e(thisisthedate/timewhen
theexistinghistogramsanddensitieswerelastupdated).Ifthisindicatesthatveryoldstatisticsindeedexist,use
theopt di agutilitytodeterminewhichstatisticsareinvolved.If,atalaterpoint,youareseeingsuboptimal

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
21

performanceforquerieswheretablesareinvolvedthatyouknowhaveveryoldstatistics,considerupdating(the
preferredmethod)ordeleting(thefastermethod)thoseoldstatistics.
However,beforedeletinganystatistics,pleasemakeabackupcopywiththeopt di agutility.Thisallowsyouto
restoretheoriginalstatistics(again,withopt di ag)inthecasethatthefreshlyupdatedstatisticsshouldresultin
unexpectedperformanceeffects.
Infact,itmaybeagoodideatomakeabackupcopyofthestatisticsforallyourtablesafterupgradingtoASE15,
butbeforerunningupdat e [ i ndex] st at i st i cstorefreshthestatistics.
Todeletestatistics,useoneofthesecommands:

del et e st at i st i cs t - - del et e al l hi st ogr ams and densi t i es on t abl e t


del et e st at i st i cs t ( a) - - del et e t he hi st ogr amon col umn t . a
del et e st at i st i cs t ( a, b) - - del et e t he densi t i es f or col umns ( t . a, t . b)

Summaryofrecommendationsforstatistics
Pleaserefertotheprecedingpagesfordetailsoneachoftheserecommendations.
Keepstatisticsonusertablesuptodatebyrunningupdat e [ i ndex] st at i st i cs regularly

Usethedat achange( ) functiontodeterminewhetherupdat e [ i ndex] st at i st i csshouldberun


moreoften

Preferablyrunupdat e i ndex st at i st i csinsteadofupdat e st at i st i cs.Forlargetables,use


samplingifnecessary.

Ifyoususpectsuboptimalqueryplansaregenerated,considerincreasingthenumberofhistogramstepsfor
thetablesinvolved.

Usethecommandset opt i on show_mi ssi ng_st at s ontodeterminecaseswherestatisticsmaybe


missing;andthencreatethosestatistics.

ConsiderdeletingorupdatingoldstatisticsafterupgradingtoASE15whentheseareassociatedwithsub
optimalqueryplans;however,alwaysmakeabackupcopyfirstwithopt di ag.

22
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

RecommendedTestingBeforeUpgradingToASE15

Whyshouldyoutest?
BeforeupgradingyourproductionsystemstoASE15,itisimportanttogatherdetailsabouttheperformance
characteristicsofyourapplicationsonthecurrent,pre15versionofASE,preferablyinaproductionenvironment.
Gatheringsuchdataisimportant,sinceanydiscussionsaboutperformancedifferencesafterupgradingtoASE15
willnotbeveryusefulifthesediscussionsarenotbasedonhardnumbers.Forthe12.xvs15performance
comparisontobevaluable,itisstronglyrecommendedthatthesetestsbeperformedasrealisticallyaspossible.
Thismeans:
Runtestsforasmanyapplicationfunctionsaspossible,oratleastthemostcriticalfunctions.Foreach
function,measuretheresponsetimeorthroughput;preferablyalsoperformthesemeasurementsfor
eachqueryexecutedbytheapplication(seepage32forsuggestions)

RuntheperformancemeasurementsinyourcurrentASE12.xproductionsystem

runthesametestsbeforeupgradingyourproductionsystemtoASE15,inafullyconfiguredASE15test
systemwithacopyofthefullASE12.xproductiondatabase,aswellasrealisticworkload(i.e.thesame
queriesasin12.x,andwiththesamelevelofconcurrentuseractivity)

Also,preferablyrunthesetestsbeforeupgradingyourproductionsystemtoASE15,sothatyoucanidentifyany
issuesbeforegoingliveonASE15.Capturingthe"performancefootprint"ofyourcurrentASE12.xproduction
environmentwillprovideagoodbaselineforanycomparisonswithASE15.Themeasurementsshouldprovide
specificnumberssuchasnumberoflogicalI/Os,elapsedtime,compilationtime,CPUutilizationetc.forapplesto
applescomparison.Differencesinthemeasuredvalueswillhelpidentifyindividualqueriesperformingpoorlyas
wellasanyserverlevelconfigurationissues.
Therearesomedifferentanglestolookingatperformance.ToenableasensiblecomparisonofperformanceinASE
12.xandASE15,performancedataneedstobegatheredontwolevels:
forindividualqueries,runinisolation
forindividualqueries,runwithfullworkloadbyotherusers
forASEasawhole,fromaserverwideresourceusageperspective

PleaseensurethattheconfigurationsoftheASE12.xandASE15serverareasidenticalaspossible.Havingsaid
that,theASE15servermayhavemoreresourcesallocatedtoitthan12.x,andinsomecases(seepage14)thatis
infactrequired.Also,makesurethetestsareexecutedinsimilarcircumstances.
Thesearesomeaspectsthatarecriticaltodoingafaircomparisonbetween12.xand15:
Ensurethecacheis'warmedup'thesamewayin12.xandin15duringthetests
Useidenticalcache/bufferpoolconfigurations
MakesuretheamountofprocedurecacheinASE15isamultipleofwhatisusedin12.x(seepage14)
Usesimilardatadevicelayout/placement,especiallyforlogdevicesandfort empdb?
Ifyourunteststhatmodifydata,considersettinguptestsystemswherebytheoriginaldatabasecanbe
restoredaftereachtestrun.

Theseconsiderationsarecriticalastheywillaffecttheperformancebeingmeasured.Differencesintheseareas
canthereforeleadtofalsealarmsandwastedtimefollowinguponnonexistentissues.

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
23

Pleasenote
ItisimportanttoobservethattheapproachtowardstestingasadvocatedaboveisnotspecificforASE15,butisa
bestpracticethatappliestoanymajorupgradeofanysoftwareproduct.Thebestchanceofavoidingpotential
risksaroundupgradesistorunasrealisticanenvironmentaspossiblebeforeputtingyouractualproduction
systemsthroughtheupgrade.Shouldyoubeunabletofollowthisapproach,thenaturalimplicationisthatyou
simplywillnotdiscoveranyissuesuntilyourproductionsystemdoes.
Fromariskmanagementperspective,youshouldaskyourselfhowimportantitistoidentifyanyperformance
issuespriortotheupgrade,andhowmuchopportunityyouwillhavetoidentifyandfixsuchissuesafteryour
productionsystemhasbeenupgraded.Although,again,thisisnotspecificforASE,Sybaserecommends
performingthoroughtestingasoutlinedinthisdocumenttominimizetheriskofdisruptionsduetoanupgrade.
UsingCompatibilityMode
Asdescribedonpage12,ASE15.0.3ESD#1providesafeaturenamed'CompatibilityMode'tooffercustomersa
migrationpathtoASE15thatrequireslesstestingeffortatthemomentofmigration.
Nevertheless,SybasestillrecommendstoperformsufficienttestingonapplicationsthataremigratedtoASE15,
evenwhenusingcompatibilitymode.
Identifyingqueriesthatrunslower
Assumingyouareabletorunrealistic,representativetestsonbothASE12.xandASE15,yournextstepsdepend
onwhatyoufindinASE15.Alongthelinesofthesuggestionsonpage7,itisrecommendedtorunyourtestsin
ASE15atleastthreetimes,eachtimewithadifferentserverwideoptimizationgoal.
Intheidealsituation,youcanestablishaserverwideoptimizationgoalunderwhicheverythingrunsthesameor
fasterinASE15,inwhichcasethereisprobablynotmuchelselefttodo.Intheeventthatsomeapplications
wouldappeartorunslowerinASE15thaninASE12.x,youwillfirstneedtoidentifythequeriesinvolved,then
determinewhytheyrunslower,andfinallyfigureouthowtoresolvethis.Themainchallengeliesinidentifying
thosequeriesthatrunslower.
IfmaybeimmediatelyapparentwhichqueriesrunslowerinASE15,forexamplewhenaclearlydefined
applicationfunctionappearstoperformlessthanin12.x.Insuchacase,thecorrespondingSQLqueriescan
hopefullybeidentifiedrelativelyeasilybyusingtheMDAtablesorbyapplicationtracing(seepage32).Ifthe
slowerqueriescannotbeidentifiedeasily,thebestapproachistocaptureallSQLqueriessubmittedbythe
applicationinASE15(again,seepage32),andanalyzethesefurther(seebelow).
Ingeneral,itisparticularlyimportanttoensurethefollowingtypesofqueriesareincludedinyourtests,evenif
theyarenotexecutedfrequently(forexample,forperiodicreporting).Applicationdevelopersmaybeableto
providesomeofthesequeries.Thisconcernsqueriesinvolving:
multitablejoins,
multipleviews/unions,
starschemajoins
severalsubqueries
derivedtables
outerjoins
AnalyzingperformancedifferencesbetweenASE12.xandASE15
OnceyouhavecapturedtheSQLtextofactualproductionqueries,youwillneedtoanalyzethesetodetermine
whichqueriesperformworseinASE15thanin12.x.Thisprocesscanbeperformedwithsimplecommandline

24
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

tools,forexampleasdescribedbelow.Notethatthisapproachiswellsuitedforidentifyingqueryplanproblem
withlongerexecutiontimes(i.e.multipleseconds),butlesssuitableforquerieswithveryshortexecutiontimes
(e.g.100milliseconds).
First,createafile,named,say,sql . i n,withthefollowinglayout,containingtheSQLtextofyourcaptured
queries(inbatches,sincethisishowapplicationssubmitqueriestotheASEserver):

set pl an opt goal al l r ows_xxx - - onl y f or 15; t hi s r ai ses an er r or i n


12. x
go
set st at i st i cs pl ancost on - - onl y f or 15; t hi s r ai ses an er r or i n
12. x
go
use your _db - - your def aul t dat abase
go
set st at i st i cs i o on
set st at i st i cs t i me on
set showpl an on
go
<batch 1> - - capt ur ed SQL quer y bat ches go her e
go
<batch 2>
go
[ . . . ]
<batch n>
go

NowrunthisfilebothinASE12.xandin15andcapturetheoutput:

i sql - U user name - P passwd - S YOUR_12X_SERVER - e - i sql . i n >


sql . 12x. out
i sql - U user name - P passwd - S YOUR_15_SERVER - e - i sql . i n > sql . 15. out

Nowyouneedtoanalyzethedifferencesinperformancebetweenexecutionin12.xandin15.
Thiscanbedonebysearchingforthestring"Serverelapsedtime:"inbothfiles(forexample,withgrep),and
comparingtheresults(forexample,byimportingthelistofexecutiontimesforbothcasesintoaspreadsheetand
lookingforthosecasesthataremorethan,say,50%slowerinASE15).
Hereisanexampleofsuchaline,indicatingthatthequeryraninlittlelessthan16minutesinASE15:

Adapt i ve Ser ver cpu t i me: 27300 ms. Adapt i ve Ser ver el apsed t i me: 945953 ms.

AnothercriteriontoidentifyqueriesistocomparetheamountofI/Othequeriesspentin12.xand15.0.Thiscan
bedonebyexaminingoutputlineslikethefollowing(notethateachquerymayproduceanumberofsuchlines,
oneforeachtablereferencedbythequery).Thenumbertolookforisthenumberofregularlogicalreads(shown
inboldbelow):

Tabl e: Account s scan count 365, l ogi cal r eads: ( r egul ar =833370 apf =16
t ot al =833386) , physi cal r eads: ( r egul ar =1927 apf =101769 t ot al =103696) ,
apf I Os used=99762

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
25

Onceyouhaveidentifiedspecificqueriesthisway,youcanstudythoseparticularcasesinmoredetailbylookingat
theirqueryplan,andtheLavaTreeoutputresultingfromthepl ancost option(seepage30).

26
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

Analyzingshortdurationqueries
Tocomparetheperformancedifferenceofveryshortqueries,youmaywanttorunsuchaqueryapredefined
numberoftimes,e.g.

decl ar e @i i nt , @d dat et i me
sel ect @i = 1000 - - r un t he quer y 1000 t i mes
decl ar e sel ect @d = get dat e( )
whi l e @i > 0
begi n
sel ect @i = @i - 1
. . . your quer y. . .
end
sel ect Dur at i onI nMi l l i Sec=dat edi f f ( ms, @d, get dat e( ) )
go

Withthisapproach,youshouldcomparethenumberofmillisecondsfor1000executionsin12.xand15.Repeating
aquery1000timeswilleliminatejitterduetoexternalcircumstances,whichcouldaffecttheresponsetimeofone
suchindividual,shortexecutionquitedrastically.
Serverlevelperformanceaspects
Serverlevelconfigurationsettingscanhaveabigimpactonqueryperformance,thoughitmaynotbepossibleto
predictwhichquerieswillbeaffectedmost.
AspartofyourtestingaroundtheASE15migration,capturethefollowingserverleveldata:
Runsp_sysmon regularlyandcaptureitsoutput;recommendisrunningitevery1015minuteswitha
sampleintervaltimeof1minute.
Itiscriticalthatdataiscapturedduringallthesignificantperiodsoftheapplicationprocessing.For
example:dailypeakperiods,nightly/weekly/monthlybatchcycles,MondaymorningMarketOpensetc.
Whenanalyzingthe sp_sysmon output,alsopayattentiontothefollowing:

o DataCacheusage:Reviewthecachehits,spinlockcontentionandthebufferpoolusage.
Highcountsforcachehitsand/orhighspinlockcontentionmaybeanindicationofpoorlyperforming
queries.

o CPUutilization:ReviewtheCPUcharacteristicsoftheloadi.e.howbusyarethevariousengines,how
muchtimeisspentinI/OBusy,Idlev/sCPUBusyetc.

o DeviceIOcharacteristics:ReviewtheI/Osoutstanding,I/Oscompleted/sectogetaroughideaofthe
levelofI/Osgeneratedbytheapplication/module.ItwouldalsobeinterestingtonotehowtheI/Os
aredistributedacrossthevariousdatabasedevices.IfthelayoutinthetargetASE15.0isexpectedto
change,thisinformationmaycomeinhandy.

Runsp_moni t or conf i g ' al l ' regularly(every1015minutes),andlookforconfiguration


parametersshowinganonzero'reuse',inparticularprocedurecache.Youmayalsorun
sp_moni t or conf i gwithatablenameasanadditionalparameter:thiswillcausetheresultvalues
fromsp_moni t or conf i gtobestoredinatable(whichyouhavetocreatefirst;seetheASEReference
manualfordetails).

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
27

ExampleOfASE15QueryPlanAndLavaTree

ASE15QueryPlans
EachSQLstatementiscompiledintoaqueryplan.InASE15,aqueryplanisbuiltasanupsidedowntreeof
operators:theoperatoratthetophasoneormorechildoperators.Eachofthese,inturn,canhaveoneormore
childoperatorsthemselves,andsoon,thusbuildingatreeofoperators.Theexactshapeofthetreeandthe
operatorsinitarechosenbytheASEqueryoptimizer.
Thequeryplancanberepresentedindifferentways:
set showpl an onshowsthequeryplaninthewellknownformat,showingthejoinorder,indexes
usedandI/Ostrategy.
set st at i st i cs pl ancost on(anewcommandinASE15)showsthequeryplaninaformatmore
closelyresemblingtheinternal"LavaTree".
Lastly,theGUItoolDBI SQLcandisplaythequeryplaninagraphicaltreeformat.Thisisnotdiscussed
furtherinthisdocument.
Example:setshowplan
TodisplaythequeryplanintheclassicASEformat,useset showpl an on:

set showpl an on
go

sel ect A. au_f name, A. au_l name
f r omaut hor s A, t i t l eaut hor TA
wher e A. au_i d = TA. au_i d
go

Thefollowingshowssomehighlightsfromtheresultingqueryplanoutput:

The t ype of quer y i s SELECT.



3 oper at or ( s) under r oot

| ROOT: EMI T Oper at or ( VA = 3)
|
| | NESTED LOOP J OI N Oper at or ( VA = 2) ( J oi n Type: I nner J oi n)
| |
| | | SCAN Oper at or ( VA = 0)
| | | FROM TABLE
| | | aut hor s
| | | A
| | | Tabl e Scan.
[ . . . ]
| | | SCAN Oper at or ( VA = 1)

28
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

| | | FROM TABLE
| | | t i t l eaut hor
| | | TA
| | | I ndex : aui di nd
| | | For war d Scan.
| | | Posi t i oni ng by key.
| | | I ndex cont ai ns al l needed col umns. Base t abl e wi l l not be
r ead.
| | | Keys ar e:
| | | au_i d ASC
[ . . . ]

Thequeryplanoutputasdisplayedbyset showpl an onconsistsoftwomaincomponents:
Thenamesofthequeryplanoperators,alongwithsomeadditionalinformation,toshowwhich
operationsarebeingexecutedinthequeryplan.NotethatthisoutputisverysimilartothatinASE12.x,
thoughASE15hasvariousnewoperators.
Verticalbars(the"|"symbol)withindentationarenewinASE15.Theseareaddedtovisuallyclarifythe
structureofthequeryplanoperatortree.

ThequeryplanfromtheexampleaboveindicatesthattheASEqueryoptimizerhaschosenaplanconsistingof3
operatorsundertherootoperatorEMIT.InASE15,theEMIToperatorisalwaysthetopoperator(calledthe'root'
operator)thatisresponsibleforroutingtheresultofthequerytotheclient.
TheplancontainsaNESTEDLOOPJOINoperator,withtheauthorstablesastheoutertable(sinceitcomesfirstin
thejoinorder)andthetitleauthortableasaninnertable(secondinthejoinorder).Thefirstindentedoperator
appearingbelowtheNESTEDLOOPJOINoperatoralwaysrepresentstheoutersideofthejoinandthesecond
operatoratthesamelevelofindentationistheinnersideofthejoin.
Thescanstrategyfortheauthorstableusesatablescan,whiletheinnertabletitleauthorwillbescannedbyindex
auidind.Boththeseoperatorsareshownintheshowpl anoutputasaSCANoperator.Graphically,thisqueryplan
canberepresentedbythefollowingoperatortree:

Aqueryplancanhaveanarbitrarilydeeptreeofqueryplanoperators.Eachoperatorreceivesrequestsforthe
nextrowfromitsparent(topdowncontrolflow),processestherequestandreturnstherequestedrowtoits
parent(bottomupdataflow).Theorderofexecutionofanoperatordependsthusonitsparent'salgorithmand,
recursively,ontheorderofexecutionofitsparent.
Forinstance,a"leftdeep"treeofnestedloopjoinoperatorswillstartbyscanningtheoutermosttable,whenthe
"nextrow"request,whichispasseddownontheoutersideofeachnestedloopjoin,reachestheoutermostscan.
Then,asanestedloopjoinreceivesarowfromitsouterchild,itwilldoacorrespondingscanofitsinnerside
basedonthatrow.Thenestedloopjoinwillreturn,eachtimeitsparentasksfor,itsownrowbasedonitscurrent
EMI T
NESTED LOOP J OI N
TABLE SCAN (authors) I NDEX SCAN (titleauthors using auidind)

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
29

outerandinnerchildrows.
Thefollowingexampleshowsamorecomplexqueryplan:

sel ect A. au_f name, A. au_l name, T. t i t l e


f r omaut hor s A, t i t l eaut hor TA, t i t l es T
wher e A. au_i d = TA. au_i d and T. t i t l e_i d = TA. t i t l e_i d

Inthiscase,EMITasksitsMERGEJOINchildforarow,whichinturnasksits2childrenforrowsattemptingto
satisfythemergeclause.
TheupperMERGEJOIN'souterchild,SORT,isablockingoperator.Thismeansitneedstoconsumeitsentireinput
beforereturningitsfirstrow(sincethefirstrowinthesortedresultcouldbelastrowreturnedbyitschild).SORT
willthusaskitschild,thelowerMERGEJOIN,onebyoneforallofitsrowsandwillsortthem(ifpossiblein
memory,overflowingifneededtoaworktable)andonlythenwillitreturnitsfirstrowtotheuppermostMERGE
JOIN.
ToproducetheserowsateachrequestofitsSORTparent,thelowerMERGEJOINwillaskfornewrowsfromits
outerand/orinnerchildren,dependingonthecurrentvaluesinthemergecolumns,untiltheequijoinclauseis
satisfiedandaMERGEJOINrowisreturned.
AsthesechildrenareINDEXSCANsusingindexesontheequijoincolumns,therowsarereturnedordered,as
requiredbytheMERGEJOINalgorithm,andnosortisdeeded.
TheupperMERGEJOINwillhavethesamebehavior,askingSORTandINDEXSCAN(titles)forrowsandreturnat
eachEMITrequestarowwheretheequijoinclauseissatisfied.
Finally,therootoperatorEMITsendseachfinalresultsetrowbacktotheclientapplicationthatinvokedthequery.
Notethatitisnotguaranteedthateachoperatorinthetreeisexecuted.Forexample,afilterconditionmay
evaluateinsuchawaythatnorowscaneverresultfromasubtree,whoseoperatorsmaythereforenotbe
executedatall.Formoreinformationabouttheoperatorsandtreestructure,seetheASEPerformanceand
TuningGuide,volume"QueryProcessingandAbstractPlans".

EMI T
MERGE J OI N
I NDEX SCAN (titleauthor) I NDEX SCAN (authors)
I NDEX SCAN (titles)
SORT
MERGE J OI N

30
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

Example:plancostandLavaTree
AusefulnewfeatureinASE15isthepl ancost option,whichdisplaysthequeryplaninasemigraphicaltree
formatmorecloselyresemblingtheinternalrepresentation,knownasthesocalled"LavaTree"(whichgotits
namesincedatarowsflowupwardthroughthetreeoperatorstoasinglepoint,similartolavainavolcano).
Thepl ancost optioncanbeturnedonusingthefollowingcommand:

set st at i st i cs pl ancost on
go

- - - Run your quer y her e

Oneapplicationofthiscommandistocomparetheestimatedandactualcostsinaqueryplan.Itcanbeauseful
toolfordiagnosingqueryperformanceproblems.Foreachoperator,theLavaTreeoptionshowstheestimated
(el:)andactual(l:)numbersoflogicalI/O,estimated(ep: )andactual(p: )physicalI/O,estimated(er : )and
actual(r:)rowcountsandactualCPUticks(cpu: ).Inaddition,executionoperatorsthatdoasortorahashbased
operationwillalsoreportthenumberofprivatebuffersusedforthatoperation(buf ct : ,notshowninthe
examplebelow).Sincenotallofthesequantitiesapplytoeachtypeofoperator,asubsetmaybeshown.Forsub
optimalqueryplans,thisinformationcanbeusedtoverifythattheoptimizer'sestimatesaresound.
Ifthejoinqueryfromthepreviousexampleisrun,yougetoutputthatlooksliketheoperatortreeshowninthe
previousdiagramwithadditionalannotationsshowingtheactualversusestimatednumbers.Theestimated
numbersarethosecomputedbythequeryoptimizerandtheactualnumbersaretheresultoftheactualquery
execution.Thisisagoodwaytovalidatehowclosetheoptimizer'scostmodeliswithrespecttotheactual
numbers.

==================== Lava Oper at or Tr ee ====================

Emi t
( VA = 6)
r : 25 er : 342
cpu: 0

/
Mer geJ oi n
I nner J oi n
( VA = 5)
r : 25 er : 342

/ \
Sor t I ndexScan
( VA = 3) t i t l es_672002394 ( T)
r : 25 er : 25 ( VA = 4)
l : 6 el : 6 r : 18 er : 18
p: 0 ep: 0 l : 2 el : 3
cpu: 0 buf ct : 24 p: 0 ep: 3
/
Mer geJ oi n
I nner J oi n
( VA = 2)
r : 25 er : 25
/ \

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
31

I ndexScan I ndexScan
aui di nd ( TA) aut hor s_57600205 ( A)
( VA = 0) ( VA = 1)
r : 25 er : 25 r : 23 er : 23
l : 1 el : 2 l : 1 el : 2
p: 0 ep: 2 p: 0 ep: 2

Fromtheaboveoutput,someinterestingobservationscanbemade.ThebottomleftI ndexScanoperator(on
thetitleauthorstable)hasanestimatedrowcount(er:)of25andtheactualrowcount(r:)is25aswell;thismeans
thattheoptimizer'sestimatewascorrect.
However,therowcountestimatesforthetopMer geJ oi n(VA=5)arecompletelyoff,astheoptimizer's
estimateis342buttheactualrowcountis25.Itmaybepossibletorectifysomeoftheinaccuraciesinthe
optimizer'sestimatesbymakingsurethatthestatisticsareuptodate,orbyincreasingthenumberofstepsinthe
histogram.Ifnohistogramsexistonthejoincolumns,asindicatedbyset opt i on show_mi ssi ng_st at s
on,creatingthosehistogramsmayimprovetheoptimizer'sestimates.
Notethatcomparingtheoptimizerestimatesandactualsisnotanexactscience:whentheestimatedrowcountis
25andtheactualrowcountis30,thatshouldnotnecessarilybetakenasanindicationthattheoptimizer's
estimatesareincorrect.Orderofmagnitudedifferences,suchas25vs.342intheexampleabove,arewhatyou
shouldlookfor.
Also,notethatthetablenameisnotdisplayedforI ndexScanoperatornodes,butonlythenameoftheindex.If
itisunclearwhichtableisassociatedwithanoperatornode,therearevariouswaystofindthisout:
Thenameoftheindexmayuniquelyidentifythetable

Ifacorrelationnamewasusedinthequery,thisisshownintheoperatornode.Forthebottomleft
I ndexScanoperator,"(TA)"refersto"t i t l eaut hor TA"fromtheoriginalSQLquery.

Theindication"(VA=n)",wheren=0,1,2,,isshownbothintheLavaTreeandintheshowpl anoutput,and
uniquelyidentifieseachoperatornode.

32
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

CapturingApplicationSQL
Inthecontextofmonitoringortroubleshootingperformanceissues,itisoftenusefultodeterminetheexactSQL
queriesanapplicationissubmittingtotheASEserver,alongwithsomeperformancemetricssuchaselapsedtime
orI/Oconsumption.ThisinformationcanbeusefulbothbeforeandaftermigratingtoASE15,forexampleinthe
contextofperformancetestingaroundtheASE15upgrade(seepage22).
FromthesideoftheASEserver,thiscanbedoneinanumberofways,dependingonyourASEversion:
Auditing
MDAtables(12.5.0.3orlater)
Applicationtracing(15.0.2orlater)
Abstractplancapture(12.0orlater)orquerymetricscapture(15.0orlater)
MonitorServer
SQLinterceptiontools,likeRibo(see$SYBASE/ j ut i l s- x_y)or3
rd
partyproducts

Wewilllookatthefirstfourinalittlemoredetailbelow.
Auditing
Withauditing,youcanenablethe'cmdt ext 'auditingoption(withsp_audi t ).Thiswillcapturetheclient
submittedSQLtextinthesybsecur i t ydatabase.Youwillneedtoextractthecapturedtextfromthisdatabase.
NoperformancemetricsrelatedtotheSQLarecaptured.
SeetheASESystemAdministrationGuidefordetailsonsetupandconfigurationofauditing,andforinformation
aboutaccessingthecaptureddata.
MDAtables(12.5.0.3)
InASE12.5.0.3orlater,theMDAtables(alsoknownas'monitoringtables')canbeusedtocapture,amongother
things,theSQLtextsubmittedbyclientapplications.Forthis,usetheMDAtablemast er . . monSysSQLText .
Associatedexecutionmetrics(executiontime,I/Ocounts,andmore)canbefoundin
mast er . . monSysSt at ement .
Whenlookingforslowrunningorresourceintensivequeries,youcanfilterthecontentsofmonSysSt at ement
by,forexample,lookingfor:
queriesrunninglongerthan,say,10seconds(i.e.10000milliseconds):
filterondat edi f f ( ms, St ar t Ti me, EndTi me) > 10000

queriesusingmorethanacertainnumberoflogicalI/Os,say,20000:
filteronLogi cal Reads > 20000

NotethatmonSysSQLText andmonSysSt at ement haveaconfigurablebutlimitedsize,sotheyshouldbe


queriedregularlytoextractthecapturedinformationandstorethisinapermanent,regulartable.Ifthisisnot
donefrequentlyenough,orifthenumberofsubmittedqueriesisveryhigh,someofthesubmittedSQLmaynotbe
capturedthroughtheseMDAtables.
ForhelpwithinstallingandusingtheMDAtablespleaserefertoeitherofthefollowing:
theASEPerformanceandTuningGuide,volume"MonitoringandAnalyzing",chapter"MonitoringTables"

membersofISUGcanusethisinformationavailableattheISUGwebsite:

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
33

ht t p: / / my. i sug. com/ p/ do/ sd/ si d=13&f i d=9&r eq=di r ect



ApplicationTracing(15.0.2)
InASE15.0.2,youcanintercepttheSQLqueriessenttotheASEserverbytheclientapplicationbymeansofanew
featurenamedapplicationtracing.ThiscanbeusedtoidentifyquerieswithlongrunningtimesorhighI/O
consumption.
SupposeanapplicationhasconnectedtoASEassession#24,andyouwanttoseethequeriessubmittedthrough
thisconnection.Thiscanbedoneasfollows(assumingASErunsonUnix/Linux):

set t r acef i l e ' / t mp/ my_di r / appt r ace. 24. out ' f or 24
go
set show_sql t ext on
set st at i st i cs i o, t i me, pl ancost on
set showpl an on
go

Asofthismoment,allSQLsubmittedbysession24willbewrittentothefile
' / t mp/ my_di r / appt r ace. 24. out ' ,accompaniedbytheoutputfromset showpl an andset
st at i st i cs.Notethattheset commandsaboveapplytosession24,andnottothesessionexecutingthese
statements,aswouldbethenormalsemantics.
Whileyoursessionhasinitiatedapplicationtracingonanothersession,itisimportanttoobservethefollowing:
Donotrunanyothercommandsinthissessionuntilyouhavedisabledthetracingagain(seebelow).
Onceapplicationtracingisenabled,donotrunotherset commandsthanthoseshownabove.
Donotdisconnectyoursessionuntilyouhavedisabledthetracingagain;thismaycause showpl anoutput
tobesenttosession24,eventhoughthatsessiondidnotrunset showpl an onitself.
Donotleavetracingenabledforlongperiods,toavoiddisconnectslikementionedinthepreviousbullet.

Todisableapplicationtracing,firstswitchallset commandsoffagainandthenstopthetracing:

set show_sql t ext of f


set st at i st i cs i o, t i me, pl ancost of f
set showpl an of f
go
set t r acef i l e of f
go

Youcannowaccessthefile' / t mp/ my_di r / appt r ace. 24. out ' andanalyzeitscontents.


Inpractice,itmaybemostpracticaltouseapplicationtracingforshortintervalsratherthanprolongedperiodsof
time,sincetheamountofdatawrittentothetracefilecanbesignificant.Formoreinformationaboutapplication
tracing,pleaseseeaseparatewhitepaperavailableontheSybasewebsiteat
http://www.sybase.com/detail?id=1052835.

34
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

AbstractPlanCapture/QueryMetricsCapture
SinceASE12.0,abstractplancapturecanbeusedtointerceptclientsubmittedSQLtext.Thistextisstoredinthe
sysquer ypl anstablealongwithitsabstractqueryplan.Thecapturedquerytextcanberetrieveddirectlyfrom
thistable.InASE15,thenewfeatureofquerymetricscaptureusesthesameunderlyingmechanismtocapture
executionmetricssuchasI/Ocountsandexecutiontimes,alongwiththeSQLtext.Thesemetricsarealsostoredin
sysquer ypl ans,butshouldbeaccessedthroughaviewnamedsysquer ymet r i cs.
Apotentialdisadvantageofthesefeaturesisthatthecaptureddataisstoredinthesysquer ypl anstableinthe
session'scurrentdatabaseatthemomentthequerywasexecuted.Thismeansthatthecapturedquerytextcould
endupin,forexample,t empdb,ifthatwasthesession'scurrentdatabase,eventhoughallqueriedtablesmay
resideinotherdatabases.
Formoreinformationaboutquerymetricscapture,seetheASEPerformanceandTuningGuide,volume"Query
ProcessingandAbstractPlans".

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
35

InformationToCaptureBeforeContactingSybase
TechSupport
BeforecontactingTechSupport,itisoftenusefultogatheradditionaldiagnostics.Thisisespeciallytruewhenthe
problemisreproducible.Thissectionwilldiscusssomepotentialproblemareasanddocumentthecollection
procedures.
701Errors
Whenaregularquery(i.e.notupdat e i ndex st at i st i cs)runsintoa701error,thisindicatesthatASE
exhaustedtheprocedurecachespace.Ifyouarerunningwiththedefaultprocedurecachesize,youshould
increasethisandtryagain.Thegeneralguidelineistoinitiallytake23timesthesizeofyour12.5.xprocedure
cache,thoughinsomecases,especiallywhenusingtheoptimizationgoalal l r ows_dss,yourprocedurecache
mayneedtobelarger.
Ifincreasingtheprocedurecachehasnotresolvedthe701errorandyoucannotisolatetheproblem,thenyou
shouldsetupaConfigurableSharedMemoryDump(CSMD).Thefollowinginstructionsareused.

sp_conf i gur e ' dump on condi t i ons' , 1


go
sp_shmdumpconf i g ' add' , ' er r or ' , 701, 1, ' / opt / my_di r ' - - Uni x
go
sp_shmdumpconf i g ' add' , ' er r or ' , 701, 1, ' D: \ my_di r ' - - Wi ndows
go

Thesecondinstructionaddstheerror701conditiontoinitiateamemorydump.Thefourthparameterindicates
thenumberofmemorydumpstocapture,inthiscase1.ASEwillnotcaptureadditionalmemorydumpsonthis
conditionuntilASEisrecycledorthecounterismanuallyreset.Thelastparametershownisthenameofa
directorytoholdthememorydump.Notethatthefilesystemonwhichthedirectoryresidesshouldhaveenough
freespacetoholdthememorydumpfile,whichcanbelarge.
Youcanverifythedumpconditionscurrentlydefinedbyrunningsp_shmdumpconf i gwithoutanyparameters.
Thiswillalsoshowanestimatedsizeofthememorydumptobecaptured.Youshouldverifythatthediskspace
availableinthedirectoryislargerthantheestimatedmemorydumpfilesize.
Afilenamewillautomaticallybegeneratedthatincludesthedateandtimeofthememorydump.Oncethe
memorydumphasbeencaptured,youcanremovethisconditionusing

sp_shmdumpconf i g ' dr op' , ' er r or ' , 701


go

IfyouwishtostopallCSMDs,configure' dump on condi t i ons' to0.
Oncethememorydumphasbeencaptured,youshouldopenacasewithTechSupportanduploadthememory
dumptotheftpsite(forinstructions,seepage39).
YoushouldalsoincludetheoutputfromthefollowingSQLstatements.TheseusetheMDAtableswithinASE,
whichisautomaticallysetupwhenrunningthei nst al l mast er scriptinASE15.0.2orlater.EarlierASEversions
needtorunthei nst al l mont abl esscript.SeeexistingdocumentationforconfiguringtheMDAtables.

sel ect * f r ommast er . . monPr ocedur eCacheMemor yUsage

36
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

sel ect * f r ommast er . . monPr ocedur eCacheModul eUsage


go

Note:thecontentsoftheMDAtablesshownabovedonotcontainanyusefulinformationforcustomers.
Bydefault,ASEwillsendthe701errormessagetotheclient.Youshouldconsidergettingthismessagealso
reportedintheerrorlog,sothatyoucantrackhowoftenitishappening.
Thiscanbedoneasfollows:

sp_al t er message 701, ' wi t h_l og' , t r ue



PerformanceProblemwithaLimitedNumberofQueries
Ifalimitednumberofqueriesarenotperformingwellduetosuboptimalqueryplansorsuboptimalresource
consumption,youmaywanttoconsiderinstallingthelatestASE15.0.xreleaseonyourdevelopmentservertosee
iftheproblemstillexists.Iftheproblemstillexists,orifyoucannottestthelatestASErelease,thenareproduction
shouldbecollectedandsubmittedtoSybaseTechSupport.IfyoucannotsendareproductiontoTechSupport,you
shouldusethefollowingstepstogatherdiagnostics:

1. Createascriptfile(here,namedsql.txt)containingthesecommands:

sel ect @@ver si on


go
sel ect @@opt goal
go
sp_cacheconf i g
go
sp_conf i gur e ' nondef aul t ' - - onl y i f you' r e r unni ng 15. 0. 2 or l at er !
go
dbcc t r aceon( 3604)
set showpl an on
set st at i st i cs t i me, i o, pl ancost on
set opt i on show l ong
go
<your quer y t ext >
go

2. Runsql . out usingi sql andcapturetheoutputinafile(WARNING:theoutputfilecanpotentiallybe
verylargepotentiallyGigabytesforcomplexquerieswithmanytables,underal l r ows_dss):

i sql Usa P your passwor d - S YOUR_SERVER_NAME i sql . t xt o sql . out

ThefollowinginformationshouldalsobeincludedsothatTechSupportcanattemptareproduction:

Thefilessql . t xt andsql . out .Ifapplicable,includeacasewiththe'fast'queryplan


(sql . f ast . t xt )andonewiththe'slow'queryplan(sql . sl ow. t xt )andcorrespondingfiles

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
37

sql . f ast . out ,sql . sl ow. out

DDLforthebasetable(s)andindex(es);thiscanbegeneratedwiththeddl genutility

Simulatestatisticsoutputforthebasetable(s)viaopt di ag:

opt di ag st at i st i cs si mul at e <f ul l y- qual i f i ed- t abl e- name> - Usa


- P your passwor d - S YOUR_SERVER_NAME - o <out put - f i l e>

AcopyoftheASEconfigurationfile,or,in15.0.2,theoutputofsp_conf i gur e ' nondef aul t '

Ifthequeryisusingview(s)orstoredprocedure(s),thenalsoincludetheirSQLsourcecodeasobtainedby
def ncopyorddl gen.

Theoutputofsp_moni t or conf i g ' al l ' .

SystemWidePerformanceProblemsorHighCPUUsage:step1
IftheperformanceofASE,ataserverwidelevel,isnotacceptable,andyouarerunning15.0.2ESD#3orlater,
pleasefollowthestepsbelow.ThisisalsorequiredwhenASEisexperiencingunusuallyhighlevelsofCPUusage
withoutaclearcause.
ThisremedyisrelevantmostlywhenrunningamultiengineASEserver;forasingleengineASEserverthis
proceduremaynotyieldasmucheffect.Pleaseenablethistraceflagonlyasdescribedbelow:

ShutdownASEandrestartitwithtraceflag757intheRUN_serverfile(i.e.addT757)

IfASEcannotberebooted,youcantryrunningthefollowingdbcccommandsinstead.Itshouldhowever
benotedthatthismayhavelesseffectthananASEreboot:

dbcc t r aceon( 757)


go
dbcc pr oc_cache( f r ee_unused)
go

Broadlyspeaking,theeffectofthistraceflagisthatallocation/deallocationalgorithmsintheprocedurecache
behavedifferentlyonsomepoints.
PleasereporttoTechSupport(byopeningacase)whetherthesestepsmakeadifferencetothesituationinyour
ASEserver.Whenreportingthisinformation,pleaserefertothiswhitepaperandrequestyourcasetobelinkedto
CR484362;pleasealsoindicatewhetheryourebootedASEornot.
NotethatthistraceflagshouldnotbeusedinanyASEversionsearlierthan15.0.2ESD#3.

38
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

SystemWidePerformanceProblemsorHighCPUUsage:step2
IftheperformanceofASE,atasystemwidelevel,isstillnotacceptableafterthestepabove,SybaseTechSupport
needsmoreinformationabouthowASEisspendingitsprocessingtime.
Since,incaseslikethese,thereisnoerrorconditiontoconfigureamemorydumpfor,youwillneedtocapturea
ManualSharedMemoryDump.Todothis,youneedtouseSybMon,whichisanundocumenteddiagnostictool.

NOTE:THEINFORMATIONOBTAINEDBYTHEFOLLOWINGPROCEDUREISUSEFULFORSYBASETECHSUPPORT
ONLYANDDOESNOTCONTAINANYINFORMATIONTHATCANBEUSEDBYCUSTOMERS.STRICTLYNOOTHER
COMMANDSSHOULDBEUSEDBYCUSTOMERSOTHERTHANASINSTRUCTEDBYSYBASETECHSUPPORTAND
THISDOCUMENT.PUBLICDISCUSSIONSABOUTSYBMON,SUCHASINNEWSGROUPS,SHOULDBEAVOIDED
SINCEINCORRECTINFORMATIONMAYBECOMMUNICATEDTHATMAYBEHARMFULTOYOURASESERVER!
USINGSYBMONOTHERTHANASINSTRUCTEDBYSYBASETECHSUPPORTANDTHISDOCUMENT,ORFOR
DIFFERENTPURPOSES,ISENTIRELYATYOUROWNRISK.

SybMonisstartedasshownbelow.YoumustusethesameOSloginthatwasusedtostartASEinordertoavoid
permissionproblems.Notethatthepasswordisnotthe'sa'loginpassword,butaspecialpasswordthatcanonly
beobtainedfromSybaseTechSupport.PleasecontactTechSupportifyouneedtorunthisstep.
Pleasenote:itisessentialthatthefollowingprocedurebeperformedwhenperformanceproblemsareactually
occurring,sinceonlyatthatmomentcantherightinformationbegatheredthatisneededtodiagnosetheissue.
OnUnix:
dat aser ver X P password D<pat h t o di r ect or y wi t h . kr g f i l e>

OnWindows:
sql sr vr . exe X P password - D<pat h t o di r ect or y wi t h . kr g f i l e>

Ifyouhaveonly1krgfileinthedirectory,ASEwillautomaticallyattachtothesharedmemoryregionand,ifthe
serverisnamed"PROD1",youwillseeapromptlikethis:
PROD1: act i ve>

Ifyouhavemultiple.krgfiles,youwillneedtoattachtothecorrectserver'ssharedmemoryusingthecommand:
at t ach <ser ver name>

Onceyouhaveattachedtothesharedmemoryregion,runthefollowingcommands:
l og on <not - yet - exi st i ng f i l e>
set di spl ay of f
sampl e count =150 i nt er val =200
set di spl ay on
l og cl ose
qui t

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
39

Theoutputwillbeinthefilespecifiedinthe"logon"command.
Inaddition,youshouldrunsp_sysmon(fora1or2minuteinterval).SubmittheoutputfrombothSybMonand
sp_sysmontoTechSupport.
UploadingdiagnosticstoSybaseTechSupportthroughFTP
Oncetherequireddiagnosticshavebeencaptured,firstopenacasewithSybaseTechSupport.Then,usethe
followinginstructionstouploaddiagnosticstotheSybaseftpsite:

f t p f t p. sybase. com
user : anonymous
pwd: <your emai l addr ess>
cd / pub/ i ncomi ng/ wcss
mkdi r <your case number >
cd <your case number >
bi n
put <memor y dump f i l ename>
qui t

40
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009

ConclusionsAndRecommendations
Themainconclusionsandrecommendationsfromthisdocumentarethefollowing.Pleaserefertothementioned
pagesfordetails:
ThequeryoptimizerinASE15issignificantlydifferentfromtheoptimizerinpriorASEreleases,offering
greatperformancebenefits,butalsointroducingnewtuningaspects(seepages321).

ForcustomerswhoprefertolimittherequiredtestingeffortforupgradingtoASE15,'Compatibility
Mode'maybeusedinASE15.0.3ESD#1.However,thismayresultinnotbeingabletobenefitfromthe
queryprocessingenhancementsinASE15(seepage12).

DonotinitiallyuseparallelprocessingwhenupgradingtoASE15,evenwhenparallelismwasusedinASE
12.x.ASE15maywelldeliverbetteroverallperformanceinserialmodethanpre15inparallelmode,
especiallyforDSStypequerieswithoptimizationgoalal l r ows_dss(seepage8).

MoreprocedurecachewillbeneededinASE15thanin12.5;expecttorequire2to3timesasmuch
procedurecacheasinpre15(seepage14).

UptodatestatisticsaremorecriticalforgoodperformanceinASE15thaneverbefore.Preferably,run
updateindexstatistics,andifneeded,configureadditionalhistogramsteps(seepage21).

Sybaserecommendstestingyourapplicationsandqueriesextensivelybeforeupgradingyourproduction
systemtoASE15.Forbestresults,testonarealisticproductiondatabasewithactualproductionqueries,
usingrealisticworkloadlevelsandreallifeconcurrency(seepage22).

Whenencounteringunexpectedqueryprocessingissues,upgradetothelatestESDavailable;Sybaseis
makingcontinuousimprovementsandyourissuemayalreadyhavebeenfixed(seepage12).

EnjoySybaseASE15!

SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
41

ReferenceDocuments

Technicalwhitepaper"ChangestoscopeandsemanticsofsessionleveloptimizationsettingsinASE15.0.2":
http://www.sybase.com/detail?id=1056206

Technicalwhitepaper"Using'CompatibilityMode'InASE15.0.3ESD#1ForASE15Migration":
http://www.sybase.com/detail?id=1063556

Technicalwhitepaper"RequiredSQLcodechangeswhenmigratingtoASE15":
http://www.sybase.com/detail?id=1063534



















































CONTACTINFORMATION

ForEurope,MiddleEast,
orAfricainquiries:
+(31)346582999

ForAsiaPacificinquiries:
+85225068900(HongKong)

ForLatinAmericainquiries:
+7707773131(Atlanta,GA)







SYBASE,INC.
WORLDWIDEHEADQUARTERS
ONESYBASEDRIVE
DUBLIN,CA945687902USA
Tel:18008SYBASE

www.sybase.com


Copyright2009Sybase,Inc.Allrightsreserved.UnpublishedrightsreservedunderU.S.
copyrightlaws.Sybase,andtheSybaselogoaretrademarksofSybase,Inc.oritssubsidiaries.
Allothertrademarksarethepropertyoftheirrespectiveowners.indicatesregistrationinthe
UnitedStates.Specificationsaresubjecttochangewithoutnotice.2/09.

You might also like