SlideShare a Scribd company logo
1 of 51
Find	
  It.	
  
Fix	
  it.	
  
Real-­‐World	
  SQL	
  Tuning	
  Cases	
  
Karen	
  Morton	
  
Infrastructure	
  Principal	
  Director	
  
Accenture	
  Enkitec	
  Group	
  
karenmorton.blogspot.com	
  
@karen_morton	
  
karen.r.morton@accenture.com	
  
Which	
  is	
  easier	
  for	
  you?	
  
Find	
  it?	
   Fix	
  it?	
  
A4?	
  
Hit!	
  
Miss.	
  
D7?	
  
AWR	
  
OEM	
  
Top	
  AcKvity	
  /	
  Top	
  SQL	
  
Users	
  
Now	
  what	
  ?	
  
Once	
  you	
  find	
  a	
  problem,	
  
how	
  do	
  you	
  fix	
  it?	
  
The	
  5	
  Whys	
  
Originally	
  developed	
  by	
  Toyota	
  Corpora<on	
  and	
  made	
  widely	
  known	
  by	
  Jeff	
  Bezos	
  of	
  Amazon.	
  
Basic	
  concept…	
  
Ask	
  why	
  repeatedly	
  unKl	
  you	
  get	
  to	
  the	
  single	
  
root	
  cause	
  for	
  a	
  problem.	
  
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.	
  
Case	
  Study	
  #1	
  
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	
  
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	
  
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)	
  
==========================================================================================================================!
| Id | Operation | Name | Rows | Execs | Rows | Activity |!
| | | | (Estim) | | (Actual) | (%) |!
==========================================================================================================================!
| 0 | UPDATE STATEMENT | | | 1 | | |!
| 1 | UPDATE | F_SCHED_APPT_STATS | | 1 | 0 | |!
| -> 2 | TABLE ACCESS STORAGE FULL | F_SCHED_APPT_STATS | 1 | 1 | 878 | |!
| 3 | TABLE ACCESS BY INDEX ROWID | PAT_PCP | 1 | 1673 | 850 | 0.02 |!
| 4 | INDEX RANGE SCAN | PK_PAT_PCP | 13 | 1673 | 19966 | 0.06 |!
| 5 | SORT AGGREGATE | | 1 | 97 | 97 | |!
| 6 | FILTER | | | 97 | 8713 | |!
| 7 | BITMAP CONVERSION TO ROWIDS | | 1494 | 96 | 8713 | |!
| 8 | BITMAP INDEX RANGE SCAN | EIX_CALENDAR_WEEKEND | | 96 | 8713 | |!
| 9 | SORT AGGREGATE | | 1 | 298 | 298 | |!
| 10 | FILTER | | | 298 | 224 | |!
| 11 | TABLE ACCESS BY INDEX ROWID | DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |!
| 12 | INDEX RANGE SCAN | PK_DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |!
| 13 | SORT AGGREGATE | | 1 | 878 | 877 | |!
| 14 | NESTED LOOPS | | | 878 | 1981 | |!
| 15 | NESTED LOOPS | | 2 | 878 | 1981 | |!
| 16 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |!
| 17 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |!
| 18 | NESTED LOOPS OUTER | | 1 | 878 | 1988 | |!
| 19 | NESTED LOOPS | | 1 | 878 | 1988 | |!
| 20 | VIEW | | 1 | 878 | 1988 | |!
| 21 | SORT GROUP BY | | 1 | 878 | 1988 | |!
| 22 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC_APPT | 1 | 878 | 1988 | 13.37 |!
| -> 23 | INDEX FULL SCAN | PK_PAT_ENC_APPT | 7M | 878 | 4G | 85.91 |!
| 24 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 1988 | |!
| 25 | INDEX UNIQUE SCAN | PK_PAT_ENC | 1 | 1988 | 1988 | |!
| 26 | VIEW PUSHED PREDICATE | V_ZC_CANCEL_REASON | 1 | 1988 | 306 | |!
| 27 | INDEX UNIQUE SCAN | PK_ZC_CANCEL_REASON | 1 | 1988 | 306 | |!
| 28 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 206 | |!
| 29 | INDEX RANGE SCAN | EIX_PAT_ENC_001 | 5 | 1988 | 2590 | 0.14 |!
| 30 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 1 | 1990 | 305 | 0.05 |!
| 31 | INDEX RANGE SCAN | PK_PAT_ENC_ES_AUD_ACT | 4 | 1990 | 4014 | 0.45 |!
| -> 32 | INDEX UNIQUE SCAN | PK_PAT_ENC_ES_AUD_ACT | 1 | 1991 | 1981 | |!
| 33 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 2 | 1981 | 1981 | |!
==========================================================================================================================!
Find	
  it?	
  
Fix	
  it?	
  
==========================================================================================================================!
| Id | Operation | Name | Rows | Execs | Rows | Activity |!
| | | | (Estim) | | (Actual) | (%) |!
==========================================================================================================================!
| 0 | UPDATE STATEMENT | | | 1 | | |!
| 1 | UPDATE | F_SCHED_APPT_STATS | | 1 | 0 | |!
| -> 2 | TABLE ACCESS STORAGE FULL | F_SCHED_APPT_STATS | 1 | 1 | 878 | |!
| 3 | TABLE ACCESS BY INDEX ROWID | PAT_PCP | 1 | 1673 | 850 | 0.02 |!
| 4 | INDEX RANGE SCAN | PK_PAT_PCP | 13 | 1673 | 19966 | 0.06 |!
| 5 | SORT AGGREGATE | | 1 | 97 | 97 | |!
| 6 | FILTER | | | 97 | 8713 | |!
| 7 | BITMAP CONVERSION TO ROWIDS | | 1494 | 96 | 8713 | |!
| 8 | BITMAP INDEX RANGE SCAN | EIX_CALENDAR_WEEKEND | | 96 | 8713 | |!
| 9 | SORT AGGREGATE | | 1 | 298 | 298 | |!
| 10 | FILTER | | | 298 | 224 | |!
| 11 | TABLE ACCESS BY INDEX ROWID | DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |!
| 12 | INDEX RANGE SCAN | PK_DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |!
| 13 | SORT AGGREGATE | | 1 | 878 | 877 | |!
| 14 | NESTED LOOPS | | | 878 | 1981 | |!
| 15 | NESTED LOOPS | | 2 | 878 | 1981 | |!
| 16 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |!
| 17 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |!
| 18 | NESTED LOOPS OUTER | | 1 | 878 | 1988 | |!
| 19 | NESTED LOOPS | | 1 | 878 | 1988 | |!
| 20 | VIEW | | 1 | 878 | 1988 | |!
| 21 | SORT GROUP BY | | 1 | 878 | 1988 | |!
| 22 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC_APPT | 1 | 878 | 1988 | 13.37 |!
| -> 23 | INDEX FULL SCAN | PK_PAT_ENC_APPT | 7M | 878 | 4G | 85.91 |!
| 24 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 1988 | |!
| 25 | INDEX UNIQUE SCAN | PK_PAT_ENC | 1 | 1988 | 1988 | |!
| 26 | VIEW PUSHED PREDICATE | V_ZC_CANCEL_REASON | 1 | 1988 | 306 | |!
| 27 | INDEX UNIQUE SCAN | PK_ZC_CANCEL_REASON | 1 | 1988 | 306 | |!
| 28 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 206 | |!
| 29 | INDEX RANGE SCAN | EIX_PAT_ENC_001 | 5 | 1988 | 2590 | 0.14 |!
| 30 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 1 | 1990 | 305 | 0.05 |!
| 31 | INDEX RANGE SCAN | PK_PAT_ENC_ES_AUD_ACT | 4 | 1990 | 4014 | 0.45 |!
| -> 32 | INDEX UNIQUE SCAN | PK_PAT_ENC_ES_AUD_ACT | 1 | 1991 | 1981 | |!
| 33 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 2 | 1981 | 1981 | |!
==========================================================================================================================!
=================================================	
  	
  
TABLE	
  STATISTICS	
  
=================================================	
  
Owner	
  	
  	
  	
  	
  	
  	
  	
  	
  :	
  clr	
  
Table	
  name	
  	
  	
  	
  :	
  pat_enc_appt	
  
Partitioned	
  	
  	
  :	
  yes	
  
Last	
  analyzed	
  :	
  08/24/2014	
  19:26:37	
  
Sample	
  size	
  	
  	
  :	
  145986286	
  
Degree	
  	
  	
  	
  	
  	
  	
  	
  :	
  1	
  
#	
  Rows	
  	
  	
  	
  	
  	
  	
  	
  :	
  145986286	
  
#	
  Blocks	
  	
  	
  	
  	
  	
  :	
  1257720	
  
Empty	
  Blocks	
  	
  :	
  0	
  
Avg	
  Space	
  	
  	
  	
  	
  :	
  0	
  
Avg	
  Row	
  Length:	
  59	
  
Monitoring?	
  	
  	
  :	
  yes	
  
======================================================================	
  
INDEX	
  INFORMATION	
  
======================================================================	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  DISTINCT	
  
INDEX_NAME	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  COLUMN_NAME(S)	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  KEYS	
  
-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐	
  
eix_pat_enc_appt_coda	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  contact_date	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  17058	
  
	
  
eix_penc_appt_provdep	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  prov_id,	
  department_id	
  	
  	
  	
  	
  38460	
  
	
  
eix_penc_prov_id	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  prov_id	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  38460	
  
	
  
pk_pat_enc_appt	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  pat_enc_csn_id,	
  line	
  	
  	
  	
  	
  	
  	
  146535236	
  
