Watch the companion webinar at: http://embt.co/1EBGmkK
There are many ways to find SQL that is performing poorly. The hard part is what to do with a bad SQL statement once you have it. In this webinar, several real-world examples will be reviewed to help you learn how to evaluate poorly performing SQL. Each example will demonstrate a commonly occurring SQL performance problem and provide a method to solve it.
Key points:
1. Why data logs are important
2. Proper log recovery actions
3. Log management best practices
10. The
5
Whys
Originally
developed
by
Toyota
Corpora<on
and
made
widely
known
by
Jeff
Bezos
of
Amazon.
11. Basic
concept…
Ask
why
repeatedly
unKl
you
get
to
the
single
root
cause
for
a
problem.
12. The
Jeff
Bezos
Story
Why
did
the
associate
damage
his
thumb?
Because
his
thumb
got
caught
in
the
conveyor.
Why
did
his
thumb
get
caught
in
the
conveyor?
Because
he
was
chasing
his
bag,
which
was
on
a
running
conveyor.
Why
did
he
chase
his
bag?
Because
he
placed
his
bag
on
the
conveyor,
but
it
then
turned-‐on
by
surprise.
Why
was
his
bag
on
the
conveyor?
Because
he
used
the
conveyor
as
a
table.
Why
did
he
use
his
bag
as
a
table?
Because
he
not
been
trained
to
not
do
so.
SoluKon:
Provide
a
work
table
*and*
safety
training.
14. Hi
Karen,
I
have
a
statement
in
a
vendor
supplied
procedure
that
is
hanging
for
days
and
I
wondered
if
you
could
take
a
look
at
it.
The
sql
monitor
report
is
below
along
with
a
formaded
copy
of
the
statement.
A
copy
of
the
procedure
is
adached
along
with
the
output
of
your
st-‐all
script
for
each
of
the
tables
involved.
We
can
add
hints,
indexes
and
refresh
staKsKcs
but
we
can’t
change
the
logic
of
the
programs
supplied
by
the
vendor.
I’ve
already
tried
refreshing
staKsKcs
but
it
didn’t
help.
I’ll
keep
digging
but
if
you
see
something
that
would
help
please
let
me
know.
Thanks
Joe
15. 71
hours
42
minutes
18
seconds
Global
Information
-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
Status
:
EXECUTING
Instance
ID
:
2
Session
:
.......
(1189:1901)
SQL
ID
:
678sypyw3yb8s
SQL
Execution
ID
:
33554442
Execution
Started
:
08/23/2014
16:04:31
First
Refresh
Time
:
08/23/2014
16:04:34
Last
Refresh
Time
:
08/26/2014
15:46:49
Duration
:
258139s
Module/Action
:
.......
Service
:
.......
Program
:
.......
PLSQL
Entry
Ids
(Object/Subprogram)
:
228587,1
PLSQL
Current
Ids
(Object/Subprogram)
:
228587,1
16. UPDATE
F_SCHED_APPT_STATS
STGSTAT
SET
(column-‐list)
=
(SELECT
SUM,COUNT
for
bunch
of
columns
.
.
.
FROM
PAT_ENC
PENC
INNER
JOIN
PAT_ENC_APPT
AVIEW
ON
AVIEW.PAT_ENC_CSN_ID
=
PENC.PAT_ENC_CSN_ID
INNER
JOIN
PAT_ENC_ES_AUD_ACT
MACT
ON
(PENC.PAT_ENC_CSN_ID
=
MACT.PAT_ENC_CSN_ID
AND
MACT.LINE
=
1)
LEFT
OUTER
JOIN
PAT_ENC_ES_AUD_ACT
CLACT
ON
(PENC.PAT_ENC_CSN_ID
=
CLACT.PAT_ENC_CSN_ID
AND
CLACT.ES_AUDIT_ACTION_C
=
4)
LEFT
OUTER
JOIN
PAT_ENC
PERESCHED
ON
(PERESCHED.APPT_SERIAL_NO
=
PENC.APPT_SERIAL_NO
AND
PERESCHED.PAT_ENC_CSN_ID
<>
PENC.PAT_ENC_CSN_ID
AND
PERESCHED.APPT_STATUS_C
<>
3)
LEFT
OUTER
JOIN
V_ZC_CANCEL_REASON
ZCCAN
ON
PENC.CANCEL_REASON_C
=
ZCCAN.CANCEL_REASON_C
WHERE
PENC.CONTACT_DATE
=
STGSTAT.STATISTICS_DATE
AND
AVIEW.DEPARTMENT_ID
=
STGSTAT.DEPARTMENT_ID
AND
AVIEW.PROV_ID
=
STGSTAT.PROV_ID)
30. During
a
health-‐check
analysis,
Top
SQL
by
both
execuKons
and
Kme
per
execuKon
was
evaluated.
One
of
the
key
findings
related
to
the
Top
SQL
was
that
opKmizer
staKsKcs
had
not
been
collected
in
over
4
years.
Many
plans
were
subopKmal
due
to
underesKmated
cardinaliKes
that
led
to
improper
join
type
and
join
order
choices.
In
addiKon,
Oracle
had
been
upgraded
twice
during
that
Kme
also
exposing
some
poorly
formulated
SQL
that
would
benefit
from
rewrites.
31. SELECT
DISTINCT
MAP_CODE,
MAP_CLASS,
GET_MAX_AUD_OID('MAP_CLASS',
MAP_CLASS_OID)
as
AUD_MAP_CLASS_OID,
MAP_CODE_OID,
GET_MAX_AUD_OID('MAP_CODE',
MAP_CODE_OID)
as
AUD_MAP_CODE_OID,
CONTEXT_NM
FROM
VWMAPCODES
WHERE
MAP_CODE
=
UPPER(:B2
)
AND
SPONSOR_OID
LIKE
:B1
Query
32. SELECT
d.destination_nm,
mc.map_code,
mc.oid
map_code_oid,
md.map_class_oid,
cl.map_class,
spg.sponsor_oid,
con.context_nm
FROM
map_code
mc,
map_code_data
md,
sponsor_product_cfg
spc,
sponsor_product_grp
spg,
destination
d,
map_class
cl,
map_code_context
con,
sponsor_prod_destination
spd
WHERE
mc.oid
=
md.map_code_oid
AND
cl.oid
=
md.map_class_oid
AND
spc.oid
=
spd.sponsor_product_cfg_oid
AND
spc.sponsor_product_grp_oid
=
spg.oid
AND
spd.destination_oid
=
d.oid
AND
mc.oid
=
d.map_code_oid
AND
con.oid(+)
=
md.map_code_context_oid
GROUP
BY
d.destination_nm,
mc.map_code,
mc.oid,
md.map_class_oid,
cl.map_class,
spg.sponsor_oid,
con.context_nm
View
36. SELECT
DISTINCT
MAP_CODE,
MAP_CLASS,
GET_MAX_AUD_OID('MAP_CLASS',
MAP_CLASS_OID)
as
AUD_MAP_CLASS_OID,
MAP_CODE_OID,
GET_MAX_AUD_OID('MAP_CODE',
MAP_CODE_OID)
as
AUD_MAP_CODE_OID,
CONTEXT_NM
FROM
VWMAPCODES
WHERE
MAP_CODE
=
UPPER(:B2
)
AND
SPONSOR_OID
LIKE
:B1
Query
37. SELECT
d.destination_nm,
mc.map_code,
mc.oid
map_code_oid,
md.map_class_oid,
cl.map_class,
spg.sponsor_oid,
con.context_nm
FROM
map_code
mc,
map_code_data
md,
sponsor_product_cfg
spc,
sponsor_product_grp
spg,
destination
d,
map_class
cl,
map_code_context
con,
sponsor_prod_destination
spd
WHERE
mc.oid
=
md.map_code_oid
AND
cl.oid
=
md.map_class_oid
AND
spc.oid
=
spd.sponsor_product_cfg_oid
AND
spc.sponsor_product_grp_oid
=
spg.oid
AND
spd.destination_oid
=
d.oid
AND
mc.oid
=
d.map_code_oid
AND
con.oid(+)
=
md.map_code_context_oid
GROUP
BY
d.destination_nm,
mc.map_code,
mc.oid,
md.map_class_oid,
cl.map_class,
spg.sponsor_oid,
con.context_nm
View
38.
Plan
HV
Execs
Min
Max
-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐
-‐-‐-‐-‐-‐-‐-‐
-‐-‐-‐-‐-‐-‐
-‐-‐-‐-‐-‐-‐-‐-‐-‐
3543794116
15,051
1.62
1,286.92
AWR
revealed
one
plan
with
varying
response
Kmes
from
1.62
to
1,286.92
seconds.
Longer
Kmes
were
associated
with
higher
PIO.
39. Why
does
the
query
need
column-‐list
funcKon
calls?
Are
they
part
of
the
problem?
Why
use
a
single
view?
Does
one
view
serve
both
predicates
opKmally?
Are
there
any
restricKons
on
the
LIKE
filter?
(0,1,2,3,n
characters
required?)
Why
is
there
such
a
big
deviaKon
in
the
response
Kmes?
41. Why
*not*
use
specific
SQL
for
specific
predicates?
Why
use
a
view
at
all?
Why
acquire
1M+
rows
only
to
throw
them
all
away?
42. select
distinct
mc.map_code,
cl.map_class,
con.context_nm
from
map_code
mc
join
map_code_data
md
on
mc.oid
=
md.map_code_oid
join
map_class
cl
on
cl.oid
=
md.map_class_oid
join
destination
d
on
mc.oid
=
d.map_code_oid
left
join
map_code_context
con
on
con.oid
=
md.map_code_context_oid
where
mc.map_code
=
:B1
;
Query
1
44. select
distinct
mc.map_code,
cl.map_class,
con.context_nm
from
map_code
mc
join
map_code_data
md
on
mc.oid
=
md.map_code_oid
join
map_class
cl
on
cl.oid
=
md.map_class_oid
join
destination
d
on
mc.oid
=
d.map_code_oid
join
sponsor_prod_destination
spd
on
spd.destination_oid
=
d.oid
join
sponsor_product_cfg
spc
on
spc.oid
=
spd.sponsor_product_cfg_oid
join
sponsor_product_grp
spg
on
spc.sponsor_product_grp_oid
=
spg.oid
left
join
map_code_context
con
on
con.oid
=
md.map_code_context_oid
where
mc.map_code
=
:B1
and
sponsor_oid
=
:B2
;
Query
2