Professional Documents
Culture Documents
July
31
Diagnosing
SQL
Performance
Problems
August
29
Making
SQL
Performance
SoluGons
SGck
September
26
Making
ImpacLul
Performance
Changes
3
Time is a luxury.
Plan
of
AWack
Evaluate
the
situaGon
Gather
data
&
determine
problem
scope
Validate soluGon
10
Do
you
have
licenses
for
ASH
&
AWR
use?
If
not,
do
you
use
S-ASH
or
rd
party
product?
Statspack
or
3
S-ASH
is
simulated
ASH
(homegrown
or
see
www.ashmasters.com).
11
12
13
14
But
Nothing
has changed!
16
If
nothing changed,
17
Ch-ch-ch-ch-changes
homage
to
David
Bowie
StaGsGcs
Data
volume
Data
distribuGon
SQL Problem?
19
21
StaGsGcs?
update set where and t_cust_acct_offr_pndg_trckg! prcss_flg = Y! bat_job_exec_trckg_id = :B1! cust_acct_offr_trckg_id = :B2 ;!
Process would execute this update over 1.5 million Gmes. Total esGmated Gme to complete ~ 500 hours. Logical IO per second over 111K
22
Response
Gme
for
single
execuGon
dropped
from
1.3
to
.002
seconds.
Logical
IO
per
second
dropped
from
over
111K
to
933.
23
Aser
stats
re-collected,
response
Gme
dropped
from
43
minutes
to
.01
second.
LIO
dropped
from
4.6
million
to
4
Stats
re-collected
with
auto_sample_size
using
FOR
ALL
COLUMNS
SIZE
AUTO
25
26
27
Cardinality
Feedback
Compares
cardinality
esGmates
to
actual
row
counts
If
enough
dierence
found,
opGmizer
applies
fudge
factor
to
correct
the
esGmate
OPT_ESTIMATE
hint
Cardinality Feedback!
Example
29
30
Quick
CF
Fixes
Turn
o
CF
(session
or
instance
level)
!_optimizer_use_feedback = FALSE!
Use
SQL
Prole
to
replace
bad
plan
with
good
! Use
hint
on
single
SQL
select /*+ opt_param(_optimizer_use_feedback false) */ !
31
Parameters
opGmizer_index_cost_adj
opGmizer_index_caching
db_le_mulGblock_read_count
pga_aggregate_target
cursor_sharing
Set
back
to
default
Use
SQL
Prole
to
replace
bad
plan
with
good
! Use
opt_param
hint
for
individual
SQL
to
override
eects
if
possible
33
How SQL is wriWen is not typically the problem when performance degrades without a plan change.
34
35
37
Query
TransformaGon
Developers
usually
write
SQL
in
style
simplest
to
understand
Not
necessarily
the
most
ecient
Oracle
rewrites
SQL
for
beWer
performance
TransformaGons
can
be
seen
in
the
execuGon
plan
(reverse
engineer
the
plan
to
the
SQL)
TransformaGon
benets
can
be
prevented
or
reduced
by
certain
techniques
DISTINCT,
GROUP
BY,
outer
joins,
etc
38
! 2!
Procedural
SQL
Access
same
table
twice
List
of
employees
who
spent
the
same
number
of
years
in
each
job
they
held.
40
Set-based
SQL
Single
table
access
41
42
Recap
If
the
problem
is
outside
the
database,
SQL
is
rarely
the
main
problem
StaGsGcs
(plan
changes)
are
the
prime
culprit
if
SQL
performance
goes
from
good
to
bad
Find
what
changed!
Try
to
keep
instance
parameters
at
defaults
43
Recap
When
wriGng
SQL
Think
like
the
opGmizer
(try
to
avoid
query
transformaGon
piLalls)
Use
proper
datatypes
Watch
out
for
complex
expressions
Think
in
sets!
44
Q
&
A
45
Thank you!