==========================================================================================================================!
| Id | Operation | Name | Rows | Execs | Rows | Activity |!
| | | | (Estim) | | (Actual) | (%) |!
==========================================================================================================================!
| 0 | UPDATE STATEMENT | | | 1 | | |!
| 1 | UPDATE | F_SCHED_APPT_STATS | | 1 | 0 | |!
| -> 2 | TABLE ACCESS STORAGE FULL | F_SCHED_APPT_STATS | 1 | 1 | 878 | |!
| 3 | TABLE ACCESS BY INDEX ROWID | PAT_PCP | 1 | 1673 | 850 | 0.02 |!
| 4 | INDEX RANGE SCAN | PK_PAT_PCP | 13 | 1673 | 19966 | 0.06 |!
| 5 | SORT AGGREGATE | | 1 | 97 | 97 | |!
| 6 | FILTER | | | 97 | 8713 | |!
| 7 | BITMAP CONVERSION TO ROWIDS | | 1494 | 96 | 8713 | |!
| 8 | BITMAP INDEX RANGE SCAN | EIX_CALENDAR_WEEKEND | | 96 | 8713 | |!
| 9 | SORT AGGREGATE | | 1 | 298 | 298 | |!
| 10 | FILTER | | | 298 | 224 | |!
| 11 | TABLE ACCESS BY INDEX ROWID | DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |!
| 12 | INDEX RANGE SCAN | PK_DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |!
| 13 | SORT AGGREGATE | | 1 | 878 | 877 | |!
| 14 | NESTED LOOPS | | | 878 | 1981 | |!
| 15 | NESTED LOOPS | | 2 | 878 | 1981 | |!
| 16 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |!
| 17 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |!
| 18 | NESTED LOOPS OUTER | | 1 | 878 | 1988 | |!
| 19 | NESTED LOOPS | | 1 | 878 | 1988 | |!
| 20 | VIEW | | 1 | 878 | 1988 | |!
| 21 | SORT GROUP BY | | 1 | 878 | 1988 | |!
| 22 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC_APPT | 1 | 878 | 1988 | 13.37 |!
| -> 23 | INDEX FULL SCAN | PK_PAT_ENC_APPT | 7M | 878 | 4G | 85.91 |!
| 24 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 1988 | |!
| 25 | INDEX UNIQUE SCAN | PK_PAT_ENC | 1 | 1988 | 1988 | |!
| 26 | VIEW PUSHED PREDICATE | V_ZC_CANCEL_REASON | 1 | 1988 | 306 | |!
| 27 | INDEX UNIQUE SCAN | PK_ZC_CANCEL_REASON | 1 | 1988 | 306 | |!
| 28 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 206 | |!
| 29 | INDEX RANGE SCAN | EIX_PAT_ENC_001 | 5 | 1988 | 2590 | 0.14 |!
| 30 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 1 | 1990 | 305 | 0.05 |!
| 31 | INDEX RANGE SCAN | PK_PAT_ENC_ES_AUD_ACT | 4 | 1990 | 4014 | 0.45 |!
| -> 32 | INDEX UNIQUE SCAN | PK_PAT_ENC_ES_AUD_ACT | 1 | 1991 | 1981 | |!
| 33 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 2 | 1981 | 1981 | |!
==========================================================================================================================!
===============================================	
  
	
  	
  TABLE	
  STATISTICS	
  
===============================================	
  
Owner	
  	
  	
  	
  	
  	
  	
  	
  	
  :	
  c_stage	
  
Table	
  name	
  	
  	
  	
  :	
  f_sched_appt_stats	
  
Partitioned	
  	
  	
  :	
  no	
  
Last	
  analyzed	
  :	
  08/23/2014	
  15:53:52	
  
Sample	
  size	
  	
  	
  :	
  0	
  
Degree	
  	
  	
  	
  	
  	
  	
  	
  :	
  1	
  
#	
  Rows	
  	
  	
  	
  	
  	
  	
  	
  :	
  0	
  
#	
  Blocks	
  	
  	
  	
  	
  	
  :	
  20	
  
Empty	
  Blocks	
  	
  :	
  0	
  
Avg	
  Space	
  	
  	
  	
  	
  :	
  0	
  
Avg	
  Row	
  Length:	
  0	
  
Monitoring?	
  	
  	
  :	
  yes	
  
==========================================================================================================================!
| Id | Operation | Name | Rows | Execs | Rows | Activity |!
| | | | (Estim) | | (Actual) | (%) |!
==========================================================================================================================!
| 0 | UPDATE STATEMENT | | | 1 | | |!
| 1 | UPDATE | F_SCHED_APPT_STATS | | 1 | 0 | |!
| -> 2 | TABLE ACCESS STORAGE FULL | F_SCHED_APPT_STATS | 1 | 1 | 878 | |!
| 3 | TABLE ACCESS BY INDEX ROWID | PAT_PCP | 1 | 1673 | 850 | 0.02 |!
| 4 | INDEX RANGE SCAN | PK_PAT_PCP | 13 | 1673 | 19966 | 0.06 |!
| 5 | SORT AGGREGATE | | 1 | 97 | 97 | |!
| 6 | FILTER | | | 97 | 8713 | |!
| 7 | BITMAP CONVERSION TO ROWIDS | | 1494 | 96 | 8713 | |!
| 8 | BITMAP INDEX RANGE SCAN | EIX_CALENDAR_WEEKEND | | 96 | 8713 | |!
| 9 | SORT AGGREGATE | | 1 | 298 | 298 | |!
| 10 | FILTER | | | 298 | 224 | |!
| 11 | TABLE ACCESS BY INDEX ROWID | DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |!
| 12 | INDEX RANGE SCAN | PK_DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |!
| 13 | SORT AGGREGATE | | 1 | 878 | 877 | |!
| 14 | NESTED LOOPS | | | 878 | 1981 | |!
| 15 | NESTED LOOPS | | 2 | 878 | 1981 | |!
| 16 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |!
| 17 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |!
| 18 | NESTED LOOPS OUTER | | 1 | 878 | 1988 | |!
| 19 | NESTED LOOPS | | 1 | 878 | 1988 | |!
| 20 | VIEW | | 1 | 878 | 1988 | |!
| 21 | SORT GROUP BY | | 1 | 878 | 1988 | |!
| 22 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC_APPT | 1 | 878 | 1988 | 13.37 |!
| -> 23 | INDEX FULL SCAN | PK_PAT_ENC_APPT | 7M | 878 | 4G | 85.91 |!
| 24 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 1988 | |!
| 25 | INDEX UNIQUE SCAN | PK_PAT_ENC | 1 | 1988 | 1988 | |!
| 26 | VIEW PUSHED PREDICATE | V_ZC_CANCEL_REASON | 1 | 1988 | 306 | |!
| 27 | INDEX UNIQUE SCAN | PK_ZC_CANCEL_REASON | 1 | 1988 | 306 | |!
| 28 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 206 | |!
| 29 | INDEX RANGE SCAN | EIX_PAT_ENC_001 | 5 | 1988 | 2590 | 0.14 |!
| 30 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 1 | 1990 | 305 | 0.05 |!
| 31 | INDEX RANGE SCAN | PK_PAT_ENC_ES_AUD_ACT | 4 | 1990 | 4014 | 0.45 |!
| -> 32 | INDEX UNIQUE SCAN | PK_PAT_ENC_ES_AUD_ACT | 1 | 1991 | 1981 | |!
| 33 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 2 | 1981 | 1981 | |!
==========================================================================================================================!
What	
  would	
  
you	
  do?	
  
Rewrite	
  the	
  query?	
  
Modify,	
  drop	
  or	
  create	
  an	
  index?	
  
Gather	
  staKsKcs?	
  
Change	
  parKKoning	
  scheme?	
  
Rebuild	
  tables?	
  
Rebuild	
  indexes?	
  
---------------------------------------------------------------------------------------------!
| Id | Operation | Name | New | Old |!
---------------------------------------------------------------------------------------------!
| 0 | UPDATE STATEMENT | | 2271 | | !
| 1 | UPDATE | F_SCHED_APPT_STATS | | | !
| 2 | TABLE ACCESS STORAGE FULL | F_SCHED_APPT_STATS | 2271 | 1 | !
| 3 | TABLE ACCESS BY INDEX ROWID | PAT_PCP | 1 | 1 | !
| 4 | INDEX RANGE SCAN | PAT_PCP_PAID | 6 | 13 | PK_PAT_PCP!
| 5 | SORT AGGREGATE | | 1 | 1 | !
| 6 | FILTER | | | | !
| 7 | BITMAP CONVERSION TO ROWIDS | | 165 | 1494 | !
| 8 | BITMAP INDEX RANGE SCAN | EIX_CALENDAR_WEEKEND | | | !
| 9 | SORT AGGREGATE | | 1 | 1 | !
| 10 | FILTER | | | | !
| 11 | TABLE ACCESS BY INDEX ROWID | DEPARTMENT_HOLIDAY | 1 | 1 | !
| 12 | INDEX RANGE SCAN | PK_DEPARTMENT_HOLIDAY | 1 | 1 | !
| 13 | SORT AGGREGATE | | 1 | 1 | !
| 14 | NESTED LOOPS | | | | !
| 15 | NESTED LOOPS | | 2 | 2 | !
| 16 | NESTED LOOPS OUTER | | 1 | 1 | !
| 17 | NESTED LOOPS OUTER | | 1 | 1 | !
| 18 | NESTED LOOPS OUTER | | 1 | 1 | !
| 19 | NESTED LOOPS | | 1 | 1 | !
| 20 | VIEW | | 1 | 1 | !
| 21 | SORT GROUP BY | | 1 | 1 | !
| 22 | TABLE ACCESS BY GLOBAL INDEX ROWID| PAT_ENC_APPT | 1 | 1 | !
| 23 | INDEX RANGE SCAN | EIX_PENC_APPT_PROVDEP | 3 | 7M | INDEX FULL SCAN | PK_PAT_ENC_APPT!
| 24 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1 |!
| 25 | INDEX UNIQUE SCAN | PK_PAT_ENC | 1 | 1 |!
| 26 | VIEW PUSHED PREDICATE | V_ZC_CANCEL_REASON | 1 | 1 |!
| 27 | INDEX UNIQUE SCAN | PK_ZC_CANCEL_REASON | 1 | 1 |!
| 28 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1 |!
| 29 | INDEX RANGE SCAN | EIX_PAT_ENC_001 | 4 | 5 |!
| 30 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 1 | 1 |!
| 31 | INDEX RANGE SCAN | PK_PAT_ENC_ES_AUD_ACT | 3 | 4 |!
| 32 | INDEX UNIQUE SCAN | PK_PAT_ENC_ES_AUD_ACT | 1 | 1 |!
| 33 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 1 | 2 |!
---------------------------------------------------------------------------------------------!
Afer	
  collecKng	
  stats	
  on	
  F_SCHED_APPT_STATS…	
  
