Documente Academic
Documente Profesional
Documente Cultură
Sahil Thapar
Riyaj Shamsudeen
Disclaimer
These slides and materials represent the work and opinions of the author and do
not constitute official positions of my current or past employer or any other
organization. This material has been peer reviewed, but author assume no
responsibility whatsoever for the test cases.
If you corrupt your databases by running my scripts, you are solely responsible
for that.
Options
EXPLAIN PLAN
(Version 7 or older)
AUTOTRACE (
Version 8i +)
SQL_TRACE (Version 7)
Actual plan; but must enable trace before the run.
DBMS_XPLAN
Actual plan, after the run, always available.
STAT #1844674 id=3 cnt=0 pid=2 pos=1 obj=0 op='SORT UNIQUE (cr=199331 pr=199262 pw=0
time=59603707 us cost=56817 size=126622640 card=2146146)'
STAT #1844674 id=4 cnt=0 pid=3 pos=1 obj=0 op='UNION-ALL (cr=199331 pr=199262 pw=0
time=59603638 us)'
tkprof
(1)
cpu
elapsed
disk
query
current
-------- ---------- ---------- ---------- ---------0.01
0.01
0
0
0
0.00
0.00
0
0
0
18.02
59.60
199262
199331
0
-------- ---------- ---------- ---------- ---------18.03
59.61
199262
199331
0
rows
---------0
0
0
---------0
tkprof
(2)
Max. Wait
---------0.00
0.01
Total Waited
-----------0.00
0.26
Usage
1) PLAN_TABLE
dbms_xplan.diplay (estimated plan)
2) SGA of instance
dbms_xplan.display_cursor (real plan from memory)
3) AWR
dbms_xplan.display_awr (real,history plan from AWR)
Comparison
Sl
Tkprof
Dbms_xplan
No predicate
*
*
*
*
*
from
from
from
from
from
table( dbms_xplan.display_cursor());
table ( dbms_xplan.display_cursor (null,null, 'ADVANCED'));
table ( dbms_xplan.display_cursor ('811a0zb26fw0x',0, 'BASIC'));
table ( dbms_xplan.display_cursor ('811a0zb26fw0x',0, ALL -projection'));
table ( dbms_xplan.display_cursor ('811a0zb26fw0x',0, ALL +peeked_binds'));
Format arguments:
'
ADVANCED'
'
PREDICATE'
'
PREDICATE
+OUTLINE'
bytes
cost
note
alias
X
X
X
X
dbms_xplan.display
SQL_ID 9sup9gfhhg32t, child number 0
------------------------------------SELECT RECID, TABLENAME, PROJECT_NUMBER, PROJECT_NAME,
L
EDIT_CLASS_CODE, ALC, FRC FROM CCW_PA_IF_TASKS WHERE PROCESSED_FLAG='U'
) ORDER BY TABLENAME, CREATION_DATE
Optimizer estimates
10
Display_cursor
select * from table(dbms_xplan.display_cursor('9yx90c0nwv9tk',
0,'allstats'));
SQL_ID 9yx90c0nwv9tk, child number 0
------------------------------------SELECT /* gather_plan_statistics */ RECID, TABLENAME,
...
Plan hash value: 3298327531
--------------------------------------------------------------------------------------------------------------| Id | Operation
| Name
| Starts | E-Rows | A-Rows |
A-Time
| Buffers | Reads |
--------------------------------------------------------------------------------------------------------------|
0 | SELECT STATEMENT
|
|
1 |
|
0 |00:00:32.50 |
199K|
199K|
|
1 | SORT ORDER BY
|
|
1 |
2146K|
0 |00:00:32.50 |
199K|
199K|
|
2 |
VIEW
|
|
1 |
2146K|
0 |00:00:32.50 |
199K|
199K|
|
3 |
SORT UNIQUE
|
|
1 |
2146K|
0 |00:00:32.50 |
199K|
199K|
|
4 |
UNION-ALL
|
|
1 |
|
0 |00:00:32.50 |
199K|
199K|
|* 5 |
TABLE ACCESS FULL| ORD_AP_IF_PROJECTS |
1 |
1 |
0 |00:00:07.90 |
46025 | 45963 |
|* 6 |
TABLE ACCESS FULL| ORD_AP_IF_TASKS
|
1 |
2146K|
0 |00:00:24.60 |
153K|
153K|
---------------------------------------------------------------------------------------------------------------
11
12
Privileges
select
select
select
select
on
on
on
on
v_$session to scott;
v_$SQL_PLAN_STATISTICS_ALL to scott;
v_$sql to scott;
v_$sql_plan to scott;
OR
SELECT_CATALOG role or select any dictionary system privilege
For dbms_xplan.display_awr
OR
SELECT_CATALOG role
13
Internals of dbms_xplan
More internals
SELECT /*+ opt_param('parallel_execution_enabled', 'false') */
/* EXEC_FROM_DBMS_XPLAN */ id, position, depth ,
operation, options, object_name, cardinality, bytes, temp_space, cost,
io_cost, cpu_cost, time,
.
vp.optimal_executions opt_cnt,
vp.onepass_executions one_cnt,
vp.multipasses_executions multi_cnt,
vp.max_tempseg_size max_tmp,
vp.last_tempseg_size last_tmp
from V$SQL_PLAN_STATISTICS_ALL vp, v$sql
where vp.SQL_ID = '8gzkcsvw362s3' and vp.child_number=2 and vp.SQL_ID = v
$sql.SQL_ID and v$sql.child_number=2)
order by id
15
How do I tune?
16
1.
2.
1.
Dos
Current execution plan and runtime statistics are the first
step.
Execute a test case first to reproduce.
Dont
Try to use same bind type as application uses.
- Literal vs bind variables
- number vs varchar2 data type etc
2.
Try to use format same as the application for your test case.
- CTAS vs INSERT
17
dbms_xplan.display_cursor
PLAN_TABLE_OUTPUT
SQL_ID cttafpfjwqjdm, child number 0
------------------------------------select oeh.header_id,oel.line_id from oe_order_headers_all oeh,oe_order_lines_all oel where
oeh.header_id=:order_id and oeh.header_id=oel.header_id
Plan hash value: 4180984038
-------------------------------------------------------------------------------------------------------------------------| Id | Operation
| Name
| Rows | Bytes | Cost (%CPU)| Time
| Pstart| Pstop
|
-------------------------------------------------------------------------------------------------------------------------|
0 | SELECT STATEMENT
|
|
|
|
11 (100)|
|
|
|
|
1 | NESTED LOOPS
|
|
6 |
114 |
11
(0)| 00:00:01 |
|
|
|
2 |
PARTITION HASH SINGLE
|
|
1 |
6 |
2
(0)| 00:00:01 |
KEY |
KEY
|
|* 3 |
INDEX UNIQUE SCAN
| OE_ORDER_HEADERS_U1 |
1 |
6 |
2
(0)| 00:00:01 |
KEY |
KEY
|
|
4 |
TABLE ACCESS BY GLOBAL INDEX ROWID| OE_ORDER_LINES_ALL |
6 |
78 |
9
(0)| 00:00:01 | ROWID | ROWID
|
|* 5 |
INDEX RANGE SCAN
| OE_ORDER_LINES_N1
|
6 |
|
3
(0)| 00:00:01 |
|
|
--------------------------------------------------------------------------------------------------------------------------
18
dbms_xplan.display_cursor
..2
...
Predicate Information (identified by operation id):
--------------------------------------------------3 - access("OEH"."HEADER_ID"=:ORDER_ID)
5 - access("OEL"."HEADER_ID"=:ORDER_ID)
Note
----- Warning These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
* Cardinality feedback used
* Dynamic sampling used
19
ROWS
CPU
Physical IO
Logical IO
Elapsed time
dbms_xplan: script
--my_sql.sql script_name
set linesize 300;
set pagesize 1000;
--Declare variable and assign values
var order_id number;
execute order_id:=53759119
22
Execution statistics
select * from table
(dbms_xplan.DISPLAY_CURSOR(null, null, 'ALLSTATS LAST'))
/
SQL_ID 7gftgf917tg2x, child number 0
------------------------------------select /*+ gather_plan_statistics */ oeh.header_id,oel.line_id from
oe_order_headers_all oeh,oe_order_lines_all oel where
oeh.header_id=:order_id and oeh.header_id=oel.header_id
Plan hash value: 4180984038
-----------------------------------------------------------------------------------------------------------------------------| Id | Operation
| Name
| Starts | E-Rows | A-Rows |
A-Time
| Buffers | Reads |
-----------------------------------------------------------------------------------------------------------------------------|
0 | SELECT STATEMENT
|
|
1 |
|
4 |00:00:00.03 |
12 |
11 |
|
1 | NESTED LOOPS
|
|
1 |
6 |
4 |00:00:00.03 |
12 |
11 |
|
2 |
PARTITION HASH SINGLE
|
|
1 |
1 |
1 |00:00:00.01 |
3 |
3 |
|* 3 |
INDEX UNIQUE SCAN
| OE_ORDER_HEADERS_U1 |
1 |
1 |
1 |00:00:00.01 |
3 |
3 |
|
4 |
TABLE ACCESS BY GLOBAL INDEX ROWID| OE_ORDER_LINES_ALL |
1 |
6 |
4 |00:00:00.02 |
9 |
8 |
|* 5 |
INDEX RANGE SCAN
| OE_ORDER_LINES_N1
|
1 |
6 |
4 |00:00:00.01 |
5 |
4 |
------------------------------------------------------------------------------------------------------------------------------
25 rows selected.
23
Alias
select * from table
(dbms_xplan.DISPLAY_CURSOR(null, null, 'ALLSTATS LAST +alias -predicate'));
SELECT /*+ gather_plan_statistics */ oel.line_id
FROM
oe_order_lines_all oel WHERE
oel.open_flag = 'Y'
and
exists
(select 1 from oe_order_headers_all oeh
where
oeh.header_id = oel.header_id
and oeh.open_flag='Y'
and oeh.last_update_date > sysdate -5)
Plan hash value: 746840967
-------------------------------------------------------------------------------------------------------------------------------------------------------| Id | Operation
| Name
| Starts | E-Rows | A-Rows |
A-Time
| Buffers | OMem | 1Mem | Used-Mem |
-------------------------------------------------------------------------------------------------------------------------------------------------------|
0 | SELECT STATEMENT
|
|
1 |
|
3 |00:00:00.01 |
16 |
|
|
|
|
1 | NESTED LOOPS
|
|
1 |
|
3 |00:00:00.01 |
16 |
|
|
|
|
2 |
NESTED LOOPS
|
|
1 |
1 |
3 |00:00:00.01 |
10 |
|
|
|
|
3 |
SORT UNIQUE
|
|
1 |
1 |
1 |00:00:00.01 |
5 | 2048 | 2048 | 2048 (0)|
|
4 |
TABLE ACCESS BY GLOBAL INDEX ROWID| OE_ORDER_HEADERS_ALL
|
1 |
1 |
1 |00:00:00.01 |
5 |
|
|
|
|
5 |
INDEX RANGE SCAN
| CCW_OE_ORD_HEADERS_ALL_D1 |
1 |
7 |
1 |00:00:00.01 |
4 |
|
|
|
|
6 |
INDEX RANGE SCAN
| OE_ORDER_LINES_N1
|
1 |
6 |
3 |00:00:00.01 |
5 |
|
|
|
|
7 |
TABLE ACCESS BY GLOBAL INDEX ROWID | OE_ORDER_LINES_ALL
|
3 |
1 |
3 |00:00:00.01 |
6 |
|
|
|
--------------------------------------------------------------------------------------------------------------------------------------------------------
Default QB Name
Prefix
CRI$
DEL$
DELETE statement
INS$
Insert Statement
MISC$
MRG$
Merge Statement
SEL$
SELECT statement
SET$
Set operators
UPD$
Update statement
26
Hints or Outlines
set linesize 300
set pagesize 300
alter session set statistics_level='ALL';
SELECT
/* outline query */
RECID, ALC, FRC
...
FROM ORD_AP_IF_TASK WHERE PROCESSED_FLAG = 'U')
ORDER BY TABLENAME, CREATION_DATE;
27
Outline
--------------------------------------------------------------------------------------------------------------------| Id | Operation
| Name
| Starts | E-Rows | A-Rows |
A-Time
| Buffers |
-------------------------------------------------------------------------------------------------------------------
|
0 | SELECT STATEMENT
|
|
1 |
|
0 |00:00:27.40 |
153K| ..
|
1 | SORT ORDER BY
|
|
1 |
2146K|
0 |00:00:27.40 |
153K|
|
2 |
VIEW
|
|
1 |
2146K|
0 |00:00:27.40 |
153K|
|
3 |
SORT UNIQUE
|
|
1 |
2146K|
0 |00:00:27.40 |
153K|
|
4 |
UNION-ALL
|
|
1 |
|
0 |00:00:27.40 |
153K|
|
5 |
TABLE ACCESS BY INDEX ROWID| ORD_AP_IF_PROJECTS
|
1 |
1 |
0 |00:00:00.01 |
3 |
|
6 |
INDEX RANGE SCAN
| ORD_AP_IF_PROJECTS_N1 |
1 |
1 |
0 |00:00:00.01 |
3 |
|
7 |
TABLE ACCESS FULL
| ORD_AP_IF_TASKS
|
1 |
2146K|
0 |00:00:27.40 |
153K|
-------------------------------------------------------------------------------------------------------------------
Outline Data
------------/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.2')
OPT_PARAM('_b_tree_bitmap_plans' 'false')
OPT_PARAM('_fast_full_scan_enabled' 'false')
ALL_ROWS
OUTLINE_LEAF(@"SEL$2")
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$3" "ORD_AP_IF_TASKS"@"SEL$3")
INDEX_RS_ASC(@"SEL$2" "ORD_AP_IF_PROJECTS"@"SEL$2
("ORD_AP_IF_PROJECTS"."PROCESSED_FLAG"))
END_OUTLINE_DATA
*/
28
Tuning SQL
Outline Data
------------/*+
...
FULL(@"SEL$3" "ORD_AP_IF_TASKS"@"SEL$3")
INDEX_RS_ASC(@"SEL$2" "ORD_AP_IF_PROJECTS
"@"SEL$2" ("ORD_AP_IF_PROJECTS"."PROCESSED_FLAG"))
END_OUTLINE_DATA
*/
ORD_AP_IF_TASKS.PROCESSED_FLAG
29
FULL(@"SEL$3" "ORD_AP_IF_TASKS"@"SEL$3")
30
Tuned Plan
---------------------------------------------------------------------------------------------------------
| Id | Operation
| Name
| Starts | E-Rows | A-Rows |
A-Time
|
--------------------------------------------------------------------------------------------------------|
0 | SELECT STATEMENT
|
|
1 |
|
0 |00:00:00.01 |
|
1 | SORT ORDER BY
|
|
1 |
2146K|
0 |00:00:00.01 |
|
2 |
VIEW
|
|
1 |
2146K|
0 |00:00:00.01 |
|
3 |
SORT UNIQUE
|
|
1 |
2146K|
0 |00:00:00.01 |
|
4 |
UNION-ALL
|
|
1 |
|
0 |00:00:00.01 |
|
5 |
TABLE ACCESS BY INDEX ROWID| ORD_AP_IF_PROJECTS
|
1 |
1 |
0 |00:00:00.01 |
|* 6 |
INDEX RANGE SCAN
| ORD_AP_IF_PROJECTS_N1 |
1 |
1 |
0 |00:00:00.01 |
|
7 |
TABLE ACCESS BY INDEX ROWID| ORD_AP_IF_TASKS
|
1 |
2146K|
0 |00:00:00.01 |
|* 8 |
INDEX RANGE SCAN
| ORD_AP_IF_TASKS_N1
|
1 |
2173K|
0 |00:00:00.01 |
---------------------------------------------------------------------------------------------------------
Outline Data
------------/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPT_PARAM('_b_tree_bitmap_plans' 'false')
OPT_PARAM('_fast_full_scan_enabled' 'false')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
NO_ACCESS(@"SEL$1" "from$_subquery$_001"@"SEL$1")
INDEX_RS_ASC(@"SEL$3" ORD_AP_IF_TASKS"@"SEL$3" (ORD_A__IF_TASKS"."PROCESSED_FLAG"))
INDEX_RS_ASC(@"SEL$2" ORD_AP_IF_PROJECTS"@"SEL$2" (ORD_AP_IF_PROJECTS"."PROCESSED_FLAG"))
END_OUTLINE_DATA
*/
Predicate Information (identified by operation id):
--------------------------------------------------6 - access("PROCESSED_FLAG"='U')
8 - access("PROCESSED_FLAG"='U)
31
Identified of each step in the execution plan; if prefixed with * then predicate information available in predicate section
Operation
Row source operation
Name
The database object in the operation
CBO parse time information
Rows
Bytes
Estimated number of rows returned by the row source operation; derived from statistics on names object in the operation
Estimated amount of data returned by the operation
TempSpc
Cost(%CPU) The estimated cost of the row source operation. The percentage CPU cost is given in () for individual row source operation
Time
Estimated amount of time needed to execute that operation in HH:MM:SS
Partitioning
Pstart
Number of first partition to be accessed
Pstop
The number of last partition to be accessed
Parallel Processing
TQ
Table queue used for processing
IN-OUT
The relation between parallel operations
PQ Distrib
The distribution used by producers to send data to consumers
Runtime Statistics
Starts
The number of times operation was executed (check more nested loop joins operation)
A-Rows
Actual number of rows returned
A-Time
Actual amount of time spent executing the operation
I/O Statistics
Buffers
Read
Write
32
dbms_xplan.display_awr
Format
select
*
from
table(dbms_xplan.display_awr(sql_id,plan_hash_value,db_id,format));
-plan_hash_value:
to
select
a
specic
plan
-dbid
:
species
which
database
to
select
from
Example
script:
SELECT * FROM TABLE(
dbms_xplan.display_awr('&&sql_id', '&plan_hash_value',
NULL, 'ALL +peeked_binds')
);
33
dbms_xplan.display_awr
select * from table(dbms_xplan.display_awr('4jtbgawt37mcd',null,
null, 'ALL +peeked_binds'));
SQL_ID 4jtbgawt37mcd
-------------------Plan hash value: 327243540
--------------------------------------------------------------------------------------------------------------| Id | Operation
| Name
| Rows | Bytes | Cost (%CPU)| Time
|
---------------------------------------------------------------------------------------------------------------
34
Cardinality feedback
select /*+ gather_plan_statistics */ max(length(v1)) from
order_headers_all where processed_flag='N'
Plan hash value: 872302569
--------------------------------------------------------------------------| Id | Operation
| Name
| Starts | E-Rows | A-Rows |
--------------------------------------------------------------------------|
0 | SELECT STATEMENT
|
|
1 |
|
1 |
|
1 | SORT AGGREGATE
|
|
1 |
1 |
1 |
|* 2 |
TABLE ACCESS FULL| ORDER_HEADERS_ALL |
1 | 50000 |
10 |
--------------------------------------------------------------------------Predicate Information (identified by operation id):
--------------------------------------------------2 - filter("PROCESSED_FLAG"='N')
Demo @demo_oh1.sql
OraInternals Riyaj Shamsudeen
35
Starts
SELECT
/*+ no_rewrite gather_plan_statistics */
MAX(LENGTH(oh.v1)), MAX(LENGTH(oh.v1))
FROM order_headers_all oh
WHERE EXISTS
( SELECT 1 FROM order_lines_all ol
WHERE oh.order_id
= ol.order_id
AND line_processed_flag = 'Y'
AND rownum
>=1
)
AND oh.processed_flag='N' ;
Demo @demo_oh2.sql
OraInternals Riyaj Shamsudeen
36
ALLSTATS LAST
select * from table (dbms_xplan.display_cursor ('', '','ALLSTATS LAST'))
---------------------------------------------------------------------------------------| Id | Operation
| Name
| Starts | E-Rows | A-Rows |
---------------------------------------------------------------------------------------|
0 | SELECT STATEMENT
|
|
1 |
|
1 |
|
1 | SORT AGGREGATE
|
|
1 |
1 |
1 |
|* 2 |
FILTER
|
|
1 |
|
10 |
|* 3 |
TABLE ACCESS FULL
| ORDER_HEADERS_ALL |
1 | 50000 |
10 |
|
4 |
COUNT
|
|
10 |
|
10 |
|* 5 |
FILTER
|
|
10 |
|
10 |
|* 6 |
TABLE ACCESS BY INDEX ROWID| ORDER_LINES_ALL
|
10 |
1 |
10 |
|* 7 |
INDEX RANGE SCAN
| OL_N1
|
10 |
1 |
10 |
---------------------------------------------------------------------------------------Predicate Information (identified by operation id):
--------------------------------------------------2
3
5
6
7
Demo @demo_oh2.sql
OraInternals Riyaj Shamsudeen
37
Starts
..2
38
Cardinality feedback
..2
-----------------------------------------------------------------------------------------| Id | Operation
| Name
| Starts | E-Rows | A-Rows |
-----------------------------------------------------------------------------------------|
0 | UPDATE STATEMENT
|
|
7822 |
|
0 |
|
1 | UPDATE
| ENI_OLTP_ITEM_STAR
|
7822 |
|
0 |
|* 2 |
FILTER
|
|
7824 |
|
7254K|
|* 3 |
TABLE ACCESS BY ROWID RANGE| ENI_OLTP_ITEM_STAR
|
7823 | 69121 |
7256K|
|
4 |
TABLE ACCESS BY INDEX ROWID | MTL_SYSTEM_ITEMS_B
|
7171K|
1 |
7167K|
|* 5 |
INDEX UNIQUE SCAN
| MTL_SYSTEM_ITEMS_B_U1 |
7176K|
1 |
7172K|
------------------------------------------------------------------------------------------
39
Cardinality feedback
..3
------------------------------------------------------------------------------------------------------| Id | Operation
| Name
| Starts |
A-Time
| Buffers | Reads |
------------------------------------------------------------------------------------------------------|
0 | UPDATE STATEMENT
|
|
7822 |00:47:24.86 |
56M|
1082K|
|
1 | UPDATE
| ENI_OLTP_ITEM_STAR
|
7822 |00:47:24.86 |
56M|
1082K|
|* 2 |
FILTER
|
|
7824 |00:01:27.46 |
23M|
868 |
|* 3 |
TABLE ACCESS BY ROWID RANGE| ENI_OLTP_ITEM_STAR
|
7823 |00:01:23.30 |
23M|
868 |
|
4 |
TABLE ACCESS BY INDEX ROWID | MTL_SYSTEM_ITEMS_B
|
7171K|00:41:09.13 |
25M|
1028K|
|* 5 |
INDEX UNIQUE SCAN
| MTL_SYSTEM_ITEMS_B_U1 |
7176K|00:01:17.74 |
17M|
488 |
------------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):
--------------------------------------------------2 - filter(CHARTOROWID(:B2)<=CHARTOROWID(:B1))
3 - access(ROWID>=CHARTOROWID(:B2) AND ROWID<=CHARTOROWID(:B1))
5 - access("MTI"."INVENTORY_ITEM_ID"=:B1 AND "MTI"."ORGANIZATION_ID"=:B2)
40
SQL - remote
WITH rem1 AS
(SELECT /*+ materialize */ order_id
FROM oli_table@orcl2 ol
WHERE line_processed_flag='Y'
)
SELECT /*+ no_rewrite gather_plan_statistics */
MAX(LENGTH(oh.v1)) FROM order_headers_all oh
WHERE EXISTS
(SELECT 1 FROM rem1 WHERE oh.order_id = rem1.order_id
)
AND oh.processed_flag='N' ;
Demo @demo_oh3.sql
OraInternals Riyaj Shamsudeen
41
Remote queries
--------------------------------------------------------------------------------------------| Id | Operation
| Name
| Starts | E-Rows | A-Rows |
--------------------------------------------------------------------------------------------|
0 | SELECT STATEMENT
|
|
1 |
|
1 |
|
1 | TEMP TABLE TRANSFORMATION |
|
1 |
|
1 |
|
2 |
LOAD AS SELECT
|
|
1 |
|
0 |
|
3 |
REMOTE
| OLI_TABLE
|
1 |
100K|
100K|
|
4 |
SORT AGGREGATE
|
|
1 |
1 |
1 |
|* 5 |
HASH JOIN RIGHT SEMI
|
|
1 | 50000 |
10 |
|
6 |
VIEW
|
|
1 |
100K|
100K|
|
7 |
TABLE ACCESS FULL
| SYS_TEMP_0FD9FC884_E8A367F2 |
1 |
100K|
100K|
|* 8 |
TABLE ACCESS FULL
| ORDER_HEADERS_ALL
|
1 | 50000 |
10 |
--------------------------------------------------------------------------------------------Predicate Information (identified by operation id):
--------------------------------------------------5 - access("OH"."ORDER_ID"="REM1"."ORDER_ID")
8 - filter("OH"."PROCESSED_FLAG"='N')
42
SQL remote
SELECT
/*+ no_rewrite gather_plan_statistics
MAX(LENGTH(oh.v1))
FROM order_headers_all oh,
(SELECT order_id
FROM oli_table@orcl2 ol
WHERE line_processed_flag='Y'
) ol
WHERE oh.order_id
= ol.order_id AND
oh.processed_flag='N' ;
..2
use_nl (oh ol) */
Demo @demo_oh3.sql
OraInternals Riyaj Shamsudeen
43
Demo @demo_oh5.sql
OraInternals Riyaj Shamsudeen
44
Parallel Queries
ALLSTATS LAST
---------------------------------------------------------------------------------------------------| Id | Operation
| Name
| Starts | E-Rows | A-Rows |
A-Time
|
---------------------------------------------------------------------------------------------------|
0 | SELECT STATEMENT
|
|
1 |
|
1 |00:00:08.83 |
|
1 | SORT AGGREGATE
|
|
1 |
1 |
1 |00:00:08.83 |
|* 2 |
HASH JOIN
|
|
1 |
999K|
260K|00:00:08.76 |
|
3 |
VIEW
|
|
1 |
999K|
999K|00:00:02.11 |
|* 4 |
COUNT STOPKEY
|
|
1 |
|
999K|00:00:01.52 |
|
5 |
PX COORDINATOR
|
|
1 |
|
999K|00:00:00.84 |
|
6 |
PX SEND QC (RANDOM)
| :TQ10000
|
0 |
11M|
0 |00:00:00.01 |
|* 7 |
COUNT STOPKEY
|
|
0 |
|
0 |00:00:00.01 |
|
8 |
PX PARTITION HASH ALL|
|
0 |
11M|
0 |00:00:00.01 |
|
9 |
INDEX FULL SCAN
| OE_ORDER_HEADERS_U1 |
0 |
11M|
0 |00:00:00.01 |
| 10 |
VIEW
|
|
1 |
999K|
999K|00:00:02.28 |
|* 11 |
COUNT STOPKEY
|
|
1 |
|
999K|00:00:01.68 |
| 12 |
INDEX FULL SCAN
| OE_ORDER_LINES_N1
|
1 |
57M|
999K|00:00:00.98 |
---------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):
--------------------------------------------------2
4
7
11
access("OH"."HEADER_ID"="OL"."HEADER_ID")
filter(ROWNUM<1000000)
filter(ROWNUM<1000000)
filter(ROWNUM<1000000)
Note
-----
45
Parallel Queries
--------------------------------------------------------------------------------------------------| Id | Operation
| Name
| Starts | E-Rows | A-Rows |
A-Time
|
---------------------------------------------------------------------------------------------------|
0 | SELECT STATEMENT
|
|
1 |
|
1 |00:00:08.83 |
|
1 | SORT AGGREGATE
|
|
1 |
1 |
1 |00:00:08.83 |
|* 2 |
HASH JOIN
|
|
1 |
999K|
260K|00:00:08.76 |
|
3 |
VIEW
|
|
1 |
999K|
999K|00:00:02.11 |
|* 4 |
COUNT STOPKEY
|
|
1 |
|
999K|00:00:01.52 |
|
5 |
PX COORDINATOR
|
|
1 |
|
999K|00:00:00.84 |
|
6 |
PX SEND QC (RANDOM)
| :TQ10000
|
0 |
11M|
0 |00:00:00.01 |
|* 7 |
COUNT STOPKEY
|
|
8 |
|
1072K|00:00:03.83 |
|
8 |
PX PARTITION HASH ALL|
|
8 |
11M|
1072K|00:00:03.17 |
|
9 |
INDEX FULL SCAN
| OE_ORDER_HEADERS_U1 |
8 |
11M|
1072K|00:00:02.56 |
| 10 |
VIEW
|
|
1 |
999K|
999K|00:00:02.28 |
|* 11 |
COUNT STOPKEY
|
|
1 |
|
999K|00:00:01.68 |
| 12 |
INDEX FULL SCAN
| OE_ORDER_LINES_N1
|
1 |
57M|
999K|00:00:00.98 |
---------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):
--------------------------------------------------2
4
7
11
access("OH"."HEADER_ID"="OL"."HEADER_ID")
filter(ROWNUM<1000000)
filter(ROWNUM<1000000)
filter(ROWNUM<1000000)
Note
-----
46
Parallel Queries
---------------------------------------------------------------------------------------------------| Id | Operation
| Name
| Starts | E-Rows | A-Rows |
A-Time
|
---------------------------------------------------------------------------------------------------|
0 | SELECT STATEMENT
|
|
4 |
|
4 |00:00:38.25 |
|
1 | SORT AGGREGATE
|
|
4 |
1 |
4 |00:00:38.25 |
|* 2 |
HASH JOIN
|
|
4 |
999K|
418K|00:00:38.16 |
|
3 |
VIEW
|
|
4 |
999K|
3999K|00:00:07.67 |
|* 4 |
COUNT STOPKEY
|
|
4 |
|
3999K|00:00:05.53 |
|
5 |
PX COORDINATOR
|
|
4 |
|
3999K|00:00:03.12 |
|
6 |
PX SEND QC (RANDOM)
| :TQ10000
|
0 |
11M|
0 |00:00:00.01 |
|* 7 |
COUNT STOPKEY
|
|
64 |
|
4779K|00:00:56.27 |
|
8 |
PX PARTITION HASH ALL|
|
64 |
11M|
4779K|00:00:53.19 |
|
9 |
INDEX FULL SCAN
| OE_ORDER_HEADERS_U1 |
64 |
11M|
4779K|00:00:50.33 |
| 10 |
VIEW
|
|
4 |
999K|
3999K|00:00:14.59 |
|* 11 |
COUNT STOPKEY
|
|
4 |
|
3999K|00:00:12.32 |
| 12 |
PX COORDINATOR
|
|
4 |
|
3999K|00:00:09.35 |
| 13 |
PX SEND QC (RANDOM)
| :TQ20000
|
0 |
57M|
0 |00:00:00.01 |
|* 14 |
COUNT STOPKEY
|
|
64 |
|
4169K|00:05:45.40 |
| 15 |
PX BLOCK ITERATOR
|
|
64 |
57M|
4169K|00:05:42.68 |
|* 16 |
TABLE ACCESS FULL
| OE_ORDER_LINES_ALL |
233 |
57M|
4169K|00:05:26.98 |
---------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):
--------------------------------------------------..
Note
-----
47
Note section
Note
----- dynamic sampling used for this statement (level=2)
Note
----- SQL profile SQL_PROF_4awcsbtwr8ksz" used for this
statement
Note
----- Cardinality feedback used
48
Few limitations
49
SQL monitor
SET LONG 1000000
SET LONGCHUNKSIZE 1000000
SET LINESIZE 1000
SET PAGESIZE 0
SET TRIM ON
SET TRIMSPOOL ON
SET ECHO OFF
SET FEEDBACK OFF
SELECT DBMS_SQLTUNE.report_sql_monitor(
sql_id
=> '&sql_id', type=>'TEXT' , report_level => 'ALL') from dual
/
50
Output
51
Output
..2
52
Me
OakTable member
Email: rshamsud@orainternals.com
Blog : orainternals.wordpress.com
Web: www.orainternals.com
53
Dates
Time
Week1
TBA
Week 2
TBA
54
References
55