Professional Documents
Culture Documents
ASE15 Optimizer Best Practices
ASE15 Optimizer Best Practices
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
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:
Timehowlongittakesbeforetherunhascompleted.
Repeatthiswiththeoptimizationgoalabovechangedtoal l r ows_mi xandal l r ows_dss,sothatyouhave
threeoutputfilesofqueryplanoutput.
Fromthecompletiontimesofthedifferentruns,itmaybeimmediatelyapparentwhichoptimizationgoalprovides
thebestresultoverall,andthatmightbeacandidatefortheserverwideoptimizationgoalsetting.
However,itwillbeinterestingtocounthowmanytimeseachjointypehasbeenchosen.Thiscanbedonequickly
withgr epforeachoftheoutputfiles:
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 :
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.
Ifyoursystemseemstobeconsuminganunreasonableamountofspaceint empdb,youcanusethe
MDAtablestoseeifoneparticularsessionconsumesalotofspaceinaworktable.
AssumingtheMDAtablesareenabled,runthefollowingquery:
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
11
remedyiscreatingmultipletemporarydatabasesandassigningthesetospecificusers.SeetheASE
documentationforfurtherdetailsonthesefeatures.
Ifyouencounteraslowqueryandyoususpectthatreformattingiscausingthesuboptimalperformance,
firstfollowtherecommendationswithrespecttostatistics(seepage21).Ifthereformattingpersistsand
performanceremainsunsatisfactory,youcanverifywhetherdisablingreformattingimprovesthingsas
follows:
Underal l r ows_dss,ifyouencounteranunreasonablyslowquery,orifthequeryrunsintoa701error
duringoptimization,firstfollowtherecommendationswithrespecttostatistics(seepage21).Iftheissues
persist,tryifthefollowingsolvestheproblem:
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= <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:
18
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
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".
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.
Thenumberofhistogramstepsestablishedatthispointisthetargetnumberofstepsforthehistogram.
Intheoptdiagoutput,thisisdisplayedas"Requestedstepcount:".
20
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
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:
Ifyoususpectsuboptimalqueryplansaregenerated,considerincreasingthenumberofhistogramstepsfor
thetablesinvolved.
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):
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.
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:
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:
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
membersofISUGcanusethisinformationavailableattheISUGwebsite:
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
33
Todisableapplicationtracing,firstswitchallset commandsoffagainandthenstopthetracing:
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.
Thesecondinstructionaddstheerror701conditiontoinitiateamemorydump.Thefourthparameterindicates
thenumberofmemorydumpstocapture,inthiscase1.ASEwillnotcaptureadditionalmemorydumpsonthis
conditionuntilASEisrecycledorthecounterismanuallyreset.Thelastparametershownisthenameofa
directorytoholdthememorydump.Notethatthefilesystemonwhichthedirectoryresidesshouldhaveenough
freespacetoholdthememorydumpfile,whichcanbelarge.
Youcanverifythedumpconditionscurrentlydefinedbyrunningsp_shmdumpconf i gwithoutanyparameters.
Thiswillalsoshowanestimatedsizeofthememorydumptobecaptured.Youshouldverifythatthediskspace
availableinthedirectoryislargerthantheestimatedmemorydumpfilesize.
Afilenamewillautomaticallybegeneratedthatincludesthedateandtimeofthememorydump.Oncethe
memorydumphasbeencaptured,youcanremovethisconditionusing
36
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
1. Createascriptfile(here,namedsql.txt)containingthesecommands:
SybaseASE15BestPractices:QueryProcessing&Optimization
Version1.1May2009
37
DDLforthebasetable(s)andindex(es);thiscanbegeneratedwiththeddl genutility
Simulatestatisticsoutputforthebasetable(s)viaopt di ag:
Ifthequeryisusingview(s)orstoredprocedure(s),thenalsoincludetheirSQLsourcecodeasobtainedby
def ncopyorddl gen.
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:
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.