9	
  seconds!	
  
Fix	
  it?	
  
Case	
  Study	
  #2	
  
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.	
  
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	
  
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	
  
=====================================================================================================================!
| Id | Operation | Name | Rows | Execs | Rows | Activity |!
| | | | (Estim) | | (Actual) | (%) |!
=====================================================================================================================!
| 0 | SELECT STATEMENT | | | 1 | 4 | |!
| 1 | HASH UNIQUE | | 3512 | 1 | 4 | |!
| 2 | HASH GROUP BY | | 3512 | 1 | 146K | 0.29 |!
| 3 | NESTED LOOPS | | 3512 | 1 | 1M | |!
| 4 | NESTED LOOPS | | 3512 | 1 | 1M | 0.29 |!
| 5 | NESTED LOOPS | | 3512 | 1 | 1M | |!
| 6 | NESTED LOOPS | | 3512 | 1 | 1M | |!
| 7 | NESTED LOOPS OUTER | | 1 | 1 | 4 | |!
| 8 | NESTED LOOPS | | 1 | 1 | 4 | |!
| 9 | NESTED LOOPS | | 1 | 1 | 4 | |!
| 10 | NESTED LOOPS | | 1 | 1 | 1 | |!
| 11 | TABLE ACCESS BY INDEX ROWID | MAP_CODE | 1 | 1 | 1 | |!
| 12 | INDEX UNIQUE SCAN | MAP_CODE_MC_IDX | 1 | 1 | 1 | |!
| 13 | TABLE ACCESS BY INDEX ROWID | DESTINATION | 1 | 1 | 1 | |!
| 14 | INDEX UNIQUE SCAN | DESTINATION_MAP_CODE_UK | 1 | 1 | 1 | |!
| 15 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_DATA | 1 | 1 | 4 | |!
| 16 | INDEX RANGE SCAN | MAP_CODE_DATA_MAP_CODE_IDX | 2 | 1 | 4 | |!
| 17 | TABLE ACCESS BY INDEX ROWID | MAP_CLASS | 1 | 4 | 4 | |!
| 18 | INDEX UNIQUE SCAN | MAP_CLASS_PK | 1 | 4 | 4 | |!
| 19 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_CONTEXT | 1 | 4 | 4 | |!
| 20 | INDEX UNIQUE SCAN | MAP_CODE_CONTEXT_PK | 1 | 4 | 4 | |!
| 21 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PROD_DESTINATION | 5045 | 4 | 1M | 10.03 |!
| 22 | INDEX RANGE SCAN | IDX_SPD_DEST | 6167 | 4 | 1M | 2.29 |!
| 23 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PRODUCT_CFG | 1 | 1M | 1M | 57.31 |!
| 24 | INDEX UNIQUE SCAN | PK_SPONSOR_PRODUCT_CFG | 1 | 1M | 1M | 10.60 |!
| 25 | INDEX UNIQUE SCAN | PK_SPONSOR_PRODUCT_GRP | 1 | 1M | 1M | 7.16 |!
| 26 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PRODUCT_GRP | 1 | 1M | 1M | 12.03 |!
=====================================================================================================================!
5	
  minutes	
  49	
  seconds	
  	
  	
  	
  LIO	
  =	
  7M+	
  	
  	
  	
  	
  	
  PIO	
  =	
  140K+	
  
Find	
  it?	
  
Fix	
  it?	
  
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	
  
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	
  
 	
  	
  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.	
  
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?	
  
=====================================================================================================================!
| Id | Operation | Name | Rows | Execs | Rows | Activity |!
| | | | (Estim) | | (Actual) | (%) |!
=====================================================================================================================!
| 0 | SELECT STATEMENT | | | 1 | 4 | |!
| 1 | HASH UNIQUE | | 3512 | 1 | 4 | |!
| 2 | HASH GROUP BY | | 3512 | 1 | 146K | 0.29 |!
| 3 | NESTED LOOPS | | 3512 | 1 | 1M | |!
| 4 | NESTED LOOPS | | 3512 | 1 | 1M | 0.29 |!
| 5 | NESTED LOOPS | | 3512 | 1 | 1M | |!
| 6 | NESTED LOOPS | | 3512 | 1 | 1M | |!
| 7 | NESTED LOOPS OUTER | | 1 | 1 | 4 | |!
| 8 | NESTED LOOPS | | 1 | 1 | 4 | |!
| 9 | NESTED LOOPS | | 1 | 1 | 4 | |!
| 10 | NESTED LOOPS | | 1 | 1 | 1 | |!
| 11 | TABLE ACCESS BY INDEX ROWID | MAP_CODE | 1 | 1 | 1 | |!
| 12 | INDEX UNIQUE SCAN | MAP_CODE_MC_IDX | 1 | 1 | 1 | |!
| 13 | TABLE ACCESS BY INDEX ROWID | DESTINATION | 1 | 1 | 1 | |!
| 14 | INDEX UNIQUE SCAN | DESTINATION_MAP_CODE_UK | 1 | 1 | 1 | |!
| 15 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_DATA | 1 | 1 | 4 | |!
| 16 | INDEX RANGE SCAN | MAP_CODE_DATA_MAP_CODE_IDX | 2 | 1 | 4 | |!
| 17 | TABLE ACCESS BY INDEX ROWID | MAP_CLASS | 1 | 4 | 4 | |!
| 18 | INDEX UNIQUE SCAN | MAP_CLASS_PK | 1 | 4 | 4 | |!
| 19 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_CONTEXT | 1 | 4 | 4 | |!
| 20 | INDEX UNIQUE SCAN | MAP_CODE_CONTEXT_PK | 1 | 4 | 4 | |!
| 21 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PROD_DESTINATION | 5045 | 4 | 1M | 10.03 |!
| 22 | INDEX RANGE SCAN | IDX_SPD_DEST | 6167 | 4 | 1M | 2.29 |!
| 23 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PRODUCT_CFG | 1 | 1M | 1M | 57.31 |!
| 24 | INDEX UNIQUE SCAN | PK_SPONSOR_PRODUCT_CFG | 1 | 1M | 1M | 10.60 |!
| 25 | INDEX UNIQUE SCAN | PK_SPONSOR_PRODUCT_GRP | 1 | 1M | 1M | 7.16 |!
| 26 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PRODUCT_GRP | 1 | 1M | 1M | 12.03 |!
=====================================================================================================================!
5	
  minutes	
  49	
  seconds	
  	
  	
  	
  LIO	
  =	
  7M+	
  	
  	
  	
  	
  	
  PIO	
  =	
  140K+	
  
Why	
  *not*	
  use	
  specific	
  SQL	
  for	
  specific	
  predicates?	
  
Why	
  use	
  a	
  view	
  at	
  all?	
  
	
  
	
  
	
  
Why	
  acquire	
  1M+	
  rows	
  only	
  to	
  throw	
  them	
  all	
  away?	
  
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	
  
----------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
----------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 4 |00:00:00.02 | 21 | 3 |
| 1 | HASH UNIQUE | | 1 | 1 | 4 |00:00:00.02 | 21 | 3 |
| 2 | NESTED LOOPS OUTER | | 1 | 1 | 4 |00:00:00.02 | 21 | 3 |
| 3 | NESTED LOOPS | | 1 | 1 | 4 |00:00:00.02 | 15 | 3 |
| 4 | NESTED LOOPS | | 1 | 1 | 4 |00:00:00.01 | 9 | 2 |
| 5 | NESTED LOOPS | | 1 | 1 | 1 |00:00:00.01 | 5 | 0 |
| 6 | TABLE ACCESS BY INDEX ROWID| MAP_CODE | 1 | 1 | 1 |00:00:00.01 | 3 | 0 |
|* 7 | INDEX UNIQUE SCAN | MAP_CODE_MC_IDX | 1 | 1 | 1 |00:00:00.01 | 2 | 0 |
|* 8 | INDEX UNIQUE SCAN | DESTINATION_MAP_CODE_UK | 1 | 1 | 1 |00:00:00.01 | 2 | 0 |
| 9 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_DATA | 1 | 1 | 4 |00:00:00.01 | 4 | 2 |
|* 10 | INDEX RANGE SCAN | MAP_CODE_DATA_MAP_CODE_IDX | 1 | 2 | 4 |00:00:00.01 | 2 | 2 |
| 11 | TABLE ACCESS BY INDEX ROWID | MAP_CLASS | 4 | 1 | 4 |00:00:00.01 | 6 | 1 |
|* 12 | INDEX UNIQUE SCAN | MAP_CLASS_PK | 4 | 1 | 4 |00:00:00.01 | 2 | 1 |
| 13 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_CONTEXT | 4 | 1 | 4 |00:00:00.01 | 6 | 0 |
|* 14 | INDEX UNIQUE SCAN | MAP_CODE_CONTEXT_PK | 4 | 1 | 4 |00:00:00.01 | 2 | 0 |
----------------------------------------------------------------------------------------------------------------------------------
.02	
  seconds	
  	
  	
  	
  LIO	
  =	
  21	
  	
  	
  	
  	
  	
  PIO	
  =	
  3	
  
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	
  
