You are on page 1of 47

1 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.

The following is intended to outline our general product direction.
It is intended for information purposes only, and may not be
incorporated into any contract. It is not a commitment to deliver
any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and
ti i f f t f ti lit d ib d f O l ’ timing of any features or functionality described for Oracle’s
products remains at the sole discretion of Oracle.
All the views expressed in this presentation are the opinion of the
authors and do not necessarily reflect the views of Oracle.
The queries are provided "as is", without warranty of any kind,
expressed or implied.
2 Copyright ©2011, Oracle and/or its affiliates. All rights reserved. 2 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
SQL Performance Tuning with Oracle AWR & ASH
3 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
Real World Use Cases
About myself
•Vlado Barun, M.Sc.
– Sr Principal Performance Engineer with Oracle Cloud Services Sr. Principal Performance Engineer with Oracle Cloud Services
– OCP, OCE SQL, MCP
– 15 years in the Database Arena (Oracle DB - 10 years)
4 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
Objective
•Enable you to start exploring the rich repository of
performance metrics inASH &AWR independent of any performance metrics in ASH & AWR independent of any
specific GUI and related limitations
•Provide list of resources that enable you to “hit the
ground running”
5 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
Agenda
•Introduction to ASH & AWR (very brief)
•Review2 real world production use cases •Review 2 real world production use cases
– step-by-step from data gathering to resolution
– write ASH/AWR queries from scratch
– use pre-existing free scripts
– Note: check license requirements
•Resources Resources
6 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
Automatic Workload Repository (AWR)
•Collects database performance statistics
– Objects (access and usage statistics)
– SQL Statement statistics SQL Statement statistics
– Wait events statistics
– System statistics
ASH Statistics (DBA HIST ACTIVE SESS HISTORY) – ASH Statistics (DBA_HIST_ACTIVE_SESS_HISTORY)
– Time Model Statistics based on time usage for activities
– Every 1 hr by default
•Stored in DBA_HIST% views
•How to access?
$ORACLE HOME/rdbms/admin/awrrpt sql SQLT custom – $ORACLE_HOME/rdbms/admin/awrrpt.sql, SQLT, custom
scripts,…
– OEM, SQL Developer
Oth t l
7 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
– Other tools
Active Session History (ASH) Introduction
v$active_session_history
(1 d i l )
dba_hist_active_sess_history
(10 second inter als)
(1 second intervals)
(10 second intervals)
3 ASH Samples in 
AWR
Browse
Books
Read Reviews
For One Book
Add to Cart
Checkout
TIME
21 ASH Samples
= time spent in database
SQL Trace (Microsecond level)
Application Logging (custom level)
8 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
When Row Source Object
ASH - Dimensions
SAMPLE_ID
SAMPLE_TIME
Session
SESSION ID
SQL_PLAN_LINE_ID
SQL_PLAN_OPERATION
Waits
EVENT
j
CURRENT_OBJ#
CURRENT_FILE#
CURRENT_BLOCK#
CURRENT_ROW#
A li ti
SESSION_ID
SESSION_SERIAL#
SESSION_TYPE
SESSION_STATE
USER_ID
QC_INSTANCE_ID
QC SESSION ID
EVENT
EVENT_ID
EVENT#
SEQ#
P1TEXT
P1
P2TEXT
Application
SERVICE_HASH
PROGRAM
MODULE
ACTION
MACHINE
QC_SESSION_ID
QC_SESSION_SERIAL#
CLIENT_ID
IN and IS columns
SQL
P2TEXT
P2
P3TEXT
P3
WAIT_CLASS
WAIT_CLASS_ID
WAIT TIME
MACHINE
Statistics
TM_DELTA_TIME
TM DELTA CPU TIME
SQL
SQL_ID
IS_SQLID_CURRENT
SQL_CHILD_NUMBER
SQL_OPCODE
SQL_OPNAME
TOP LEVEL SQL ID
WAIT_TIME
TIME_WAITED
CURRENT_OBJ#
CURRENT_FILE#
CURRENT_BLOCK#
CURRENT_ROW#
TM_DELTA_CPU_TIME
TM_DELTA_DB_TIME
DELTA_TIME
DELTA_READ_IO_REQUESTS
DELTA_WRITE_IO_REQUESTS
DELTA_READ_IO_BYTES
TOP_LEVEL_SQL_ID
TOP_LEVEL_SQL_OPCODE
SQL_EXEC_ID
SQL_EXEC_START
SQL_PLAN_HASH_VALUE
SQL_PLAN_OPTIONS
Blocking Session
BLOCKING_SESSION_STATUS
BLOCKING_SESSION
BLOCKING_SESSION_SERIAL#
OC G S
DELTA_WRITE_IO_BYTES
DELTA_INTERCONNECT_IO_BYTES
PGA_ALLOCATED
TEMP_SPACE_ALLOCATED
9 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
BLOCKING_INST_ID
BLOCKING_HANGCHAIN_INFO
ASH - Summary
•Samples the current state of all active session
– 1 second samples
Stores various attributes (dimensions) of a session – Stores various attributes (dimensions) of a session
•Stored in
– V$ACTIVE_SESSION_HISTORY _ _
•1-second sampling rate
– DBA_HIST_ACTIVE_SESS_HISTORY
- Sub-sampling to disk into AWR Snapshot
- 1-in-10 samples
•How to access?
- $ORACLE HOME/rdbms/admin/ashrpt.sql, ashrpti.sql, SQLT, custom $ORACLE_HOME/rdbms/admin/ashrpt.sql, ashrpti.sql, SQLT, custom
scripts,…
- OEM, SQL Developer, Real Time SQL Monitoring, …
- Other tools
10 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
GUI command line or
•It is about knowing the right tool for the right situation
•Understand the strengths and weaknesses of each
GUI t l t th
d li k
•GUI tools strengths
– Easy to use
– Good visualization of data
=> cmd line weaknesses
Good visualization of data
– Provides concise summary of system activity
– etc…
Performance 
data
•GUI tools weaknesses
– Slow - click…wait…click…wait…
A il bilit GUI i f t t i d
Performance data 
exposed by GUI
=> cmd line strength
– Availability – GUI infrastructure is down
– Limited exposure – subset of available data
– etc
11 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
etc…
ASH dimensions growth
See 
https://sites.google.com/site/embtdbo/wait‐event‐documentation/ash‐‐‐active‐session‐history
12 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
Wh t
Id tif
Understand the issue
What
Identify
(app is slow)
Quantify
Initial
Data
collection
How Much
(takes 1m)
Timeline
(during peak hours)
AWR/ASH, Trace,
Apps Logs/Tables,
OS/IO stats etc
When
( gp )
Component
(Web Tier, App Tier,
DB , Network, Storage,
Where
Analyze
etc.)
Flow chart
How
Additional
Root Cause
(Stats not updated)
SQL/Object Stats,
Execution Plans,
etc
Why
Additional
Data
Collection
and
Analysis
13 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
Use Case 1
What
SlowETL
What
Slow ETL
20+ hours
How Much
Once a month
When
Informatica + DB
Where
How
Extract, Transform, Load
14 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
Find slow SQL (ASH)
SQL> SELECT sql_id
2 , COUNT(*) as sample_count
3 FROM v$active_session_history _ _
4 WHERE sample_time BETWEEN TO_DATE('2011-06-29 07:57', 'yyyy-mm-dd hh24:mi')
5 AND TO_DATE('2011-06-30 04:30', 'yyyy-mm-dd hh24:mi')
6 AND user_id = 61
7 AND program like 'pmdtm@%'
8 GROUP BY sql id 8 GROUP BY sql_id
9 ORDER BY 2 DESC
10 ;
no rows selected
SQL> SELECT min(sample_time)
2 FROM v$active_session_history
3 ;
MIN(SAMPLE_TIME)
----------------------------------------
2011-07-01 19:14:48
1 row selected.
15 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
Find slow SQL (ASH in AWR)
SELECT sql_id
, COUNT(*) as sample_count
FROM dba_hist_active_sess_history v$active_session_history
WHERE sample time BETWEEN TO DATE('2011-06-29 07:57' 'yyyy-mm-dd hh24:mi')
JOIN dba_hist_snapshot USING (dbid, instance_number, snap_id)
WHERE sample_time BETWEEN TO_DATE( 2011-06-29 07:57 , yyyy-mm-dd hh24:mi )
AND TO_DATE('2011-06-30 04:30', 'yyyy-mm-dd hh24:mi')
AND user_id = 61
AND program like 'pmdtm@%‘
GROUP BY sql id
_ _ _ _
AND begin interval time BETWEEN TO DATE('2011-06-29 07:00' 'yyyy-mm-dd hh24:mi')
GROUP BY sql_id
ORDER BY 2 DESC
;
AND begin_interval_time BETWEEN TO_DATE( 2011 06 29 07:00 , yyyy mm dd hh24:mi )
AND TO_DATE('2011-06-30 05:00', 'yyyy-mm-dd hh24:mi')
SQL_ID SAMPLE_COUNT _ _
------------- ------------
dkwucgaxxhm2z 7362
grksgbxxuacaf 6041

