Escolar Documentos
Profissional Documentos
Cultura Documentos
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.
2
Options
EXPLAIN PLAN
Estimated, not always reliable
(Version 7 or older)
AUTOTRACE (
Version 8i +) Actual plan, buggy.
SQL_TRACE (Version 7)
Actual plan; but must enable trace before the run.
DBMS_XPLAN
Actual plan, after the run, always available.
3
Raw trace file
Content of a sql trace file:
PARSING IN CURSOR #1844674 len=1000 dep=0 uid=173 oct=3 lid=173 tim=7861072491388
hv=2701626457 ad='498d8f1d0' sqlid='9sup9gfhhg32t'
SELECT RECID, TABLENAME, PROJECT_NUMBER, PROJECT_NAME, CARRYING_OUT_ORGANIZATION,
...FROM ( SELECT STGTBL_RECID
...
WHERE PROCESSED_FLAG='U' ) ORDER BY TABLENAME, CREATION_DATE
PARSE:#1844674:c=10000,e=10162,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,plh=3298327531,tim=78610
72491386
EXEC:#1844674:c=0,e=139,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=3298327531,tim=786107249172
3
EXEC:#1844674:c=0,e=139,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=3298327531,tim=786107249172
3
..
WAIT #1844674: nam='Disk file operations I/O' ela= 2013 FileOperation=2 fileno=811
filetype=2 obj#=706379 tim=786107
FETCH#1844674:c=18020000,e=59603730,p=199262,cr=199331,cu=0,mis=0,r=0,dep=0,og=1,plh=32983
27531,tim=7861
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)'
4
tkprof (1)
5
tkprof (2)
6
Usage
Displays execution plan stored in three different places
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)
7
Comparison
Sl Tkprof Dbms_xplan
1 Trace must be enabled. Basic statistics are available in
memory and AWR
2 CBO notes are not visible Note section is very useful
3 No predicate Predicates printed from memory.
4 Bind values can be retrieved with
ease
5 Plan history can be retrieved
easily.
8
dbms_xplan format arguments
Format
select
*
from
table(dbms_xplan.display_cursor(sql_id,child_number,format));
Examples:
select * from table( dbms_xplan.display_cursor());
select * from table ( dbms_xplan.display_cursor (null,null, 'ADVANCED'));
select * from table ( dbms_xplan.display_cursor ('811a0zb26fw0x',0, 'BASIC'));
select * from table ( dbms_xplan.display_cursor ('811a0zb26fw0x',0, ALL -projection'));
select * from table ( dbms_xplan.display_cursor ('811a0zb26fw0x',0, ALL +peeked_binds'));
Format
arguments:
'
ADVANCED'
'
PREDICATE'
'
PREDICATE
+OUTLINE'
TYPICAL is the default class
Format
arguments
combinaKon:
Class level alias
bytes
cost
note
predicate
parallel
partition
projection outlines
peeked_binds
remote
rows
BASIC
null
X
X
X
X
X
TYPICAL
X
X
X
X
X
X
X
X
SERIAL
X
X
X
X
X
X
ALL
X
X
X
X
X
X
X
X
X
X
X
ADVANCED
X
X
X
X
X
X
X
X
X
X
X
X
9
dbms_xplan.display
SQL_ID 9sup9gfhhg32t, child number 0
-------------------------------------
SELECT RECID, TABLENAME, PROJECT_NUMBER, PROJECT_NAME,
L Optimizer estimates
EDIT_CLASS_CODE, ALC, FRC FROM CCW_PA_IF_TASKS WHERE PROCESSED_FLAG='U'
) ORDER BY TABLENAME, CREATION_DATE
5 - filter("PROCESSED_FLAG"='U')
6 - filter("PROCESSED_FLAG"='U')
Note
-----
- SQL profile not used for this statement
10
Display_cursor
11
Easily quantify the solution given..
----------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
----------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 0 |00:00:00.01 | 6 | | | |
| 1 | SORT ORDER BY | | 1 | 2146K| 0 |00:00:00.01 | 6 | 1024 | 1024 | |
| 2 | VIEW | | 1 | 2146K| 0 |00:00:00.01 | 6 | | | |
| 3 | SORT UNIQUE | | 1 | 2146K| 0 |00:00:00.01 | 6 | 1024 | 1024 | |
| 4 | UNION-ALL | | 1 | | 0 |00:00:00.01 | 6 | | | |
| 5 | TABLE ACCESS BY INDEX ROWID| ORD_PA_IF_PROJECTS | 1 | 1 | 0 |00:00:00.01 | 3 | | | |
|* 6 | INDEX RANGE SCAN | ORD_PA_IF_PROJECTS_N1 | 1 | 1 | 0 |00:00:00.01 | 3 | | | |
| 7 | TABLE ACCESS BY INDEX ROWID| ORD_PA_IF_TASKS | 1 | 2146K| 0 |00:00:00.01 | 3 | | | |
|* 8 | INDEX RANGE SCAN | ORD_PA_IF_TASKS_N1 | 1 | 2173K| 0 |00:00:00.01 | 3 | | | |
----------------------------------------------------------------------------------------------------------------------------------------------
6 - access("PROCESSED_FLAG"='U')
8 - access("PROCESSED_FLAG"='U')
Note
-----
12
Privileges
Privileges needed to execute dbms_xplan
For dbms_xplan.display_cursor
grant select on v_$session to scott;
grant select on v_$SQL_PLAN_STATISTICS_ALL to scott;
grant select on v_$sql to scott;
grant select on v_$sql_plan to scott;
OR
SELECT_CATALOG role or select any dictionary system privilege
For dbms_xplan.display_awr
grant select on dba_hist_sqltext to scott
grant select on dba_hist_sql_plan to scott;
grant select on v_$database to scott;
OR
SELECT_CATALOG role
13
Internals of dbms_xplan
Really complicated recursive SQL statements!
SELECT PLAN_TABLE_OUTPUT
FROM
TABLE(CAST(DBMS_XPLAN.PREPARE_RECORDS(:B1 , :B2 ) AS
SYS.DBMS_XPLAN_TYPE_TABLE))
14
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
Dos & Donts
Dos
1. Current execution plan and runtime statistics are the first
step.
2. Execute a test case first to reproduce.
Dont
1. 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
-------------------------------------------------------------------------------------------------------------------------
--
| 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
...
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
dbms_xplan: access and filter predicates
Added a predicate oel.open_flag=Y
------------------------------------------------------------------------------------------------------------------------
--
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart|
Pstop |
------------------------------------------------------------------------------------------------------------------------
---
| 0 | SELECT STATEMENT | | | | 11200 (100)| | |
|
| 1 | NESTED LOOPS | | 6 | 114 | 11 (0)| 00:10: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 | 9000 (0)| 00:07:01 | ROWID |
ROWID |
|* 5 | INDEX RANGE SCAN | OE_ORDER_LINES_N1 | 60000 | | 300 (0)| 00:03:01 | |
|
------------------------------------------------------------------------------------------------------------------------
---
20
Detailed execution statistics
v$sql_plan_statistics_all collects row source level execution
statistics
ROWS
CPU Setting statistics_level=ALL at system
level can be resource intensive and
Physical IO should preferably not be enabled in busy
Logical IO PRODUCTION SYSTEM
Elapsed time
21
dbms_xplan: script
Modify the script to enable extended execution statistics
--my_sql.sql script_name
set linesize 300;
set pagesize 1000;
--Declare variable and assign values
var order_id number;
execute order_id:=53759119
alter session set statistics_level=ALL; --OR ADD HINT
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
/
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
------------------------------------------------------------------------------------------------------------------------------
| 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 |
------------------------------------------------------------------------------------------------------------------------------
3 - access("OEH"."HEADER_ID"=:ORDER_ID)
5 - access("OEL"."HEADER_ID"=:ORDER_ID)
25 rows selected.
23
Alias
select * from table
(dbms_xplan.DISPLAY_CURSOR(null, null, 'ALLSTATS LAST +alias -predicate'));
24
Query Block name
SQL_ID cu2f3xhzy75vc, child number 0
-------------------------------------
SELECT /*+ gather_plan_statistics qb_name(outer_block) */ oel.line_id
FROM oe_order_lines_all oel
WHERE
oel.open_flag = 'Y'
and exists
(select /*+ qb_name(innner_block) */ 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);
25
Default QB Name
26
Hints or Outlines
set linesize 300
set pagesize 300
alter session set statistics_level='ALL';
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
*/
6 - access("PROCESSED_FLAG"='U')
7 - filter("PROCESSED_FLAG"='U')
29
Bob the Builder Copying outline as hint;
Altering Full Table Scan
set linesize 300
set pagesize 300
alter session set statistics_level='ALL';
to Index Range Scan.
SELECT
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.2')
DB_VERSION('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$3")
OUTLINE_LEAF(@"SET$1")
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_AP_IF_TASKS"."PROCESSED_FLAG"))
INDEX_RS_ASC(@"SEL$2" ORD_AP_IF_PROJECTS"@"SEL$2" (ORD_AP_IF_PROJECTS"."PROCESSED_FLAG"))
END_OUTLINE_DATA
*/
WHERE PROCESSED_FLAG = 'U')
ORDER BY TABLENAME, CREATION_DATE
/
select * from table(dbms_xplan.display_cursor
(null,null,'ALLSTATS LAST +outline'))
/
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
So many details..So little space..
Column Description
Always available columns
id 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 Estimated number of rows returned by the row source operation; derived from statistics on names object in the operation
Bytes Estimated amount of data returned by the operation
TempSpc The estimated amount of temp space usage by the operation
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
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 |
---------------------------------------------------------------------------------------------------------------
Peeked Binds (identified by position):
--------------------------------------
SQL_ID 4jtbgawt37mcd
--------------------
Plan hash value: 2294473928
---------------------------------------------------------------------------------------------------------------
| 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'
---------------------------------------------------------------------------
| 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 |
---------------------------------------------------------------------------
2 - filter("PROCESSED_FLAG"='N')
Demo @demo_oh1.sql
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
----------------------------------------------------------------------------------------
| 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 |
----------------------------------------------------------------------------------------
Demo @demo_oh2.sql
--------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows |
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 256K| | 246K|
|* 1 | INDEX UNIQUE SCAN| PA_TASKS_U1 | 256K| 1 | 246K|
--------------------------------------------------------------------
1 - access("TASK_ID"=:B1)
------------------------------------------------------------------------------------------
| 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|
------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
| 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 |
-------------------------------------------------------------------------------------------------------
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)
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
5 - access("OH"."ORDER_ID"="REM1"."ORDER_ID")
8 - filter("OH"."PROCESSED_FLAG"='N')
Remote SQL Information (identified by operation id):
----------------------------------------------------
SELECT
/*+ no_rewrite gather_plan_statistics use_nl (oh ol) */
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' ;
Demo @demo_oh3.sql
Demo @demo_oh5.sql
Note
-----
- Degree of Parallelism is 8 because of hint
2 - access("OH"."HEADER_ID"="OL"."HEADER_ID")
4 - filter(ROWNUM<1000000)
7 - filter(ROWNUM<1000000)
11 - filter(ROWNUM<1000000)
Note
-----
- Degree of Parallelism is 8 because of hint
----------------------------------------------------------------------------------------------------
| 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 |
----------------------------------------------------------------------------------------------------
Note
-----
- Degree of Parallelism is 16 because of hint
Note
-----
- SQL profile SQL_PROF_4awcsbtwr8ksz" used for this
statement
Note
-----
- Cardinality feedback used