----------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
----------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 4 |00:00.21 | 904 | 25 |
| 1 | HASH UNIQUE | | 1 | 1 | 4 |00:00.21 | 904 | 25 |
| 2 | NESTED LOOPS OUTER | | 1 | 1 | 188 |00:00.21 | 904 | 25 |
| 3 | NESTED LOOPS | | 1 | 1 | 188 |00:00.21 | 712 | 25 |
| 4 | NESTED LOOPS | | 1 | 5 | 188 |00:00.10 | 370 | 11 |
|* 5 | HASH JOIN | | 1 | 5 | 188 |00:00.03 | 52 | 2 |
|* 6 | HASH JOIN | | 1 | 6 | 188 |00:00.02 | 46 | 2 |
| 7 | NESTED LOOPS | | 1 | 7 | 47 |00:00.02 | 31 | 2 |
| 8 | NESTED LOOPS | | 1 | 1 | 1 |00:00.01 | 6 | 0 |
| 9 | TABLE ACCESS BY INDEX ROWID| MAP_CODE | 1 | 1 | 1 |00:00.01 | 3 | 0 |
|* 10 | INDEX UNIQUE SCAN | MAP_CODE_MC_IDX | 1 | 1 | 1 |00:00.01 | 2 | 0 |
| 11 | TABLE ACCESS BY INDEX ROWID| DESTINATION | 1 | 1 | 1 |00:00.01 | 3 | 0 |
|* 12 | INDEX UNIQUE SCAN | DESTINATION_MAP_CODE_UK | 1 | 1 | 1 |00:00.01 | 2 | 0 |
| 13 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PRODUCT_GRP | 1 | 7 | 47 |00:00.02 | 25 | 2 |
|* 14 | INDEX RANGE SCAN | SPONSOR_PRODUCT_GRP_SPONSOR | 1 | 7 | 47 |00:00.02 | 3 | 2 |
| 15 | TABLE ACCESS FULL | MAP_CODE_DATA | 1 | 715 | 715 |00:00.01 | 15 | 0 |
| 16 | TABLE ACCESS FULL | MAP_CLASS | 1 | 189 | 189 |00:00.01 | 6 | 0 |
|* 17 | INDEX RANGE SCAN | IDX_SPC_SPG_PP_OID | 188 | 1 | 188 |00:00.07 | 318 | 9 |
|* 18 | INDEX UNIQUE SCAN | SPONSOR_PROD_DEST_SD_UK | 188 | 1 | 188 |00:00.11 | 342 | 14 |
| 19 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_CONTEXT | 188 | 1 | 188 |00:00.01 | 192 | 0 |
|* 20 | INDEX UNIQUE SCAN | MAP_CODE_CONTEXT_PK | 188 | 1 | 188 |00:00.01 | 4 | 0 |
----------------------------------------------------------------------------------------------------------------------------------
.21	
  seconds	
  	
  	
  	
  LIO	
  =	
  904	
  	
  	
  	
  	
  	
  PIO	
  =	
  25	
  
Fix	
  it?	
  
2	
  Cases.	
  
	
  
2	
  Very	
  Different	
  SoluKons.	
  
	
  
1	
  
StaKsKcs.	
  
	
  
2	
  
Prac<cal	
  SQL	
  constructs.	
  
Don't	
  limit	
  yourself.	
  
	
  
Just	
  because	
  something	
  
worked	
  once	
  doesn't	
  mean	
  it's	
  
the	
  best	
  choice	
  for	
  another	
  
case.	
  
Find	
  it.	
  
	
  
5	
  Whys.	
  
	
  
Evaluate	
  SoluKon(s).	
  
	
  
Fix	
  it!	
  
Thank	
  You!	
  

More Related Content

Viewers also liked

Патент на полезную модель Республики Беларусь
Патент на полезную модель Республики БеларусьПатент на полезную модель Республики Беларусь
Патент на полезную модель Республики БеларусьИван Иванов
 
учебно методическое пособие-по_дисциплине_прикладная_голография_
учебно методическое пособие-по_дисциплине_прикладная_голография_учебно методическое пособие-по_дисциплине_прикладная_голография_
учебно методическое пособие-по_дисциплине_прикладная_голография_Иван Иванов
 
Chem 2P20 SciFinder exercise November 2016
Chem 2P20 SciFinder exercise November 2016Chem 2P20 SciFinder exercise November 2016
Chem 2P20 SciFinder exercise November 2016Brock University
 
RESUME ( Salman Khanzada)
RESUME ( Salman Khanzada)RESUME ( Salman Khanzada)
RESUME ( Salman Khanzada)Salman Khanzada
 
Jessie lee dia_2016_oral_presentation_final
Jessie lee dia_2016_oral_presentation_finalJessie lee dia_2016_oral_presentation_final
Jessie lee dia_2016_oral_presentation_finalJessie Lee
 
Reflective in Psychology
Reflective in PsychologyReflective in Psychology
Reflective in PsychologyModupe Sarratt
 
client centered therapy
client centered therapyclient centered therapy
client centered therapyume habiba
 
Ethical decision making –Attitude and beliefs
Ethical decision making –Attitude and beliefs Ethical decision making –Attitude and beliefs
Ethical decision making –Attitude and beliefs mital radadiya
 

Viewers also liked (9)

Art Babble Case Study
Art Babble Case StudyArt Babble Case Study
Art Babble Case Study
 
Патент на полезную модель Республики Беларусь
Патент на полезную модель Республики БеларусьПатент на полезную модель Республики Беларусь
Патент на полезную модель Республики Беларусь
 
учебно методическое пособие-по_дисциплине_прикладная_голография_
учебно методическое пособие-по_дисциплине_прикладная_голография_учебно методическое пособие-по_дисциплине_прикладная_голография_
учебно методическое пособие-по_дисциплине_прикладная_голография_
 
Chem 2P20 SciFinder exercise November 2016
Chem 2P20 SciFinder exercise November 2016Chem 2P20 SciFinder exercise November 2016
Chem 2P20 SciFinder exercise November 2016
 
RESUME ( Salman Khanzada)
RESUME ( Salman Khanzada)RESUME ( Salman Khanzada)
RESUME ( Salman Khanzada)
 
Jessie lee dia_2016_oral_presentation_final
Jessie lee dia_2016_oral_presentation_finalJessie lee dia_2016_oral_presentation_final
Jessie lee dia_2016_oral_presentation_final
 
Reflective in Psychology
Reflective in PsychologyReflective in Psychology
Reflective in Psychology
 
client centered therapy
client centered therapyclient centered therapy
client centered therapy
 
Ethical decision making –Attitude and beliefs
Ethical decision making –Attitude and beliefs Ethical decision making –Attitude and beliefs
Ethical decision making –Attitude and beliefs
 

Similar to Find it. Fix it. Real-World SQL Tuning Cases with Karen Morton

Are you a monkey or an astronaut?
Are you a monkey or an astronaut?Are you a monkey or an astronaut?
Are you a monkey or an astronaut?Karen Morton
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performanceGuy Harrison
 
Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...Odoo
 
Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deploymentsOdoo
 
Testar2014 presentation
Testar2014 presentationTestar2014 presentation
Testar2014 presentationTanja Vos
 
Docker Logging and analysing with Elastic Stack - Jakub Hajek
Docker Logging and analysing with Elastic Stack - Jakub Hajek Docker Logging and analysing with Elastic Stack - Jakub Hajek
Docker Logging and analysing with Elastic Stack - Jakub Hajek PROIDEA
 
Docker Logging and analysing with Elastic Stack
Docker Logging and analysing with Elastic StackDocker Logging and analysing with Elastic Stack
Docker Logging and analysing with Elastic StackJakub Hajek
 
Reproducible AI Using PyTorch and MLflow
Reproducible AI Using PyTorch and MLflowReproducible AI Using PyTorch and MLflow
Reproducible AI Using PyTorch and MLflowDatabricks
 
Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Valeriy Kravchuk
 
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And WhatPerformance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And Whatudaymoogala
 
7 QC Tools and Problem Solving Presentation.pdf
7 QC Tools and Problem Solving Presentation.pdf7 QC Tools and Problem Solving Presentation.pdf
7 QC Tools and Problem Solving Presentation.pdfAzizOUBBAD1
 
7_QC_Tools_and_Problem_Solving_Presentation_1656881575.pdf
7_QC_Tools_and_Problem_Solving_Presentation_1656881575.pdf7_QC_Tools_and_Problem_Solving_Presentation_1656881575.pdf
7_QC_Tools_and_Problem_Solving_Presentation_1656881575.pdfEngFaisalAlrai
 
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdfHailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdfcookie1969
 
Fast and Reliable Apache Spark SQL Engine
Fast and Reliable Apache Spark SQL EngineFast and Reliable Apache Spark SQL Engine
Fast and Reliable Apache Spark SQL EngineDatabricks
 
Profiling ruby
Profiling rubyProfiling ruby
Profiling rubynasirj
 
MySQL Performance Schema : fossasia
MySQL Performance Schema : fossasiaMySQL Performance Schema : fossasia
MySQL Performance Schema : fossasiaMayank Prasad
 
OpenWhisk: Event-driven Design
OpenWhisk: Event-driven DesignOpenWhisk: Event-driven Design
OpenWhisk: Event-driven DesignAltoros
 
Meng_Aero_Vergara_Camilo
Meng_Aero_Vergara_CamiloMeng_Aero_Vergara_Camilo
Meng_Aero_Vergara_CamiloCamilo Vergara
 
Metrics-Driven Engineering
Metrics-Driven EngineeringMetrics-Driven Engineering
Metrics-Driven EngineeringMike Brittain
 

Similar to Find it. Fix it. Real-World SQL Tuning Cases with Karen Morton (20)

Are you a monkey or an astronaut?
Are you a monkey or an astronaut?Are you a monkey or an astronaut?
Are you a monkey or an astronaut?
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performance
 
Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...
 
Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deployments
 
Testar2014 presentation
Testar2014 presentationTestar2014 presentation
Testar2014 presentation
 
Docker Logging and analysing with Elastic Stack - Jakub Hajek
Docker Logging and analysing with Elastic Stack - Jakub Hajek Docker Logging and analysing with Elastic Stack - Jakub Hajek
Docker Logging and analysing with Elastic Stack - Jakub Hajek
 
Docker Logging and analysing with Elastic Stack
Docker Logging and analysing with Elastic StackDocker Logging and analysing with Elastic Stack
Docker Logging and analysing with Elastic Stack
 
Reproducible AI Using PyTorch and MLflow
Reproducible AI Using PyTorch and MLflowReproducible AI Using PyTorch and MLflow
Reproducible AI Using PyTorch and MLflow
 
Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013
 
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And WhatPerformance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
 