24 rows selected
16 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
24 rows selected.
Find slow SQL (ASH in AWR) - readable
SQL>SELECT sql id sql type SQL>SELECT sql_id, sql_type
2 , round(sample_cnt_sql/sample_cnt_total*100) as sample_pct
3 , round(sample_cnt_sql /6/60,1) hours
4 FROM(SELECT DISTINCT sql_id
5 , aa.name AS sql_type
6 , COUNT(*) over (PARTITION BY sql_id) AS sample_cnt_sql
7 , COUNT(*) over () AS sample_cnt_total
8 FROM dba_hist_active_sess_history ash
9 JOIN dba_hist_snapshot s USING (dbid, INSTANCE_NUMBER, snap_id)
10 JOIN audit actions aa on (ash.sql opcode = aa.action) 10 JOIN audit_actions aa on (ash.sql_opcode aa.action)
11 WHERE begin_interval_time BETWEEN
… snip …
18 ORDER BY 3 desc)
19 WHERE rownum <= 3;
SQL_ID SQL_TYPE SAMPLE_PCT HOURS
------------- -------- ---------- -----
dkwucgaxxhm2z SELECT 25 20.4
grksgbxxuacaf SELECT 21 16 8 grksgbxxuacaf SELECT 21 16.8
gh6w2fm3avn3j SELECT 12 10.1
3 rows selected.
17 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
When Row Source Object
Active Session History (ASH) - Dimensions
SAMPLE_ID
SAMPLE_TIME
Session
SESSION ID
SQL_PLAN_LINE_ID
SQL_PLAN_OPERATION
Waits
EVENT
j
CURRENT_OBJ#
CURRENT_FILE#
CURRENT_BLOCK#
CURRENT_ROW#
A li ti
SESSION_ID
SESSION_SERIAL#
SESSION_TYPE
SESSION_STATE
USER_ID
QC_INSTANCE_ID
QC SESSION ID
EVENT
EVENT_ID
EVENT#
SEQ#
P1TEXT
P1
P2TEXT
Application
SERVICE_HASH
PROGRAM
MODULE
ACTION
MACHINE
QC_SESSION_ID
QC_SESSION_SERIAL#
CLIENT_ID
IN and IS columns
SQL
P2TEXT
P2
P3TEXT
P3
WAIT_CLASS
WAIT_CLASS_ID
WAIT TIME
MACHINE
Statistics
TM_DELTA_TIME
TM DELTA CPU TIME
SQL
SQL_ID
IS_SQLID_CURRENT
SQL_CHILD_NUMBER
SQL_OPCODE
SQL_OPNAME
TOP LEVEL SQL ID
WAIT_TIME
TIME_WAITED
CURRENT_OBJ#
CURRENT_FILE#
CURRENT_BLOCK#
CURRENT_ROW#
TM_DELTA_CPU_TIME
TM_DELTA_DB_TIME
DELTA_TIME
DELTA_READ_IO_REQUESTS
DELTA_WRITE_IO_REQUESTS
DELTA_READ_IO_BYTES
TOP_LEVEL_SQL_ID
TOP_LEVEL_SQL_OPCODE
SQL_EXEC_ID
SQL_EXEC_START
SQL_PLAN_HASH_VALUE
SQL_PLAN_OPTIONS
Blocking Session
BLOCKING_SESSION_STATUS
BLOCKING_SESSION
BLOCKING_SESSION_SERIAL#
OC G S
DELTA_WRITE_IO_BYTES
DELTA_INTERCONNECT_IO_BYTES
PGA_ALLOCATED
TEMP_SPACE_ALLOCATED
18 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
BLOCKING_INST_ID
BLOCKING_HANGCHAIN_INFO
AWR SQL stats
SQL> SELECT PLAN HASH VALUE SQL> SELECT PLAN_HASH_VALUE,
2 , sum(EXECUTIONS_DELTA) as executions
3 , sum(ROWS_PROCESSED_DELTA) as rows_processed
4 , sum(ELAPSED_TIME_DELTA) as elapsed_time
5 , sum(CPU_TIME_DELTA) as cpu_time, sum(IOWAIT_DELTA) as iowait_time
6 , sum(DIRECT_WRITES_DELTA) as direct_writes
7 , sum(BUFFER_GETS_DELTA) as LIO, sum(DISK_READS_DELTA) as PIO
8 FROM dba_hist_sqlstat
9 WHERE snap_id between 132042 and 132124
10 AND sql id = 'dkwucgaxxhm2z' 10 AND sql_id dkwucgaxxhm2z
11 GROUP BY sql_id, PLAN_HASH_VALUE, OPTIMIZER_ENV_HASH_VALUE;
Plan IO
Hash Rows Elapsed CPU WAIT Direct
Value EXECUTIONS Processed Time TIME TIME Writes LIO PIO Value EXECUTIONS Processed Time TIME TIME Writes LIO PIO
---------- ---------- ---------- ---------- ---------- ----------- -------- -------- -------
1700726234 1 5997889 7.3806E+10 903837577 73047955458 219418 36152215 6427679
1 row selected.
19 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
AWR SQL stats - readable
SQL> SELECT PLAN HASH VALUE executions SQL> SELECT PLAN_HASH_VALUE, executions
2 , round(elapsed_time /1000000/60/60,1) as elapsed_hours
3 , rows_processed
4 , round(cpu_time /elapsed_time * 100) as cpu_time_pct
5 round(iowait time /elapsed time * 100) as iowait pct 5 , round(iowait_time /elapsed_time 100) as iowait_pct
6 , LIO, PIO, direct_writes
7 , round(iowait_time /PIO/1000,1) as mili_sec_PIO
8 FROM(SELECT PLAN_HASH_VALUE
9 , sum(EXECUTIONS DELTA) as executions 9 , sum(EXECUTIONS_DELTA) as executions
10 , sum(ROWS_PROCESSED_DELTA) as rows_processed
11 , sum(ELAPSED_TIME_DELTA) as elapsed_time
12 , sum(CPU_TIME_DELTA) as cpu_time, sum(IOWAIT_DELTA) as iowait_time
13 , sum(DIRECT_WRITES_DELTA) as direct_writes
14 , sum(BUFFER_GETS_DELTA) as LIO, sum(DISK_READS_DELTA) as PIO
15 FROM dba_hist_sqlstat
16 WHERE snap_id between 132042 and 132124
17 AND sql_id = 'dkwucgaxxhm2z'
18 GROUP BY sql id, PLAN HASH VALUE); q _ , _ _ );
Plan CPU IO Milisec
Hash Elapsed Rows TIME WAIT Direct /
Value EXECUTIONS Hours Processed PCT PCT LIO PIO Writes Pio
---------- ---------- -------- ---------- ---- ----- ---------- ---------- -------- -------
20 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.
1700726234 1 20.5 5,997,889 1 99 36,152,215 6,427,679 219,418 11.4
AWR SQL plan
SQL>select * from table(dbms xplan display awr('dkwucgaxxhm2z' 1700726234 null SQL>select * from table(dbms_xplan.display_awr( dkwucgaxxhm2z , 1700726234, null,
'ALL LAST'));
----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | | 9553K(100)| |
| 1 | NESTED LOOPS OUTER | | 8011K| 46G| | 9553K (1)| 31:50:39 |
| 2 | NESTED LOOPS OUTER | | 8011K| 45G| | 7148K (1)| 23 49 40 | | 2 | NESTED LOOPS OUTER | | 8011K| 45G| | 7148K (1)| 23:49:40 |
| 3 | NESTED LOOPS OUTER | | 8011K| 45G| | 4743K (1)| 15:48:44 |
| 4 | NESTED LOOPS OUTER | | 8011K| 45G| | 3941K (1)| 13:08:24 |
| 5 | NESTED LOOPS OUTER | | 8011K| 44G| | 3140K (1)| 10:28:03 |
| 6 | HASH JOIN RIGHT OUTER | | 8011K| 44G| | 2338K (1)| 07:47:43 |
| 7 | VIEW | index$_join$_009 | 6633 | 285K| | 39 (3)| 00:00:01 |
| 8 | HASH JOIN | | | | | | |
| 9 | HASH JOIN | | | | | | |
| 10 | INDEX FAST FULL SCAN | S_SRC_M10 | 6633 | 285K| | 10 (0)| 00:00:01 |
| 11 | INDEX FAST FULL SCAN | S SRC M12 | 6633 | 285K| | 10 (0)| 00:00:01 | | 11 | INDEX FAST FULL SCAN | S_SRC_M12 | 6633 | 285K| | 10 (0)| 00:00:01 |
| 12 | INDEX FAST FULL SCAN | S_SRC_P1 | 6633 | 285K| | 8 (0)| 00:00:01 |
| 13 | HASH JOIN RIGHT OUTER | | 8011K| 44G| 228M| 2338K (1)| 07:47:42 |
| 14 | TABLE ACCESS FULL | S_ORG_EXT_LSX | 7488K| 142M| | 38163 (2)| 00:07:38 |
| 15 | HASH JOIN RIGHT OUTER | | 8011K| 43G| | 51545 (1)| 00:10:19 |
| 16 | TABLE ACCESS FULL | S_INDUST_LANG | 4023 | 113K| | 199 (0)| 00:00:03 |
| 17 | HASH JOIN RIGHT OUTER | | 8011K| 43G| | 51289 (1)| 00:10:16 |
| 18 | TABLE ACCESS FULL | S_ORG_PRTNR | 324 | 43740 | | 8 (0)| 00:00:01 |
| 19 | NESTED LOOPS OUTER | | 8011K| 42G| | 51224 (1)| 00:10:15 |
| 20 | VIEW | | 8011K| 42G| | 51169 (1)| 00:10:15 | | 20 | VIEW | | 8011K| 42G| | 51169 (1)| 00:10:15 |
| 21 | NESTED LOOPS | | | | | | |
| 22 | NESTED LOOPS | | 8011K| 8091M| | 51169 (1)| 00:10:15 |
| 23 | INDEX FULL SCAN | SO_ANA_BU_U2 | 19 | 285 | | 1 (0)| 00:00:01 |
| 24 | INDEX RANGE SCAN | S_ORG_EXT_M91 | 74493 | | | 35 (3)| 00:00:01 |
| 25 | TABLE ACCESS BY INDEX ROWID| S_ORG_EXT | 421K| 419M| | 2693 (1)| 00:00:33 |
| 26 | TABLE ACCESS BY INDEX ROWID | S_OU_PRTNR_TYPE | 1 | 94 | | 1 (0)| 00:00:01 |
| 27 | INDEX UNIQUE SCAN | S_OU_PRTNR_TYPE_P1 | 1 | | | 1 (0)| 00:00:01 |
| 28 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 42 | | 1 (0)| 00:00:01 |
| 29 | INDEX UNIQUE SCAN | S ORG EXT P1 | 1 | | | 1 (0)| 00:00:01 | _ _ _
| 30 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 42 | | 1 (0)| 00:00:01 |
| 31 | INDEX UNIQUE SCAN | S_ORG_EXT_P1 | 1 | | | 1 (0)| 00:00:01 |
| 32 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 42 | | 1 (0)| 00:00:01 |
| 33 | INDEX UNIQUE SCAN | S_ORG_EXT_P1 | 1 | | | 1 (0)| 00:00:01 |
| 34 | TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1 | 59 | | 1 (0)| 00:00:01 |
| 35 | INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | | 1 (0)| 00:00:01 |
| 36 | TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1 | 59 | | 1 (0)| 00:00:01 |
| 37 | INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | | 1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------------------------
21 Copyright ©2011, Oracle and/or its affiliates. All rights reserved.

Find slow SQL (ASH in AWR)
LECT sql id sql type LECT sql_id, sql_type
, round(sample_cnt_sql/sample_cnt_total*100) as sample_pct
, round(sample_cnt_sql /6/60,1) hours
FROM(SELECT DISTINCT sql_id
, aa.name AS sql_type
, COUNT(*) over (PARTITION BY sql_id) AS sample_cnt_sql
, COUNT(*) over () AS sample_cnt_total
FROM dba_hist_active_sess_history ash
JOIN dba_hist_snapshot s USING (dbid, INSTANCE_NUMBER, snap_id)
JOIN audit actions aa on (ash.sql opcode = aa.action) JOIN audit_actions aa on (ash.sql_opcode aa.action)
WHERE begin_interval_time BETWEEN

ORDER BY 3 desc)
WHERE rownum <= 3;
SQL_TYPE SAMPLE_PCT HOURS
------- -------- ---------- -----
axxhm2z SELECT 25 20.4
xxuacaf SELECT 21 16 8 xxuacaf SELECT 21 16.8
m3avn3j SELECT 12 10.1
selected.
ASH rowsource data (plan line id)
LECT sql_id, sql_plan_line_id
, round(sample_cnt_plan_line/sample_cnt_total*100) AS sql_plan_line_pct
, round(sample_cnt_plan_line/6) minutes
OM(
SELECT DISTINCT sql id sql plan line id SELECT DISTINCT sql_id, sql_plan_line_id
, COUNT(*) over (PARTITION BY sql_plan_line_id) AS sample_cnt_plan_line
, COUNT(*) over () AS sample_cnt_total
FROM dba_hist_active_sess_history ash
JOIN dba_hist_snapshot s USING (dbid, INSTANCE_NUMBER, snap_id)
WHERE sql_id = 'dkwucgaxxhm2z‘ and begin_interval_time BETWEEN

SQL_PLAN_LINE_ID SQL_PLAN_LINE_PCT MINUTES
------- ---------------- ----------------- ----------
axxhm2z 34 48 593
axxhm2z 35 27 331
axxhm2z 25 17 213
ASH rowsource (plan line id + event)
ECT sql_id, sql_plan_line_id, event _ _ _ _
round(sample_cnt_plan_line_event/sample_cnt_total*100) as plan_line_event_pct
round(sample_cnt_plan_line_event/6) minutes
OM (SELECT DISTINCT sql_id
, sql_plan_line_id, nvl(event, 'CPU') as event
UNT(*) over (PARTITION BY sql plan line id event)AS sample cnt plan line event UNT(*) over (PARTITION BY sql_plan_line_id,event)AS sample_cnt_plan_line_event
UNT(*) over () AS sample_cnt_total
FROM dba_hist_active_sess_history ash
JOIN dba_hist_snapshot s USING (dbid, INSTANCE_NUMBER, snap_id)
WHERE sql_id = 'dkwucgaxxhm2z' and begin_interval_time BETWEEN …

SQL_PLAN_LINE_ID EVENT PLAN_LINE_EVENT_PCT MINUTES
----- ---------------- ------------------------- ------------------- ----------
xhm2z 34 db file sequential read 48 591
xhm2z 35 db file sequential read 27 328
xhm2z 25 db file sequential read 17 212
selected.
ASH rowsource (10g) (object + event)
ECT sql id object name event ECT sql_id, object_name, event
, round(sample_cnt_object_event/sample_cnt_total*100) as object_event_pct
, round(sample_cnt_object_event/6) minutes
M(SELECT DISTINCT sql_id, object_name, event
count(*) over (partition by object_name,event) as sample_cnt_object_event
count(*) over () as sample_cnt_total
ROM ( SELECT sql_id, nvl(event,'CPU') as event
, case
when wait_class_id in (3871361733,1740759767,427450380,3875070507)
then object name else 'N/A‘ end as object name then object_name else N/A end as object_name
FROM dba_hist_active_sess_history ash

OBJECT_NAME EVENT OBJECT_EVENT_PCT MINUTES
----- -------------------- ------------------------- ---------------- ----------
xhm2z S_ADDR_PER db file sequential read 52 634
xhm2z S_ADDR_PER_P1 db file sequential read 28 347
xhm2z S_ORG_EXT db file sequential read 16 195
AWR SQL plan
-----------------------------------------------------------------------------------------------------------
ration | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------------------------
ECT STATEMENT | | | | | 9553K(100)| |
STED LOOPS OUTER | | 8011K| 46G| | 9553K (1)| 31:50:39 |
ESTED LOOPS OUTER | | 8011K| 45G| | 7148K (1)| 23:49:40 |
NESTED LOOPS OUTER | | 8011K| 45G| | 4743K (1)| 15:48:44 |
NESTED LOOPS OUTER | | 8011K| 45G| | 3941K (1)| 13:08:24 |
NESTED LOOPS OUTER | | 8011K| 44G| | 3140K (1)| 10:28:03 | | | | | | ( )| |
HASH JOIN RIGHT OUTER | | 8011K| 44G| | 2338K (1)| 07:47:43 |
VIEW | index$_join$_009 | 6633 | 285K| | 39 (3)| 00:00:01 |
HASH JOIN | | | | | | |
HASH JOIN | | | | | | |
INDEX FAST FULL SCAN | S_SRC_M10 | 6633 | 285K| | 10 (0)| 00:00:01 |
INDEX FAST FULL SCAN | S_SRC_M12 | 6633 | 285K| | 10 (0)| 00:00:01 |
INDEX FAST FULL SCAN | S_SRC_P1 | 6633 | 285K| | 8 (0)| 00:00:01 |
HASH JOIN RIGHT OUTER | | 8011K| 44G| 228M| 2338K (1)| 07:47:42 |
• IO is 99% of elapsed time
• 75% of time in nested loop
(2,34,35)
• IO is 99% of elapsed time
• 75% of time in nested loop
(2,34,35)
TABLE ACCESS FULL | S_ORG_EXT_LSX | 7488K| 142M| | 38163 (2)| 00:07:38 |
HASH JOIN RIGHT OUTER | | 8011K| 43G| | 51545 (1)| 00:10:19 |
TABLE ACCESS FULL | S_INDUST_LANG | 4023 | 113K| | 199 (0)| 00:00:03 |
HASH JOIN RIGHT OUTER | | 8011K| 43G| | 51289 (1)| 00:10:16 |
TABLE ACCESS FULL | S_ORG_PRTNR | 324 | 43740 | | 8 (0)| 00:00:01 |
NESTED LOOPS OUTER | | 8011K| 42G| | 51224 (1)| 00:10:15 |
VIEW | | 8011K| 42G| | 51169 (1)| 00:10:15 |
NESTED LOOPS | | | | | | |
( , , )
• Query is processing a large
data set
• Nested loop is not an efficient
method for joining large data
( , , )
• Query is processing a large
data set
• Nested loop is not an efficient
method for joining large data
NESTED LOOPS | | 8011K| 8091M| | 51169 (1)| 00:10:15 |
INDEX FULL SCAN | SO_ANA_BU_U2 | 19 | 285 | | 1 (0)| 00:00:01 |
INDEX RANGE SCAN | S_ORG_EXT_M91 | 74493 | | | 35 (3)| 00:00:01 |
TABLE ACCESS BY INDEX ROWID| S_ORG_EXT | 421K| 419M| | 2693 (1)| 00:00:33 |
TABLE ACCESS BY INDEX ROWID | S_OU_PRTNR_TYPE | 1 | 94 | | 1 (0)| 00:00:01 |
INDEX UNIQUE SCAN | S_OU_PRTNR_TYPE_P1 | 1 | | | 1 (0)| 00:00:01 |
TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 42 | | 1 (0)| 00:00:01 |
INDEX UNIQUE SCAN | S_ORG_EXT_P1 | 1 | | | 1 (0)| 00:00:01 |
method for joining large data
sets
• Why does the CBO choose this
inefficient plan ?!
– Bad stats?
method for joining large data
sets
• Why does the CBO choose this
inefficient plan ?!
– Bad stats?
_ _ _
TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 42 | | 1 (0)| 00:00:01 |
INDEX UNIQUE SCAN | S_ORG_EXT_P1 | 1 | | | 1 (0)| 00:00:01 |
TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 42 | | 1 (0)| 00:00:01 |
INDEX UNIQUE SCAN | S_ORG_EXT_P1 | 1 | | | 1 (0)| 00:00:01 |
TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1 | 59 | | 1 (0)| 00:00:01 |
INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | | 1 (0)| 00:00:01 |
ABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1 | 59 | | 1 (0)| 00:00:01 |
INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | | 1 (0)| 00:00:01 |
– Incorrect optimizer settings?
– Or something else?
– Incorrect optimizer settings?
– Or something else?
_ _ _
-----------------------------------------------------------------------------------------------------------
AWR SQL stats
ELECT PLAN HASH VALUE executions ELECT PLAN_HASH_VALUE, executions
, round(elapsed_time /1000000/60/60,1) as elapsed_hours
, rows_processed
, round(cpu_time /elapsed_time * 100) as cpu_time_pct
round(iowait time /elapsed time * 100) as iowait pct , round(iowait_time /elapsed_time 100) as iowait_pct
, LIO, PIO, direct_writes
, round(iowait_time /PIO/1000,1) as mili_sec_PIO
FROM(SELECT PLAN_HASH_VALUE
, sum(EXECUTIONS DELTA) as executions , sum(EXECUTIONS_DELTA) as executions
, sum(ROWS_PROCESSED_DELTA) as rows_processed
, sum(ELAPSED_TIME_DELTA) as elapsed_time
, sum(CPU_TIME_DELTA) as cpu_time, sum(IOWAIT_DELTA) as iowait_time
, sum(DIRECT_WRITES_DELTA) as direct_writes
, sum(BUFFER_GETS_DELTA) as LIO, sum(DISK_READS_DELTA) as PIO
FROM dba_hist_sqlstat
WHERE snap_id between 132042 and 132124
AND sql_id = 'dkwucgaxxhm2z'
GROUP BY sql id, PLAN HASH VALUE); q _ , _ _ );
an CPU IO Milisec
sh Elapsed Rows TIME WAIT Direct /
ue EXECUTIONS Hours Processed PCT PCT LIO PIO Writes Pio
-- ---------- -------- ---------- ----- ---- ---------- ---------- -------- -------
34 1 20.5 5,997,889 1 99 36,152,215 6,427,679 219,418 11.4
AWR SQL Optimizer Env values
ect * from table(dbms xplan display awr('dkwucgaxxhm2z' 1700726234 null ect * from table(dbms_xplan.display_awr( dkwucgaxxhm2z , 1700726234, null,
LAST +OUTLINE'));
------------------------------------------------------------------------------------------------------
Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------------
SELECT STATEMENT | | | | | 9553K(100)| | SELECT STATEMENT | | | | | 9553K(100)| |
NESTED LOOPS OUTER | | 8011K| 46G| | 9553K (1)| 31:50:39 |
Data Data
------
EGIN_OUTLINE_DATA
GNORE_OPTIM_EMBEDDED_HINTS _ _ _
PTIMIZER_FEATURES_ENABLE('11.1.0.7')
B_VERSION('11.1.0.7')
PT_PARAM('_b_tree_bitmap_plans' 'false')
PT_PARAM('_optim_peek_user_binds' 'false')
PT PARAM('optimizer index cost adj' 10) PT_PARAM( optimizer_index_cost_adj 10)
LL_ROWS
UTLINE_LEAF(@"SEL$335DD26A")
ERGE(@"SEL$3")
AWR SQL plan
-------------------------------------------------------------------------------------------------------------
peration | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------------------
ELECT STATEMENT | | | | | 9553K(100)| |
NESTED LOOPS OUTER | | 8011K| 46G| | 9553K (1)| 31:50:39 |
NESTED LOOPS OUTER | | 8011K| 45G| | 7148K (1)| 23:49:40 |
NESTED LOOPS OUTER | | 8011K| 45G| | 4743K (1)| 15:48:44 |
NESTED LOOPS OUTER | | 8011K| 45G| | 3941K (1)| 13:08:24 |
NESTED LOOPS OUTER | | 8011K| 44G| | 3140K (1)| 10:28:03 | | | | | | ( )| |
HASH JOIN RIGHT OUTER | | 8011K| 44G| | 2338K (1)| 07:47:43 |
VIEW | index$_join$_009 | 6633 | 285K| | 39 (3)| 00:00:01 |
HASH JOIN | | | | | | |
HASH JOIN | | | | | | |
INDEX FAST FULL SCAN | S_SRC_M10 | 6633 | 285K| | 10 (0)| 00:00:01 |
INDEX FAST FULL SCAN | S_SRC_M12 | 6633 | 285K| | 10 (0)| 00:00:01 |
INDEX FAST FULL SCAN | S_SRC_P1 | 6633 | 285K| | 8 (0)| 00:00:01 |
HASH JOIN RIGHT OUTER | | 8011K| 44G| 228M| 2338K (1)| 07:47:42 |
TABLE ACCESS FULL | S_ORG_EXT_LSX | 7488K| 142M| | 38163 (2)| 00:07:38 |
HASH JOIN RIGHT OUTER | | 8011K| 43G| | 51545 (1)| 00:10:19 |
TABLE ACCESS FULL | S_INDUST_LANG | 4023 | 113K| | 199 (0)| 00:00:03 |
HASH JOIN RIGHT OUTER | | 8011K| 43G| | 51289 (1)| 00:10:16 |
TABLE ACCESS FULL | S_ORG_PRTNR | 324 | 43740 | | 8 (0)| 00:00:01 |
NESTED LOOPS OUTER | | 8011K| 42G| | 51224 (1)| 00:10:15 |
VIEW | | 8011K| 42G| | 51169 (1)| 00:10:15 |
NESTED LOOPS | | | | | | |
Direct
Writes
Direct
Writes
NESTED LOOPS | | 8011K| 8091M| | 51169 (1)| 00:10:15 |
INDEX FULL SCAN | SO_ANA_BU_U2 | 19 | 285 | | 1 (0)| 00:00:01 |
INDEX RANGE SCAN | S_ORG_EXT_M91 | 74493 | | | 35 (3)| 00:00:01 |
TABLE ACCESS BY INDEX ROWID| S_ORG_EXT | 421K| 419M| | 2693 (1)| 00:00:33 |
TABLE ACCESS BY INDEX ROWID | S_OU_PRTNR_TYPE | 1 | 94 | | 1 (0)| 00:00:01 |
INDEX UNIQUE SCAN | S_OU_PRTNR_TYPE_P1 | 1 | | | 1 (0)| 00:00:01 |
TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 42 | | 1 (0)| 00:00:01 |
INDEX UNIQUE SCAN | S_ORG_EXT_P1 | 1 | | | 1 (0)| 00:00:01 |
--------
219,418
workarea_size_policy=manual
hash area size=2147483647
--------
219,418
workarea_size_policy=manual
hash area size=2147483647
_ _ _
TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 42 | | 1 (0)| 00:00:01 |
INDEX UNIQUE SCAN | S_ORG_EXT_P1 | 1 | | | 1 (0)| 00:00:01 |
TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 42 | | 1 (0)| 00:00:01 |
INDEX UNIQUE SCAN | S_ORG_EXT_P1 | 1 | | | 1 (0)| 00:00:01 |
TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1 | 59 | | 1 (0)| 00:00:01 |
INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | | 1 (0)| 00:00:01 |
TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1 | 59 | | 1 (0)| 00:00:01 |
INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | | 1 (0)| 00:00:01 |
hash_area_size=2147483647 hash_area_size=2147483647
_ _ _
-------------------------------------------------------------------------------------------------------------
New SQL Plan
rom table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
------------------------------------------------------------------------------------------------------------------------------------------------------------
ion | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| A-Rows | A-Time | Buffers | Reads | OMem | 1Mem | Used-Mem |
------------------------------------------------------------------------------------------------------------------------------------------------------------
STATEMENT | | 1 | | | 674K(100)| 0 |00:11:40.62 | 16M| 3031K| | | |
JOIN RIGHT OUTER | | 1 | 17M| 98G| 674K (2)| 5352K|01:20:42.29 | 16M| 3031K| 1143K| 1143K| 74M (0)|
| index$_join$_010 | 1 | 6633 | 285K| 383 (1)| 6707 |00:00:01.93 | 749 | 725 | | | |
H JOIN | | 1 | | | | 6707 |00:00:01.93 | 749 | 725 | 1143K| 1143K| 73M (0)|
SH JOIN | | 1 | | | | 6707 |00:00:01.07 | 680 | 659 | 1117K| 1117K| 73M (0)|
NDEX FAST FULL SCAN | S SRC M10 | 1 | 6633 | 285K| 103 (0)| 6707 |00:00:00 08 | 338 | 328 | | | | NDEX FAST FULL SCAN | S_SRC_M10 | 1 | 6633 | 285K| 103 (0)| 6707 |00:00:00.08 | 338 | 328 | | | |
NDEX FAST FULL SCAN | S_SRC_M12 | 1 | 6633 | 285K| 100 (0)| 6707 |00:00:00.17 | 342 | 331 | | | |
DEX FAST FULL SCAN | S_SRC_P1 | 1 | 6633 | 285K| 76 (0)| 6707 |00:00:00.04 | 69 | 66 | | | |
JOIN RIGHT OUTER | | 1 | 7460K| 41G| 674K (2)| 5352K|01:20:08.10 | 16M| 3030K| 1208M| 33M| 1455M (0)|
LE ACCESS FULL | S_ADDR_PER | 1 | 13M| 744M| 107K (2)| 14M|00:01:53.38 | 392K| 392K| | | |
H JOIN RIGHT OUTER | | 1 | 7460K| 41G| 566K (2)| 5352K|01:17:16.78 | 16M| 2638K| 1208M| 33M| 1455M (0)|
BLE ACCESS FULL | S_ADDR_PER | 1 | 13M| 744M| 107K (2)| 14M|00:02:21.69 | 392K| 392K| | | |
SH JOIN RIGHT OUTER | | 1 | 7460K| 41G| 458K (2)| 5352K|01:14:39.07 | 15M| 2246K| 285M| 10M| 459M (0)|
ABLE ACCESS FULL | S_ORG_EXT_LSX | 1 | 7488K| 142M| 38163 (2)| 6777K|00:01:55.31 | 173K| 138K| | | |
ASH JOIN RIGHT OUTER | | 1 | 7460K| 40G| 420K (2)| 5352K|01:12:09.86 | 15M| 2107K| 445M| 18M| 606M (0)| | | | | | ( )| | : : | | | | | ( )|
INDEX FAST FULL SCAN | S_ORG_EXT_W3 | 1 | 7068K| 276M| 26545 (1)| 6887K|00:04:56.19 | 154K| 102K| | | |
HASH JOIN RIGHT OUTER | | 1 | 7460K| 40G| 393K (2)| 5352K|01:07:28.03 | 15M| 2005K| 445M| 18M| 606M (0)|
INDEX FAST FULL SCAN | S_ORG_EXT_W3 | 1 | 7068K| 276M| 26545 (1)| 6887K|00:00:48.23 | 102K| 19057 | | | |
HASH JOIN RIGHT OUTER | | 1 | 7460K| 40G| 367K (2)| 5352K|01:05:45.34 | 15M| 1986K| 445M| 18M| 606M (0)|
INDEX FAST FULL SCAN | S_ORG_EXT_W3 | 1 | 7068K| 276M| 26545 (1)| 6887K|00:00:00.01 | 102K| 0 | | | |
HASH JOIN RIGHT OUTER | | 1 | 7460K| 40G| 340K (2)| 5352K|01:05:35.55 | 15M| 1986K| 915K| 915K| 74M (0)|
TABLE ACCESS FULL | S_INDUST_LANG | 1 | 4023 | 113K| 199 (0)| 4023 |00:00:00.04 | 713 | 709 | | | |
HASH JOIN RIGHT OUTER | | 1 | 7460K| 39G| 340K (2)| 5352K|01:05:23.59 | 15M| 1985K| 899K| 899K| 74M (0)|
TABLE ACCESS FULL | S_ORG_PRTNR | 1 | 324 | 43740 | 8 (0)| 319 |00:00:00.02 | 23 | 21 | | | | _ _
HASH JOIN RIGHT OUTER | | 1 | 7460K| 38G| 340K (2)| 5352K|01:05:23.46 | 15M| 1985K| 1593K| 1593K| 64M (0)|
VIEW | index$_join$_014 | 1 | 1 | 94 | 1 (100)| 0 |00:00:00.06 | 3 | 2 | | | |
HASH JOIN | | 1 | | | | 0 |00:00:00.06 | 3 | 2 | 1269K| 1269K| 64M (0)|
INDEX FAST FULL SCAN| S_OU_PRTNR_TYPE_P1 | 1 | 1 | 94 | 0 (0)| 0 |00:00:00.02 | 3 | 2 | | | |
INDEX FAST FULL SCAN| S_OU_PRTNR_TYPE_U1 | 0 | 1 | 94 | 0 (0)| 0 |00:00:00.01 | 0 | 0 | | | |
VIEW | | 1 | 7460K| 38G| 340K (2)| 5352K|01:05:12.63 | 15M| 1985K| | | |
HASH JOIN | | 1 | 7460K| 7527M| 340K (2)| 5352K|01:05:12.59 | 15M| 1985K| 1078K| 1078K| 72M (0)|
INDEX FULL SCAN | SO_ANA_BU_U2 | 1 | 19 | 285 | 1 (0)| 19 |00:00:00.02 | 1 | 1 | | | |
TABLE ACCESS FULL | S_ORG_EXT | 1 | 7068K| 7030M| 339K (2)| 6887K|01:05:18.93 | 15M| 1985K| | | |
------------------------------------------------------------------------------------------------------------------------------------------------------------
Evaluating the changes
CPU IO Milisec
sh Elapsed Rows TIME WAIT Direct /
ue EXECUTIONS Hours Processed PCT PCT LIO PIO Writes PIO
-- ---------- ---------- ---------- ---- ---- ----------- ---------- -------- ----------
34 1 20.5 5,997,889 1 99 36,152,215 6,427,679 219,418 11.4
CPU IO Milisec
sh Elapsed Rows TIME WAIT Direct /
ue EXECUTIONS Hours Processed PCT PCT LIO PIO Writes PIO
-- ---------- ---------- ---------- ---- ---- ----------- ---------- -------- ----------
41 1 1.3 5,352,381 5 96 13,134,981 2,651,076 0 2
educed elapsed  time by 94%, Logical IO by 63% and Physical IO by 59% 
ut increased IOPS by 6x => ensure that disk subsystem can handle it !!!
Use Case 2 – Find sql & stats
SQL for the time period
D SQL_TYPE SAMPLE_PCT HOURS
-------- ---------- ---------- ----------
0c9tdj80 INSERT 11 3.9
gt7ytnm9 SELECT 9 3.2
wkk6x5b5 INSERT 7 2.6
for SQL dvaxm0c9tdj80
Plan CPU IO milisec
Hash Elapsed Rows time WAIT Direct /
Value executions Minutes processed PCT PCT LIO PIO Writes PIO
--- ---------- ---------- -------- ---------- ---- ---- ----------- ---------- -------- --------
-29 4061473922 1 118 9,289 1 99 449,940 406,585 0 17
-30 4061473922 1 236 6,754 0 100 408,245 406,481 0 35 , , ,
-01 4061473922 1 89 352 1 99 406,564 406,349 0 13
-02 4061473922 1 145 7,383 1 99 410,586 406,358 0 21
-03 4061473922 1 220 13,944 1 100 413,684 406,027 0 32
Use Case 2 – SQL details
LLan
lect * from table(dbms_xplan.display_awr('dvaxm0c9tdj80', 4061473922, null,
LAST’));
-------------------------------------------------------------------------
Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------
INSERT STATEMENT | | | | 24155 (100)| |
INDEX FULL SCAN | S PARTY W1 | 911K| 17M| 24155 (1)| 00 04 50 | INDEX FULL SCAN | S_PARTY_W1 | 911K| 17M| 24155 (1)| 00:04:50 |
-------------------------------------------------------------------------
Text Text
T /*+APPEND*/ INTO S_ETL_I_IMG_70
(ROW_ID, MODIFICATION_NUM, OPERATION, LAST_UPD)
T ROW_ID, 1, 'I', LAST_UPD
S_PARTY
S_PARTY.LAST_UPD > :1;
Use Case 2 – SQL rowsource
SQL_PLAN_LINE_ID EVENT PLAN_LINE_EVENT_PCT MINUTES
------- ---------------- ------------------------- ------------------- ----------
c9tdj80 2 db file sequential read 100 235
c9tdj80 2 CPU 0 1
or SQL dvaxm0c9tdj80
Plan CPU IO milisec
Hash Elapsed Rows time WAIT Direct /
Value executions Minutes processed PCT PCT LIO PIO Writes PIO
--- ---------- ---------- -------- ---------- ---- ---- ----------- ---------- -------- --------
-29 4061473922 1 118 9,289 1 99 449,940 406,585 0 17
-30 4061473922 1 236 6,754 0 100 408,245 406,481 0 35
-01 4061473922 1 89 352 1 99 406,564 406,349 0 13
-02 4061473922 1 145 7,383 1 99 410,586 406,358 0 21
-03 4061473922 1 220 13,944 1 100 413,684 406,027 0 32
Use Case 2 – Index Structure
@i S PARTY @i S_PARTY
Unq? Part? Index name STATUS Column name DATA_TYPE
- ---- ------ ----------- -------- -------------- ---------
L NO NO S PARTY F1 VALID PAR PARTY ID VARCHAR2 L NO NO S_PARTY_F1 VALID PAR_PARTY_ID VARCHAR2
S_PARTY_M1 VALID ROOT_PARTY_FLG CHAR
p …
NO NO S_PARTY_W1 VALID LAST_UPD DATE
VALID ROW ID VARCHAR2
t
 IO is 99% of elapsed time
U i f t i d b t
VALID ROW_ID VARCHAR2
ut based on modified version of Tim Gorman’s script at
w.evdbt.com/tool.htm
ext
T /*+APPEND*/ INTO S_ETL_I_IMG_70
(ROW_ID, MODIFICATION_NUM, OPERATION, LAST_UPD)
T ROW ID, 1, 'I', LAST UPD
 Using perfect index, but wrong 
access method
 Why does the CBO choose this 
inefficient  plan ?!
B d t t ?
_ _
S_PARTY
S_PARTY.LAST_UPD > :1;
FULL SCAN | S_PARTY_W1
 Bad stats?
 Incorrect optimizer settings?
 Or something else?
Use Case 2 – Bad stats?
lect * from table(dbms xplan display awr('dvaxm0c9tdj80' 4061473922 null lect * from table(dbms_xplan.display_awr('dvaxm0c9tdj80', 4061473922, null,
LAST’));
-------------------------------------------------------------------------
Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------
INSERT STATEMENT | | | | 24155 (100)| |
INDEX FULL SCAN | S_PARTY_W1 | 911K| 17M| 24155 (1)| 00:04:50 |
-------------------------------------------------------------------------
Use Case 2 – Replicate take 1
plain plan for
NSERT /*+APPEND*/ INTO S ETL I IMG 70 NSERT /*+APPEND*/ INTO S_ETL_I_IMG_70
(ROW_ID, MODIFICATION_NUM, OPERATION, LAST_UPD)
ELECT ROW_ID, 1, 'I', LAST_UPD
ROM S_PARTY
HERE S_PARTY.LAST_UPD > :x;
ned.
lect * from table(dbms_xplan.display(null, null, 'ALLSTATS LAST'));
p …
------------------------------------------------------- -------------------------------------------------------
| Operation | Name | E-Rows |
-------------------------------------------------------
| INSERT STATEMENT | | 913K|
| LOAD TABLE CONVENTIONAL | S_ETL_I_IMG_70 | |
| INDEX RANGE SCAN | S_PARTY_W1 | 913K|
-------------------------------------------------------
cate Information (identified by operation id):
----------------------------------------------
- access("S PARTY"."LAST UPD">:X) access( S_PARTY . LAST_UPD >:X)
Statistics History
WRI$_OPTSTAT_TAB_HISTORY
WRI$_OPTSTAT_IND_HISTORY
Etc.
Use Case 2 – bind data type
lect distinct name was captured last captured lect distinct name, was_captured, last_captured
sys.anydata.gettypename(value_anydata) as data_type
sys.anydata.accesstimestamp(value_anydata) as data_value
rom DBA_HIST_SQLBIND where sql_id = 'dvaxm0c9tdj80’ order by last_captured;
was
captured LAST_CAPTURED DATA_TYPE DATA_VALUE
-------- ------------------------- -------------------- --------------------
YES 2011-06-29 17:51:44 SYS.TIMESTAMP 2011-06-28 08:12:58
YES 2011-06-30 18:16:03 SYS TIMESTAMP 2011-06-29 17:01:20 YES 2011 06 30 18:16:03 SYS.TIMESTAMP 2011 06 29 17:01:20
YES 2011-07-01 03:21:51 SYS.TIMESTAMP 2011-06-30 17:01:11
YES 2011-07-02 17:59:52 SYS.TIMESTAMP 2011-07-01 03:03:19
YES 2011-07-03 17:59:08 SYS.TIMESTAMP 2011-07-02 17:01:38
Unq? Part? Index name STATUS Column name DATA_TYPE
- ---- ------ ----------- -------- -------------- ---------
L NO NO S PARTY F1 VALID PAR PARTY ID VARCHAR2 L NO NO S_PARTY_F1 VALID PAR_PARTY_ID VARCHAR2
S_PARTY_M1 VALID ROOT_PARTY_FLG CHAR
p …
NO NO S_PARTY_W1 VALID LAST_UPD DATE
VALID ROW_ID VARCHAR2
Use Case 2 – Replicate (2
nd
try)
eclare eclare
x timestamp;
begin
INSERT /*+APPEND*/ INTO S_ETL_I_IMG_70
(ROW ID MODIFICATION NUM OPERATION LAST UPD) (ROW_ID, MODIFICATION_NUM, OPERATION, LAST_UPD)
SELECT ROW_ID, 1, 'I', LAST_UPD
FROM S_PARTY
WHERE S_PARTY.LAST_UPD > :x;
end; end;
/
-------------------------------------------------------
d | Operation | Name | E-Rows | d | Operation | Name | E Rows |
-------------------------------------------------------
0 | INSERT STATEMENT | | |
1 | LOAD TABLE CONVENTIONAL | | |
2 | INDEX FULL SCAN | S PARTY W1 | 913K| 2 | INDEX FULL SCAN | S_PARTY_W1 | 913K|
-------------------------------------------------------
dicate Information (identified by operation id):
------------------------------------------------
2 - filter(INTERNAL FUNCTION("S PARTY"."LAST UPD")>:B1) 2 filter(INTERNAL_FUNCTION( S_PARTY . LAST_UPD )>:B1)
Use Case 2: Visualizing the
improvement p o e e t
IMG Process Duration
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
ETL Day
Free script collections
•Tanel Poder
• tech.e2sn.com/oracle-scripts-and-tools
•Kerry Osborne -
• kerryosborne.oracle-guy.com/papers/my_favorite_scripts_2010.zip
•TimGorman •Tim Gorman
• evdbt.com/tools.htm
•Adrian Billington
• oracle-developer.net/utilities.php
•J onathan Lewis
• jonathanlewis wordpress com/2009/12/18/simple scripts/ • jonathanlewis.wordpress.com/2009/12/18/simple-scripts/
SQL Tuning Forms Tuning
Resources
SQL Tuning
– Trace files
– SQLT output (MOS Doc: 215187.1)
– TraceAnalyzer (MOS Doc :
Forms Tuning
– Forms Tracing (MOS Doc : 373548.1)
– Generic MOS Doc : 438652.1
Trace Analyzer (MOS Doc :
224270.1)
– AWR Report (MOS Doc : 748642.1)
– AWR SQL Report (awrsqrpt.sql)
SQ
Reports Tracing
– MOS Doc: 111311.1
– 11g Real-Time SQL Monitoring
– SQL Tuning Advisor
PL/SQL Tuning
Database Tuning
– AWR Report (MOS Doc : 748642.1)
– ADDM report (MOS Doc : 250655.1)
PL/SQL Tuning
– Product logs
– PL/SQL Profiler (MOS Doc :
808005.1)
– Active Session History (ASH) Report
– LTOM output (MOS Doc : 352363.1)
OS
Middletier Tuning
– J VM Logs
OS
– OSWatcher (MOS Doc : 301137.1)
– Third Party Tools
To learn even more
•Performance Fundamentals for Oracle Database 10g and 11g
by Graham Wood and J ohn Beresniewicz
(http://www.oracle.com/technetwork/database/focus-areas/manageability/db-perf-tuning-ow08-131582.pdf)
•ASH website by Kyle Hailey
(https://sites.google.com/site/embtdbo/wait-event-documentation/ash---active-session-history)
•Expert Oracle DatabaseArchitecture: Oracle Database 9i 10g •Expert Oracle Database Architecture: Oracle Database 9i, 10g,
and 11g Programming Techniques and Solutions by Thomas
Kyte
•Troubleshooting Oracle Performance by Christian Antognini
•Blogs •Blogs
– Tanel Poder, Kerry Osborne, J onathan Lewis, Cary Millsap, Greg
Rahn, Randolf Geist, etc.
Summary
•Ask questions
•Understand the database internals •Understand the database internals
•Use multiple tools depending on the situation
•Combine the best of both (i e PerfSheet fromTanel Combine the best of both (i.e. PerfSheet from Tanel
Poder)
Q&A Q&A