7/29/2019 Diagnosis Performance
1/44
DiagnosingSQL
PerformanceProblems
KarenMorton
Sr.TechnicalConsultant
1
AnEmbarcaderoOracleCommunityWebinar
7/29/2019 Diagnosis Performance
2/44
karenmorton.blogspot.com
karen_morton
7/29/2019 Diagnosis Performance
3/44
3
July31
DiagnosingSQLPerformanceProblems
August29
MakingSQLPerformanceSoluGonsSGck
September26
MakingImpaculPerformanceChanges
7/29/2019 Diagnosis Performance
4/44
4
Whensomethingsonfire,
whatdoyoudo?
7/29/2019 Diagnosis Performance
5/44
5
Put.
It.
Out.
7/29/2019 Diagnosis Performance
6/44
Timeisaluxury.
6
7/29/2019 Diagnosis Performance
7/44
PlanofAack
EvaluatethesituaGonatherdata&determineproblemscope
Propose&eliminate(postpone)opGonsArethereanyquickfixes?
ImplementbestopGonBest=quickestalternaGvetoachievecorrecGon
ValidatesoluGon7
7/29/2019 Diagnosis Performance
8/44
8
Whatalertedtheissue?
7/29/2019 Diagnosis Performance
9/44
Usercomplaintsmayormaynot
beobviousinmonitoringtools.
9
7/29/2019 Diagnosis Performance
10/44
10
Howdoyoumonitor
andanalyzedatabase
acGvity?
7/29/2019 Diagnosis Performance
11/44
Doyouhavelicensesfor
ASH&AWRuse?
11
Ifnot,doyouuseS-ASHor
Statspackor3rdpartyproduct?
S-ASHissimulatedASH
(homegrownorseewww.ashmasters.com).
7/29/2019 Diagnosis Performance
12/44
Remember:DiagnosGc&TuningPacks
neededtolegallyuseASH/AWR.
12
WhatisincludedwithvariousOracleManagementPacks?
hp://docs.oracle.com/cd/E11882_01/license.112/e10594/opGons.htm#CIHIHDDJ
7/29/2019 Diagnosis Performance
13/44
TopSQL(byelapsedGme)
13
7/29/2019 Diagnosis Performance
14/44
TopSQL(ASH)
14
7/29/2019 Diagnosis Performance
15/44
EvaluatetheSituaGon
DetermineifstressinsideoroutsidethedatabaseOSresources?Networkresources?Storageresources?
etanaccuratedescripGonoftheproblemWhatistheproblemscope?WhatistheexpectedvscurrentresponseGme(s)?Doestheproblemoccurrandomlyorrepeatedly?Whathaschanged?
15
DBAs
Developers
SANAdmins
NetAdmins
OSAdmins
Managers
Users
7/29/2019 Diagnosis Performance
16/44
Nothing
has changed!
16
But
7/29/2019 Diagnosis Performance
17/44
If
nothingchanged,whyissomethingdifferent?
17
7/29/2019 Diagnosis Performance
18/44
Ch-ch-ch-ch-changes
StaGsGcsDatavolumeDatadistribuGon
Cardinalityfeedback ParametersOutsidethedatabase
18
homagetoDavidBowie
SQLisnotlikely
theproblemifthe
changeisoutside
thedatabase.
7/29/2019 Diagnosis Performance
19/44
SQLProblem?
19
SameexecuGonplanonbothnodes.
7/29/2019 Diagnosis Performance
20/44
21
OutsidetheDatabase?
7/29/2019 Diagnosis Performance
21/44
StaGsGcs?
22
update t_cust_acct_offr_pndg_trckg!set prcss_flg = Y!
where bat_job_exec_trckg_id = :B1!and cust_acct_offr_trckg_id = :B2 ;!
Uniqueindexavailableon
thesecolumns
Processwouldexecutethisupdateover1.5millionGmes.
TotalesGmatedGmetocomplete~500hours.
LogicalIOpersecondover111K
7/29/2019 Diagnosis Performance
22/44
23
Aerstatscollected,
jobcompletedin40minutes.
ResponseGmeforsingleexecuGondroppedfrom1.3to.002seconds.
LogicalIOperseconddroppedfromover111Kto933.
7/29/2019 Diagnosis Performance
23/44
24
Statscollectedat1%usingFORALLCOLUMNSSIZE254
7/29/2019 Diagnosis Performance
24/44
25
Statsre-collectedwithauto_sample_sizeusingFORALLCOLUMNSSIZEAUTO
Aerstatsre-collected,
responseGmedroppedfrom43minutesto.01second.
LIOdroppedfrom4.6millionto4
7/29/2019 Diagnosis Performance
25/44
OtherstaGsGcsissues
CollecttoofrequentlyEvenminorchangecanresultinbigplanchanges
Collecttoomanyhistograms(ornotenough)ColumnswithhundredsofdisGnctvalues
DynamicsamplingdisabledDefaultsused
26
7/29/2019 Diagnosis Performance
26/44
QuickStaGsGcsFixes
Collectonneededobjects!dbms_stats.gather_table_stats!
Reverttopreviousstatsdbms_stats.restore_table_stats!
27
7/29/2019 Diagnosis Performance
27/44
CardinalityFeedback
ComparescardinalityesGmatestoactualrowcounts
Ifenoughdifferencefound,opGmizerappliesfudgefactortocorrecttheesGmate
OPT_ESTIMATEhint SomeGmesesGmatesimprovebutresponseGmedecreases
Controlledby_optimizer_use_feedback!28
Seehp://kerryosborne.oracle-guy.com/2011/07/cardinality-feedback/
7/29/2019 Diagnosis Performance
28/44
Example
29
CardinalityFeedback!
7/29/2019 Diagnosis Performance
29/44
UnstablePlans(AWR)
30
7/29/2019 Diagnosis Performance
30/44
QuickCFFixes
TurnoffCF(sessionorinstancelevel)!_optimizer_use_feedback = FALSE!
UseSQLProfiletoreplacebadplanwithgood!
UsehintonsingleSQLselect /*+
opt_param(_optimizer_use_feedback
false) */ !31
7/29/2019 Diagnosis Performance
31/44
Parameters
opGmizer_index_cost_adj opGmizer_index_caching db_file_mulGblock_read_count pga_aggregate_target cursor_sharing
32
Watchoutforhiddenparametersthathavebeenchanged!
7/29/2019 Diagnosis Performance
32/44
QuickParameterFixes
JustsayNo!Onlychangeaparameteraercarefuland
comprehensivetesGng
Setbacktodefault UseSQLProfiletoreplacebadplanwithgood!
Useopt_paramhintforindividualSQLtooverrideeffectsifpossible
33
7/29/2019 Diagnosis Performance
33/44
34
HowSQLiswrien
isnottypicallytheproblem
whenperformancedegradeswithouta
planchange.
CheckAWRorStatspackhistorytodetermineifplanchanged.
7/29/2019 Diagnosis Performance
34/44
CheckAWRforExecuGonInfo
35
7/29/2019 Diagnosis Performance
35/44
3MostCommonRewriteReasons
QuerytransformaGonproblems DatatypeoddiGesorcomplexexpressions Proceduralvsset-basedapproach
37
7/29/2019 Diagnosis Performance
36/44
QueryTransformaGon
DevelopersusuallywriteSQLinstylesimplesttounderstand
Notnecessarilythemostefficient OraclerewritesSQLforbeerperformance TransformaGonscanbeseenintheexecuGonplan(reverseengineertheplantotheSQL)
TransformaGonbenefitscanbepreventedorreducedbycertaintechniques
DISTINCT,ROUPBY,outerjoins,etc38
7/29/2019 Diagnosis Performance
37/44
Datatypes&Expressions
Choosingthewrongdatatypeforacolumn
Usingcomplexexpressionsinpredicateswith/withoutproperindexing(FBI)39
SQL> select '20111231' - '20111201' from dual ; 30!!SQL> select '20120102' - '20111231' from dual ; 8871!!SQL> select to_date('20120102','yyyymmdd') !
to_date('20111231','yyyymmdd') from dual ; ! !2!
WHERE my_func1(my_func2(col)) = col . . .!!
7/29/2019 Diagnosis Performance
38/44
ProceduralSQL
40
Listofemployeeswhospentthesamenumberofyearsineachjobtheyheld.
Accesssametabletwice
7/29/2019 Diagnosis Performance
39/44
Set-basedSQL
41
Singletableaccess
7/29/2019 Diagnosis Performance
40/44
42
Stopthinking
row-by-row!
7/29/2019 Diagnosis Performance
41/44
Recap
Iftheproblemisoutsidethedatabase,SQLisrarelythemainproblem
StaGsGcs(planchanges)aretheprimeculpritifSQLperformancegoesfromgoodtobad
Findwhatchanged! Trytokeepinstanceparametersatdefaults
43
7/29/2019 Diagnosis Performance
42/44
Recap
WhenwriGngSQLThinkliketheopGmizer(trytoavoidquerytransformaGonpialls)
UseproperdatatypesWatchoutforcomplexexpressionsThinkinsets!
44
7/29/2019 Diagnosis Performance
43/44
Q&A
45
7/29/2019 Diagnosis Performance
44/44
Thankyou!
Top Related