7 QC Tools and Problem Solving Presentation.pdf
7 QC Tools and Problem Solving Presentation.pdf7 QC Tools and Problem Solving Presentation.pdf
7 QC Tools and Problem Solving Presentation.pdf
 
7_QC_Tools_and_Problem_Solving_Presentation_1656881575.pdf
7_QC_Tools_and_Problem_Solving_Presentation_1656881575.pdf7_QC_Tools_and_Problem_Solving_Presentation_1656881575.pdf
7_QC_Tools_and_Problem_Solving_Presentation_1656881575.pdf
 
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdfHailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
 
Fast and Reliable Apache Spark SQL Engine
Fast and Reliable Apache Spark SQL EngineFast and Reliable Apache Spark SQL Engine
Fast and Reliable Apache Spark SQL Engine
 
Profiling ruby
Profiling rubyProfiling ruby
Profiling ruby
 
Vertica trace
Vertica traceVertica trace
Vertica trace
 
MySQL Performance Schema : fossasia
MySQL Performance Schema : fossasiaMySQL Performance Schema : fossasia
MySQL Performance Schema : fossasia
 
OpenWhisk: Event-driven Design
OpenWhisk: Event-driven DesignOpenWhisk: Event-driven Design
OpenWhisk: Event-driven Design
 
Meng_Aero_Vergara_Camilo
Meng_Aero_Vergara_CamiloMeng_Aero_Vergara_Camilo
Meng_Aero_Vergara_Camilo
 
Metrics-Driven Engineering
Metrics-Driven EngineeringMetrics-Driven Engineering
Metrics-Driven Engineering
 

More from Embarcadero Technologies

PyTorch for Delphi - Python Data Sciences Libraries.pdf
PyTorch for Delphi - Python Data Sciences Libraries.pdfPyTorch for Delphi - Python Data Sciences Libraries.pdf
PyTorch for Delphi - Python Data Sciences Libraries.pdfEmbarcadero Technologies
 
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...Embarcadero Technologies
 
Linux GUI Applications on Windows Subsystem for Linux
Linux GUI Applications on Windows Subsystem for LinuxLinux GUI Applications on Windows Subsystem for Linux
Linux GUI Applications on Windows Subsystem for LinuxEmbarcadero Technologies
 
Python on Android with Delphi FMX - The Cross Platform GUI Framework
Python on Android with Delphi FMX - The Cross Platform GUI Framework Python on Android with Delphi FMX - The Cross Platform GUI Framework
Python on Android with Delphi FMX - The Cross Platform GUI Framework Embarcadero Technologies
 
Introduction to Python GUI development with Delphi for Python - Part 1: Del...
Introduction to Python GUI development with Delphi for Python - Part 1:   Del...Introduction to Python GUI development with Delphi for Python - Part 1:   Del...
Introduction to Python GUI development with Delphi for Python - Part 1: Del...Embarcadero Technologies
 
FMXLinux Introduction - Delphi's FireMonkey for Linux
FMXLinux Introduction - Delphi's FireMonkey for LinuxFMXLinux Introduction - Delphi's FireMonkey for Linux
FMXLinux Introduction - Delphi's FireMonkey for LinuxEmbarcadero Technologies
 
Python for Delphi Developers - Part 1 Introduction
Python for Delphi Developers - Part 1 IntroductionPython for Delphi Developers - Part 1 Introduction
Python for Delphi Developers - Part 1 IntroductionEmbarcadero Technologies
 
RAD Industrial Automation, Labs, and Instrumentation
RAD Industrial Automation, Labs, and InstrumentationRAD Industrial Automation, Labs, and Instrumentation
RAD Industrial Automation, Labs, and InstrumentationEmbarcadero Technologies
 
Embeddable Databases for Mobile Apps: Stress-Free Solutions with InterBase
Embeddable Databases for Mobile Apps: Stress-Free Solutions with InterBaseEmbeddable Databases for Mobile Apps: Stress-Free Solutions with InterBase
Embeddable Databases for Mobile Apps: Stress-Free Solutions with InterBaseEmbarcadero Technologies
 
Rad Server Industry Template - Connected Nurses Station - Setup Document
Rad Server Industry Template - Connected Nurses Station - Setup DocumentRad Server Industry Template - Connected Nurses Station - Setup Document
Rad Server Industry Template - Connected Nurses Station - Setup DocumentEmbarcadero Technologies
 
Move Desktop Apps to the Cloud - RollApp & Embarcadero webinar
Move Desktop Apps to the Cloud - RollApp & Embarcadero webinarMove Desktop Apps to the Cloud - RollApp & Embarcadero webinar
Move Desktop Apps to the Cloud - RollApp & Embarcadero webinarEmbarcadero Technologies
 
Getting Started Building Mobile Applications for iOS and Android
Getting Started Building Mobile Applications for iOS and AndroidGetting Started Building Mobile Applications for iOS and Android
Getting Started Building Mobile Applications for iOS and AndroidEmbarcadero Technologies
 
ER/Studio 2016: Build a Business-Driven Data Architecture
ER/Studio 2016: Build a Business-Driven Data ArchitectureER/Studio 2016: Build a Business-Driven Data Architecture
ER/Studio 2016: Build a Business-Driven Data ArchitectureEmbarcadero Technologies
 
The Secrets of SQL Server: Database Worst Practices
The Secrets of SQL Server: Database Worst PracticesThe Secrets of SQL Server: Database Worst Practices
The Secrets of SQL Server: Database Worst PracticesEmbarcadero Technologies
 
Driving Business Value Through Agile Data Assets
Driving Business Value Through Agile Data AssetsDriving Business Value Through Agile Data Assets
Driving Business Value Through Agile Data AssetsEmbarcadero Technologies
 
Troubleshooting Plan Changes with Query Store in SQL Server 2016
Troubleshooting Plan Changes with Query Store in SQL Server 2016Troubleshooting Plan Changes with Query Store in SQL Server 2016
Troubleshooting Plan Changes with Query Store in SQL Server 2016Embarcadero Technologies
 

More from Embarcadero Technologies (20)

PyTorch for Delphi - Python Data Sciences Libraries.pdf
PyTorch for Delphi - Python Data Sciences Libraries.pdfPyTorch for Delphi - Python Data Sciences Libraries.pdf
PyTorch for Delphi - Python Data Sciences Libraries.pdf
 
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
 
Linux GUI Applications on Windows Subsystem for Linux
Linux GUI Applications on Windows Subsystem for LinuxLinux GUI Applications on Windows Subsystem for Linux
Linux GUI Applications on Windows Subsystem for Linux
 
Python on Android with Delphi FMX - The Cross Platform GUI Framework
Python on Android with Delphi FMX - The Cross Platform GUI Framework Python on Android with Delphi FMX - The Cross Platform GUI Framework
Python on Android with Delphi FMX - The Cross Platform GUI Framework
 
Introduction to Python GUI development with Delphi for Python - Part 1: Del...
Introduction to Python GUI development with Delphi for Python - Part 1:   Del...Introduction to Python GUI development with Delphi for Python - Part 1:   Del...
Introduction to Python GUI development with Delphi for Python - Part 1: Del...
 
FMXLinux Introduction - Delphi's FireMonkey for Linux
FMXLinux Introduction - Delphi's FireMonkey for LinuxFMXLinux Introduction - Delphi's FireMonkey for Linux
FMXLinux Introduction - Delphi's FireMonkey for Linux
 
Python for Delphi Developers - Part 2
Python for Delphi Developers - Part 2Python for Delphi Developers - Part 2
Python for Delphi Developers - Part 2
 
Python for Delphi Developers - Part 1 Introduction
Python for Delphi Developers - Part 1 IntroductionPython for Delphi Developers - Part 1 Introduction
Python for Delphi Developers - Part 1 Introduction
 
RAD Industrial Automation, Labs, and Instrumentation
RAD Industrial Automation, Labs, and InstrumentationRAD Industrial Automation, Labs, and Instrumentation
RAD Industrial Automation, Labs, and Instrumentation
 
Embeddable Databases for Mobile Apps: Stress-Free Solutions with InterBase
Embeddable Databases for Mobile Apps: Stress-Free Solutions with InterBaseEmbeddable Databases for Mobile Apps: Stress-Free Solutions with InterBase
Embeddable Databases for Mobile Apps: Stress-Free Solutions with InterBase
 
Rad Server Industry Template - Connected Nurses Station - Setup Document
Rad Server Industry Template - Connected Nurses Station - Setup DocumentRad Server Industry Template - Connected Nurses Station - Setup Document
Rad Server Industry Template - Connected Nurses Station - Setup Document
 
TMS Google Mapping Components
TMS Google Mapping ComponentsTMS Google Mapping Components
TMS Google Mapping Components
 
Move Desktop Apps to the Cloud - RollApp & Embarcadero webinar
Move Desktop Apps to the Cloud - RollApp & Embarcadero webinarMove Desktop Apps to the Cloud - RollApp & Embarcadero webinar
Move Desktop Apps to the Cloud - RollApp & Embarcadero webinar
 
Useful C++ Features You Should be Using
Useful C++ Features You Should be UsingUseful C++ Features You Should be Using
Useful C++ Features You Should be Using
 
Getting Started Building Mobile Applications for iOS and Android
Getting Started Building Mobile Applications for iOS and AndroidGetting Started Building Mobile Applications for iOS and Android
Getting Started Building Mobile Applications for iOS and Android
 
Embarcadero RAD server Launch Webinar
Embarcadero RAD server Launch WebinarEmbarcadero RAD server Launch Webinar
Embarcadero RAD server Launch Webinar
 
ER/Studio 2016: Build a Business-Driven Data Architecture
ER/Studio 2016: Build a Business-Driven Data ArchitectureER/Studio 2016: Build a Business-Driven Data Architecture
ER/Studio 2016: Build a Business-Driven Data Architecture
 
The Secrets of SQL Server: Database Worst Practices
The Secrets of SQL Server: Database Worst PracticesThe Secrets of SQL Server: Database Worst Practices
The Secrets of SQL Server: Database Worst Practices
 
Driving Business Value Through Agile Data Assets
Driving Business Value Through Agile Data AssetsDriving Business Value Through Agile Data Assets
Driving Business Value Through Agile Data Assets
 
Troubleshooting Plan Changes with Query Store in SQL Server 2016
Troubleshooting Plan Changes with Query Store in SQL Server 2016Troubleshooting Plan Changes with Query Store in SQL Server 2016
Troubleshooting Plan Changes with Query Store in SQL Server 2016
 

Recently uploaded

Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 

Recently uploaded (20)

Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 

Find it. Fix it. Real-World SQL Tuning Cases with Karen Morton

  • 1. Find  It.   Fix  it.   Real-­‐World  SQL  Tuning  Cases   Karen  Morton   Infrastructure  Principal  Director   Accenture  Enkitec  Group  
  • 3. Which  is  easier  for  you?   Find  it?   Fix  it?  
  • 6. OEM   Top  AcKvity  /  Top  SQL  
  • 9. Once  you  find  a  problem,   how  do  you  fix  it?  
  • 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)  
  • 17. ==========================================================================================================================! | Id | Operation | Name | Rows | Execs | Rows | Activity |! | | | | (Estim) | | (Actual) | (%) |! ==========================================================================================================================! | 0 | UPDATE STATEMENT | | | 1 | | |! | 1 | UPDATE | F_SCHED_APPT_STATS | | 1 | 0 | |! | -> 2 | TABLE ACCESS STORAGE FULL | F_SCHED_APPT_STATS | 1 | 1 | 878 | |! | 3 | TABLE ACCESS BY INDEX ROWID | PAT_PCP | 1 | 1673 | 850 | 0.02 |! | 4 | INDEX RANGE SCAN | PK_PAT_PCP | 13 | 1673 | 19966 | 0.06 |! | 5 | SORT AGGREGATE | | 1 | 97 | 97 | |! | 6 | FILTER | | | 97 | 8713 | |! | 7 | BITMAP CONVERSION TO ROWIDS | | 1494 | 96 | 8713 | |! | 8 | BITMAP INDEX RANGE SCAN | EIX_CALENDAR_WEEKEND | | 96 | 8713 | |! | 9 | SORT AGGREGATE | | 1 | 298 | 298 | |! | 10 | FILTER | | | 298 | 224 | |! | 11 | TABLE ACCESS BY INDEX ROWID | DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |! | 12 | INDEX RANGE SCAN | PK_DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |! | 13 | SORT AGGREGATE | | 1 | 878 | 877 | |! | 14 | NESTED LOOPS | | | 878 | 1981 | |! | 15 | NESTED LOOPS | | 2 | 878 | 1981 | |! | 16 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |! | 17 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |! | 18 | NESTED LOOPS OUTER | | 1 | 878 | 1988 | |! | 19 | NESTED LOOPS | | 1 | 878 | 1988 | |! | 20 | VIEW | | 1 | 878 | 1988 | |! | 21 | SORT GROUP BY | | 1 | 878 | 1988 | |! | 22 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC_APPT | 1 | 878 | 1988 | 13.37 |! | -> 23 | INDEX FULL SCAN | PK_PAT_ENC_APPT | 7M | 878 | 4G | 85.91 |! | 24 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 1988 | |! | 25 | INDEX UNIQUE SCAN | PK_PAT_ENC | 1 | 1988 | 1988 | |! | 26 | VIEW PUSHED PREDICATE | V_ZC_CANCEL_REASON | 1 | 1988 | 306 | |! | 27 | INDEX UNIQUE SCAN | PK_ZC_CANCEL_REASON | 1 | 1988 | 306 | |! | 28 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 206 | |! | 29 | INDEX RANGE SCAN | EIX_PAT_ENC_001 | 5 | 1988 | 2590 | 0.14 |! | 30 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 1 | 1990 | 305 | 0.05 |! | 31 | INDEX RANGE SCAN | PK_PAT_ENC_ES_AUD_ACT | 4 | 1990 | 4014 | 0.45 |! | -> 32 | INDEX UNIQUE SCAN | PK_PAT_ENC_ES_AUD_ACT | 1 | 1991 | 1981 | |! | 33 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 2 | 1981 | 1981 | |! ==========================================================================================================================!
  • 20. ==========================================================================================================================! | Id | Operation | Name | Rows | Execs | Rows | Activity |! | | | | (Estim) | | (Actual) | (%) |! ==========================================================================================================================! | 0 | UPDATE STATEMENT | | | 1 | | |! | 1 | UPDATE | F_SCHED_APPT_STATS | | 1 | 0 | |! | -> 2 | TABLE ACCESS STORAGE FULL | F_SCHED_APPT_STATS | 1 | 1 | 878 | |! | 3 | TABLE ACCESS BY INDEX ROWID | PAT_PCP | 1 | 1673 | 850 | 0.02 |! | 4 | INDEX RANGE SCAN | PK_PAT_PCP | 13 | 1673 | 19966 | 0.06 |! | 5 | SORT AGGREGATE | | 1 | 97 | 97 | |! | 6 | FILTER | | | 97 | 8713 | |! | 7 | BITMAP CONVERSION TO ROWIDS | | 1494 | 96 | 8713 | |! | 8 | BITMAP INDEX RANGE SCAN | EIX_CALENDAR_WEEKEND | | 96 | 8713 | |! | 9 | SORT AGGREGATE | | 1 | 298 | 298 | |! | 10 | FILTER | | | 298 | 224 | |! | 11 | TABLE ACCESS BY INDEX ROWID | DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |! | 12 | INDEX RANGE SCAN | PK_DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |! | 13 | SORT AGGREGATE | | 1 | 878 | 877 | |! | 14 | NESTED LOOPS | | | 878 | 1981 | |! | 15 | NESTED LOOPS | | 2 | 878 | 1981 | |! | 16 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |! | 17 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |! | 18 | NESTED LOOPS OUTER | | 1 | 878 | 1988 | |! | 19 | NESTED LOOPS | | 1 | 878 | 1988 | |! | 20 | VIEW | | 1 | 878 | 1988 | |! | 21 | SORT GROUP BY | | 1 | 878 | 1988 | |! | 22 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC_APPT | 1 | 878 | 1988 | 13.37 |! | -> 23 | INDEX FULL SCAN | PK_PAT_ENC_APPT | 7M | 878 | 4G | 85.91 |! | 24 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 1988 | |! | 25 | INDEX UNIQUE SCAN | PK_PAT_ENC | 1 | 1988 | 1988 | |! | 26 | VIEW PUSHED PREDICATE | V_ZC_CANCEL_REASON | 1 | 1988 | 306 | |! | 27 | INDEX UNIQUE SCAN | PK_ZC_CANCEL_REASON | 1 | 1988 | 306 | |! | 28 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 206 | |! | 29 | INDEX RANGE SCAN | EIX_PAT_ENC_001 | 5 | 1988 | 2590 | 0.14 |! | 30 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 1 | 1990 | 305 | 0.05 |! | 31 | INDEX RANGE SCAN | PK_PAT_ENC_ES_AUD_ACT | 4 | 1990 | 4014 | 0.45 |! | -> 32 | INDEX UNIQUE SCAN | PK_PAT_ENC_ES_AUD_ACT | 1 | 1991 | 1981 | |! | 33 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 2 | 1981 | 1981 | |! ==========================================================================================================================!
  • 21. =================================================     TABLE  STATISTICS   =================================================   Owner                  :  clr   Table  name        :  pat_enc_appt   Partitioned      :  yes   Last  analyzed  :  08/24/2014  19:26:37   Sample  size      :  145986286   Degree                :  1   #  Rows                :  145986286   #  Blocks            :  1257720   Empty  Blocks    :  0   Avg  Space          :  0   Avg  Row  Length:  59   Monitoring?      :  yes  
  • 22. ======================================================================   INDEX  INFORMATION   ======================================================================                                                                                                                      DISTINCT   INDEX_NAME                                          COLUMN_NAME(S)                          KEYS   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐   eix_pat_enc_appt_coda                    contact_date                              17058     eix_penc_appt_provdep                    prov_id,  department_id          38460     eix_penc_prov_id                              prov_id                                        38460     pk_pat_enc_appt                                pat_enc_csn_id,  line              146535236  
  • 23. ==========================================================================================================================! | Id | Operation | Name | Rows | Execs | Rows | Activity |! | | | | (Estim) | | (Actual) | (%) |! ==========================================================================================================================! | 0 | UPDATE STATEMENT | | | 1 | | |! | 1 | UPDATE | F_SCHED_APPT_STATS | | 1 | 0 | |! | -> 2 | TABLE ACCESS STORAGE FULL | F_SCHED_APPT_STATS | 1 | 1 | 878 | |! | 3 | TABLE ACCESS BY INDEX ROWID | PAT_PCP | 1 | 1673 | 850 | 0.02 |! | 4 | INDEX RANGE SCAN | PK_PAT_PCP | 13 | 1673 | 19966 | 0.06 |! | 5 | SORT AGGREGATE | | 1 | 97 | 97 | |! | 6 | FILTER | | | 97 | 8713 | |! | 7 | BITMAP CONVERSION TO ROWIDS | | 1494 | 96 | 8713 | |! | 8 | BITMAP INDEX RANGE SCAN | EIX_CALENDAR_WEEKEND | | 96 | 8713 | |! | 9 | SORT AGGREGATE | | 1 | 298 | 298 | |! | 10 | FILTER | | | 298 | 224 | |! | 11 | TABLE ACCESS BY INDEX ROWID | DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |! | 12 | INDEX RANGE SCAN | PK_DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |! | 13 | SORT AGGREGATE | | 1 | 878 | 877 | |! | 14 | NESTED LOOPS | | | 878 | 1981 | |! | 15 | NESTED LOOPS | | 2 | 878 | 1981 | |! | 16 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |! | 17 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |! | 18 | NESTED LOOPS OUTER | | 1 | 878 | 1988 | |! | 19 | NESTED LOOPS | | 1 | 878 | 1988 | |! | 20 | VIEW | | 1 | 878 | 1988 | |! | 21 | SORT GROUP BY | | 1 | 878 | 1988 | |! | 22 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC_APPT | 1 | 878 | 1988 | 13.37 |! | -> 23 | INDEX FULL SCAN | PK_PAT_ENC_APPT | 7M | 878 | 4G | 85.91 |! | 24 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 1988 | |! | 25 | INDEX UNIQUE SCAN | PK_PAT_ENC | 1 | 1988 | 1988 | |! | 26 | VIEW PUSHED PREDICATE | V_ZC_CANCEL_REASON | 1 | 1988 | 306 | |! | 27 | INDEX UNIQUE SCAN | PK_ZC_CANCEL_REASON | 1 | 1988 | 306 | |! | 28 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 206 | |! | 29 | INDEX RANGE SCAN | EIX_PAT_ENC_001 | 5 | 1988 | 2590 | 0.14 |! | 30 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 1 | 1990 | 305 | 0.05 |! | 31 | INDEX RANGE SCAN | PK_PAT_ENC_ES_AUD_ACT | 4 | 1990 | 4014 | 0.45 |! | -> 32 | INDEX UNIQUE SCAN | PK_PAT_ENC_ES_AUD_ACT | 1 | 1991 | 1981 | |! | 33 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 2 | 1981 | 1981 | |! ==========================================================================================================================!
  • 24. ===============================================      TABLE  STATISTICS   ===============================================   Owner                  :  c_stage   Table  name        :  f_sched_appt_stats   Partitioned      :  no   Last  analyzed  :  08/23/2014  15:53:52   Sample  size      :  0   Degree                :  1   #  Rows                :  0   #  Blocks            :  20   Empty  Blocks    :  0   Avg  Space          :  0   Avg  Row  Length:  0   Monitoring?      :  yes  
  • 25. ==========================================================================================================================! | Id | Operation | Name | Rows | Execs | Rows | Activity |! | | | | (Estim) | | (Actual) | (%) |! ==========================================================================================================================! | 0 | UPDATE STATEMENT | | | 1 | | |! | 1 | UPDATE | F_SCHED_APPT_STATS | | 1 | 0 | |! | -> 2 | TABLE ACCESS STORAGE FULL | F_SCHED_APPT_STATS | 1 | 1 | 878 | |! | 3 | TABLE ACCESS BY INDEX ROWID | PAT_PCP | 1 | 1673 | 850 | 0.02 |! | 4 | INDEX RANGE SCAN | PK_PAT_PCP | 13 | 1673 | 19966 | 0.06 |! | 5 | SORT AGGREGATE | | 1 | 97 | 97 | |! | 6 | FILTER | | | 97 | 8713 | |! | 7 | BITMAP CONVERSION TO ROWIDS | | 1494 | 96 | 8713 | |! | 8 | BITMAP INDEX RANGE SCAN | EIX_CALENDAR_WEEKEND | | 96 | 8713 | |! | 9 | SORT AGGREGATE | | 1 | 298 | 298 | |! | 10 | FILTER | | | 298 | 224 | |! | 11 | TABLE ACCESS BY INDEX ROWID | DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |! | 12 | INDEX RANGE SCAN | PK_DEPARTMENT_HOLIDAY | 1 | 295 | 224 | |! | 13 | SORT AGGREGATE | | 1 | 878 | 877 | |! | 14 | NESTED LOOPS | | | 878 | 1981 | |! | 15 | NESTED LOOPS | | 2 | 878 | 1981 | |! | 16 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |! | 17 | NESTED LOOPS OUTER | | 1 | 878 | 1990 | |! | 18 | NESTED LOOPS OUTER | | 1 | 878 | 1988 | |! | 19 | NESTED LOOPS | | 1 | 878 | 1988 | |! | 20 | VIEW | | 1 | 878 | 1988 | |! | 21 | SORT GROUP BY | | 1 | 878 | 1988 | |! | 22 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC_APPT | 1 | 878 | 1988 | 13.37 |! | -> 23 | INDEX FULL SCAN | PK_PAT_ENC_APPT | 7M | 878 | 4G | 85.91 |! | 24 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 1988 | |! | 25 | INDEX UNIQUE SCAN | PK_PAT_ENC | 1 | 1988 | 1988 | |! | 26 | VIEW PUSHED PREDICATE | V_ZC_CANCEL_REASON | 1 | 1988 | 306 | |! | 27 | INDEX UNIQUE SCAN | PK_ZC_CANCEL_REASON | 1 | 1988 | 306 | |! | 28 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1988 | 206 | |! | 29 | INDEX RANGE SCAN | EIX_PAT_ENC_001 | 5 | 1988 | 2590 | 0.14 |! | 30 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 1 | 1990 | 305 | 0.05 |! | 31 | INDEX RANGE SCAN | PK_PAT_ENC_ES_AUD_ACT | 4 | 1990 | 4014 | 0.45 |! | -> 32 | INDEX UNIQUE SCAN | PK_PAT_ENC_ES_AUD_ACT | 1 | 1991 | 1981 | |! | 33 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 2 | 1981 | 1981 | |! ==========================================================================================================================!
  • 26. What  would   you  do?   Rewrite  the  query?   Modify,  drop  or  create  an  index?   Gather  staKsKcs?   Change  parKKoning  scheme?   Rebuild  tables?   Rebuild  indexes?  
  • 27. ---------------------------------------------------------------------------------------------! | Id | Operation | Name | New | Old |! ---------------------------------------------------------------------------------------------! | 0 | UPDATE STATEMENT | | 2271 | | ! | 1 | UPDATE | F_SCHED_APPT_STATS | | | ! | 2 | TABLE ACCESS STORAGE FULL | F_SCHED_APPT_STATS | 2271 | 1 | ! | 3 | TABLE ACCESS BY INDEX ROWID | PAT_PCP | 1 | 1 | ! | 4 | INDEX RANGE SCAN | PAT_PCP_PAID | 6 | 13 | PK_PAT_PCP! | 5 | SORT AGGREGATE | | 1 | 1 | ! | 6 | FILTER | | | | ! | 7 | BITMAP CONVERSION TO ROWIDS | | 165 | 1494 | ! | 8 | BITMAP INDEX RANGE SCAN | EIX_CALENDAR_WEEKEND | | | ! | 9 | SORT AGGREGATE | | 1 | 1 | ! | 10 | FILTER | | | | ! | 11 | TABLE ACCESS BY INDEX ROWID | DEPARTMENT_HOLIDAY | 1 | 1 | ! | 12 | INDEX RANGE SCAN | PK_DEPARTMENT_HOLIDAY | 1 | 1 | ! | 13 | SORT AGGREGATE | | 1 | 1 | ! | 14 | NESTED LOOPS | | | | ! | 15 | NESTED LOOPS | | 2 | 2 | ! | 16 | NESTED LOOPS OUTER | | 1 | 1 | ! | 17 | NESTED LOOPS OUTER | | 1 | 1 | ! | 18 | NESTED LOOPS OUTER | | 1 | 1 | ! | 19 | NESTED LOOPS | | 1 | 1 | ! | 20 | VIEW | | 1 | 1 | ! | 21 | SORT GROUP BY | | 1 | 1 | ! | 22 | TABLE ACCESS BY GLOBAL INDEX ROWID| PAT_ENC_APPT | 1 | 1 | ! | 23 | INDEX RANGE SCAN | EIX_PENC_APPT_PROVDEP | 3 | 7M | INDEX FULL SCAN | PK_PAT_ENC_APPT! | 24 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1 |! | 25 | INDEX UNIQUE SCAN | PK_PAT_ENC | 1 | 1 |! | 26 | VIEW PUSHED PREDICATE | V_ZC_CANCEL_REASON | 1 | 1 |! | 27 | INDEX UNIQUE SCAN | PK_ZC_CANCEL_REASON | 1 | 1 |! | 28 | TABLE ACCESS BY GLOBAL INDEX ROWID | PAT_ENC | 1 | 1 |! | 29 | INDEX RANGE SCAN | EIX_PAT_ENC_001 | 4 | 5 |! | 30 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 1 | 1 |! | 31 | INDEX RANGE SCAN | PK_PAT_ENC_ES_AUD_ACT | 3 | 4 |! | 32 | INDEX UNIQUE SCAN | PK_PAT_ENC_ES_AUD_ACT | 1 | 1 |! | 33 | TABLE ACCESS BY INDEX ROWID | PAT_ENC_ES_AUD_ACT | 1 | 2 |! ---------------------------------------------------------------------------------------------! Afer  collecKng  stats  on  F_SCHED_APPT_STATS…   9  seconds!  
  • 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  
  • 33. =====================================================================================================================! | Id | Operation | Name | Rows | Execs | Rows | Activity |! | | | | (Estim) | | (Actual) | (%) |! =====================================================================================================================! | 0 | SELECT STATEMENT | | | 1 | 4 | |! | 1 | HASH UNIQUE | | 3512 | 1 | 4 | |! | 2 | HASH GROUP BY | | 3512 | 1 | 146K | 0.29 |! | 3 | NESTED LOOPS | | 3512 | 1 | 1M | |! | 4 | NESTED LOOPS | | 3512 | 1 | 1M | 0.29 |! | 5 | NESTED LOOPS | | 3512 | 1 | 1M | |! | 6 | NESTED LOOPS | | 3512 | 1 | 1M | |! | 7 | NESTED LOOPS OUTER | | 1 | 1 | 4 | |! | 8 | NESTED LOOPS | | 1 | 1 | 4 | |! | 9 | NESTED LOOPS | | 1 | 1 | 4 | |! | 10 | NESTED LOOPS | | 1 | 1 | 1 | |! | 11 | TABLE ACCESS BY INDEX ROWID | MAP_CODE | 1 | 1 | 1 | |! | 12 | INDEX UNIQUE SCAN | MAP_CODE_MC_IDX | 1 | 1 | 1 | |! | 13 | TABLE ACCESS BY INDEX ROWID | DESTINATION | 1 | 1 | 1 | |! | 14 | INDEX UNIQUE SCAN | DESTINATION_MAP_CODE_UK | 1 | 1 | 1 | |! | 15 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_DATA | 1 | 1 | 4 | |! | 16 | INDEX RANGE SCAN | MAP_CODE_DATA_MAP_CODE_IDX | 2 | 1 | 4 | |! | 17 | TABLE ACCESS BY INDEX ROWID | MAP_CLASS | 1 | 4 | 4 | |! | 18 | INDEX UNIQUE SCAN | MAP_CLASS_PK | 1 | 4 | 4 | |! | 19 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_CONTEXT | 1 | 4 | 4 | |! | 20 | INDEX UNIQUE SCAN | MAP_CODE_CONTEXT_PK | 1 | 4 | 4 | |! | 21 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PROD_DESTINATION | 5045 | 4 | 1M | 10.03 |! | 22 | INDEX RANGE SCAN | IDX_SPD_DEST | 6167 | 4 | 1M | 2.29 |! | 23 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PRODUCT_CFG | 1 | 1M | 1M | 57.31 |! | 24 | INDEX UNIQUE SCAN | PK_SPONSOR_PRODUCT_CFG | 1 | 1M | 1M | 10.60 |! | 25 | INDEX UNIQUE SCAN | PK_SPONSOR_PRODUCT_GRP | 1 | 1M | 1M | 7.16 |! | 26 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PRODUCT_GRP | 1 | 1M | 1M | 12.03 |! =====================================================================================================================! 5  minutes  49  seconds        LIO  =  7M+            PIO  =  140K+  
  • 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?  
  • 40. =====================================================================================================================! | Id | Operation | Name | Rows | Execs | Rows | Activity |! | | | | (Estim) | | (Actual) | (%) |! =====================================================================================================================! | 0 | SELECT STATEMENT | | | 1 | 4 | |! | 1 | HASH UNIQUE | | 3512 | 1 | 4 | |! | 2 | HASH GROUP BY | | 3512 | 1 | 146K | 0.29 |! | 3 | NESTED LOOPS | | 3512 | 1 | 1M | |! | 4 | NESTED LOOPS | | 3512 | 1 | 1M | 0.29 |! | 5 | NESTED LOOPS | | 3512 | 1 | 1M | |! | 6 | NESTED LOOPS | | 3512 | 1 | 1M | |! | 7 | NESTED LOOPS OUTER | | 1 | 1 | 4 | |! | 8 | NESTED LOOPS | | 1 | 1 | 4 | |! | 9 | NESTED LOOPS | | 1 | 1 | 4 | |! | 10 | NESTED LOOPS | | 1 | 1 | 1 | |! | 11 | TABLE ACCESS BY INDEX ROWID | MAP_CODE | 1 | 1 | 1 | |! | 12 | INDEX UNIQUE SCAN | MAP_CODE_MC_IDX | 1 | 1 | 1 | |! | 13 | TABLE ACCESS BY INDEX ROWID | DESTINATION | 1 | 1 | 1 | |! | 14 | INDEX UNIQUE SCAN | DESTINATION_MAP_CODE_UK | 1 | 1 | 1 | |! | 15 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_DATA | 1 | 1 | 4 | |! | 16 | INDEX RANGE SCAN | MAP_CODE_DATA_MAP_CODE_IDX | 2 | 1 | 4 | |! | 17 | TABLE ACCESS BY INDEX ROWID | MAP_CLASS | 1 | 4 | 4 | |! | 18 | INDEX UNIQUE SCAN | MAP_CLASS_PK | 1 | 4 | 4 | |! | 19 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_CONTEXT | 1 | 4 | 4 | |! | 20 | INDEX UNIQUE SCAN | MAP_CODE_CONTEXT_PK | 1 | 4 | 4 | |! | 21 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PROD_DESTINATION | 5045 | 4 | 1M | 10.03 |! | 22 | INDEX RANGE SCAN | IDX_SPD_DEST | 6167 | 4 | 1M | 2.29 |! | 23 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PRODUCT_CFG | 1 | 1M | 1M | 57.31 |! | 24 | INDEX UNIQUE SCAN | PK_SPONSOR_PRODUCT_CFG | 1 | 1M | 1M | 10.60 |! | 25 | INDEX UNIQUE SCAN | PK_SPONSOR_PRODUCT_GRP | 1 | 1M | 1M | 7.16 |! | 26 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PRODUCT_GRP | 1 | 1M | 1M | 12.03 |! =====================================================================================================================! 5  minutes  49  seconds        LIO  =  7M+            PIO  =  140K+  
  • 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  
  • 43. ---------------------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads | ---------------------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | | 4 |00:00:00.02 | 21 | 3 | | 1 | HASH UNIQUE | | 1 | 1 | 4 |00:00:00.02 | 21 | 3 | | 2 | NESTED LOOPS OUTER | | 1 | 1 | 4 |00:00:00.02 | 21 | 3 | | 3 | NESTED LOOPS | | 1 | 1 | 4 |00:00:00.02 | 15 | 3 | | 4 | NESTED LOOPS | | 1 | 1 | 4 |00:00:00.01 | 9 | 2 | | 5 | NESTED LOOPS | | 1 | 1 | 1 |00:00:00.01 | 5 | 0 | | 6 | TABLE ACCESS BY INDEX ROWID| MAP_CODE | 1 | 1 | 1 |00:00:00.01 | 3 | 0 | |* 7 | INDEX UNIQUE SCAN | MAP_CODE_MC_IDX | 1 | 1 | 1 |00:00:00.01 | 2 | 0 | |* 8 | INDEX UNIQUE SCAN | DESTINATION_MAP_CODE_UK | 1 | 1 | 1 |00:00:00.01 | 2 | 0 | | 9 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_DATA | 1 | 1 | 4 |00:00:00.01 | 4 | 2 | |* 10 | INDEX RANGE SCAN | MAP_CODE_DATA_MAP_CODE_IDX | 1 | 2 | 4 |00:00:00.01 | 2 | 2 | | 11 | TABLE ACCESS BY INDEX ROWID | MAP_CLASS | 4 | 1 | 4 |00:00:00.01 | 6 | 1 | |* 12 | INDEX UNIQUE SCAN | MAP_CLASS_PK | 4 | 1 | 4 |00:00:00.01 | 2 | 1 | | 13 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_CONTEXT | 4 | 1 | 4 |00:00:00.01 | 6 | 0 | |* 14 | INDEX UNIQUE SCAN | MAP_CODE_CONTEXT_PK | 4 | 1 | 4 |00:00:00.01 | 2 | 0 | ---------------------------------------------------------------------------------------------------------------------------------- .02  seconds        LIO  =  21            PIO  =  3  
  • 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  
  • 45. ---------------------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads | ---------------------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | | 4 |00:00.21 | 904 | 25 | | 1 | HASH UNIQUE | | 1 | 1 | 4 |00:00.21 | 904 | 25 | | 2 | NESTED LOOPS OUTER | | 1 | 1 | 188 |00:00.21 | 904 | 25 | | 3 | NESTED LOOPS | | 1 | 1 | 188 |00:00.21 | 712 | 25 | | 4 | NESTED LOOPS | | 1 | 5 | 188 |00:00.10 | 370 | 11 | |* 5 | HASH JOIN | | 1 | 5 | 188 |00:00.03 | 52 | 2 | |* 6 | HASH JOIN | | 1 | 6 | 188 |00:00.02 | 46 | 2 | | 7 | NESTED LOOPS | | 1 | 7 | 47 |00:00.02 | 31 | 2 | | 8 | NESTED LOOPS | | 1 | 1 | 1 |00:00.01 | 6 | 0 | | 9 | TABLE ACCESS BY INDEX ROWID| MAP_CODE | 1 | 1 | 1 |00:00.01 | 3 | 0 | |* 10 | INDEX UNIQUE SCAN | MAP_CODE_MC_IDX | 1 | 1 | 1 |00:00.01 | 2 | 0 | | 11 | TABLE ACCESS BY INDEX ROWID| DESTINATION | 1 | 1 | 1 |00:00.01 | 3 | 0 | |* 12 | INDEX UNIQUE SCAN | DESTINATION_MAP_CODE_UK | 1 | 1 | 1 |00:00.01 | 2 | 0 | | 13 | TABLE ACCESS BY INDEX ROWID | SPONSOR_PRODUCT_GRP | 1 | 7 | 47 |00:00.02 | 25 | 2 | |* 14 | INDEX RANGE SCAN | SPONSOR_PRODUCT_GRP_SPONSOR | 1 | 7 | 47 |00:00.02 | 3 | 2 | | 15 | TABLE ACCESS FULL | MAP_CODE_DATA | 1 | 715 | 715 |00:00.01 | 15 | 0 | | 16 | TABLE ACCESS FULL | MAP_CLASS | 1 | 189 | 189 |00:00.01 | 6 | 0 | |* 17 | INDEX RANGE SCAN | IDX_SPC_SPG_PP_OID | 188 | 1 | 188 |00:00.07 | 318 | 9 | |* 18 | INDEX UNIQUE SCAN | SPONSOR_PROD_DEST_SD_UK | 188 | 1 | 188 |00:00.11 | 342 | 14 | | 19 | TABLE ACCESS BY INDEX ROWID | MAP_CODE_CONTEXT | 188 | 1 | 188 |00:00.01 | 192 | 0 | |* 20 | INDEX UNIQUE SCAN | MAP_CODE_CONTEXT_PK | 188 | 1 | 188 |00:00.01 | 4 | 0 | ---------------------------------------------------------------------------------------------------------------------------------- .21  seconds        LIO  =  904            PIO  =  25  
  • 47. 2  Cases.     2  Very  Different  SoluKons.    
  • 48. 1   StaKsKcs.     2   Prac<cal  SQL  constructs.  
  • 49. Don't  limit  yourself.     Just  because  something   worked  once  doesn't  mean  it's   the  best  choice  for  another   case.  
  • 50. Find  it.     5  Whys.     Evaluate  SoluKon(s).     Fix  it!