jonathan lewis eoug jun 2000 execution plans agenda what are execution plans where do you find...
TRANSCRIPT
Jonathan LewisEOUG Jun 2000
Execution Plans
Agenda
• What are execution plans
• Where do you find execution plans
• Key mechanisms of execution
• Understanding a complex plan
• Conclusion
Jonathan LewisEOUG Jun 2000
Execution Plans
What are execution plans
Show me
all clients accounts
which are
holding at least one position
and have no unsettled positions
Jonathan LewisEOUG Jun 2000
Execution Plans
What are execution plans
Select * from accounts awhere exists ( select null from holdings h1
where h1.account = a.account and av_qty != 0
)and not exists (select null from holdings h2
where h2.account = a.acount and unset_qty = 0
)
Jonathan LewisEOUG Jun 2000
Execution Plans
What are execution plans
SELECT STATEMENT
FILTER
TABLE ACCESS FULL ACCOUNT
TABLE ACCESS BY ROWID HOLDING
INDEX RANGE SCAN HOLD_IX1 NON-UNIQUE
TABLE ACCESS BY ROWID HOLDING
INDEX RANGE SCAN HOLD_IX1 NON-UNIQUE
Execution Plans
Where do plans come from ?
select ep1.v1, ep2.v2, ep3.n2
from ep3, ep2, ep1
where (
ep3.v1 = 'TV Region1'
or ep3.v2 = 'Newspaper2'
)
and ep2.n1 = ep3.n1
and ep2.n2 = ep3.n2
and ep1.n1 = ep2.n1;
Jonathan LewisEOUG Jun 2000
Execution Plans
Autotrace
• SQL*Plus
• set autotrace on
• set autotrace on explain
• set autotrace traceonly explain
• set autotrace traceonly statistics
Execution Plans
Autotrace
0 SELECT STATEMENT Optimizer=FIRST_ROWS (c,c,b)
1 0 HASH JOIN (c,c,b)
2 1 TABLE ACCESS (FULL) OF 'EP1' (c,c,b)
3 1 NESTED LOOPS (c,c,b)
4 3 TABLE ACCESS (BY INDEX ROWID) OF 'EP3' (c,c,b)
5 4 BITMAP CONVERSION (TO ROWIDS)
6 5 BITMAP OR
7 6 BITMAP INDEX (SINGLE VALUE) OF 'EP3_BI1'
8 6 BITMAP INDEX (SINGLE VALUE) OF 'EP3_BI2'
9 3 TABLE ACCESS (BY INDEX ROWID) OF 'EP2' (c,c,b)
10 9 INDEX (UNIQUE SCAN) OF 'EP2_PK' (UNIQUE)
Jonathan LewisEOUG Jun 2000
Execution Plans
Explain Plan
explain plan
set statement_id = userenv(‘sessionid’)
for
sql_statement;
select from plan_table
start with
connect by
order by
Execution Plans
Explain Plan
0 402 SELECT STATEMENT (first_rows) (c,c,b)
1 0 1 HASH JOIN (c,c,b)
2 1 1 3 TABLE ACCESS (analyzed) EP1 (full) (c,c,b)
3 1 2 NESTED LOOPS (c,c,b)
4 3 1 1 TABLE ACCESS (analyzed) EP3 (by index rowid) (c,c,b)
5 4 1 BITMAP CONVERSION (to rowids)
6 5 1 BITMAP OR
7 6 1 BITMAP INDEX EP3_BI1 (single value)
8 6 2 BITMAP INDEX EP3_BI2 (single value)
9 3 2 2 TABLE ACCESS (analyzed) EP2 (by index rowid) (c,c,b)
10 9 1 INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Jonathan LewisEOUG Jun 2000
Execution Plans
tkprof
alter session set sql_trace true;
tkprof {file stem} {file stem} \
explain=userid/password \
sort=\(options\)
Execution Plans
tkprof (1)
301 HASH JOIN
200 TABLE ACCESS FULL EP1
303 NESTED LOOPS
304 TABLE ACCESS BY INDEX ROWID EP3
304 BITMAP CONVERSION TO ROWIDS
2 BITMAP OR
2 BITMAP INDEX SINGLE VALUE
2 BITMAP INDEX SINGLE VALUE
303 TABLE ACCESS BY INDEX ROWID EP2
606 INDEX UNIQUE SCAN (object id 21464)
Execution Plans
tkprof (2)
0 SELECT STATEMENT GOAL: HINT: FIRST_ROWS
301 HASH JOIN
200 TABLE ACCESS GOAL: ANALYZED (FULL) OF 'EP1'
303 NESTED LOOPS
304 TABLE ACCESS GOAL: ANA (BY IND RID) OF 'EP3'
304 BITMAP CONVERSION (TO ROWIDS)
2 BITMAP OR
2 BITMAP INDEX (SINGLE VALUE) OF 'EP3_BI1'
2 BITMAP INDEX (SINGLE VALUE) OF 'EP3_BI2'
303 TABLE ACCESS GOAL: ANA (BY IND RID) OF 'EP2'
606 INDEX GOAL: ANA (UNIQ SC) OF 'EP2_PK' (UNIQ)
Execution Plans
Trace file
id=1 cnt=301 pid=0 pos=0 obj=0 op='HASH JOIN '
id=2 cnt=200 pid=1 pos=1 obj=21461 op='TABLE ACCESS FULL EP1 '
id=3 cnt=303 pid=1 pos=2 obj=0 op='NESTED LOOPS '
id=4 cnt=304 pid=3 pos=1 obj=21465 op='TABLE ACCESS BY IND RID EP3 '
id=5 cnt=304 pid=4 pos=1 obj=0 op='BITMAP CONVERSION TO ROWIDS '
id=6 cnt=2 pid=5 pos=1 obj=0 op='BITMAP OR '
id=7 cnt=2 pid=6 pos=1 obj=21466 op='BITMAP INDEX SINGLE VALUE '
id=8 cnt=2 pid=6 pos=2 obj=21467 op='BITMAP INDEX SINGLE VALUE '
id=9 cnt=303 pid=3 pos=2 obj=21463 op='TABLE ACCESS BY IND RID EP2 '
id=10 cnt=606 pid=9 pos=1 obj=21464 op='INDEX UNIQUE SCAN '
Jonathan LewisEOUG Jun 2000
Execution Plans
Key mechanisms of execution
• Data access methods
• Data manipulation methods
Jonathan LewisEOUG Jun 2000
Execution Plans
Data access
select * from dept
where dname = 'SALES';
TABLE ACCESS FULL DEPT
Jonathan LewisEOUG Jun 2000
Execution Plans
Data access
select empno from emp
where mgr = 7698;
INDEX RANGE SCAN NON-UNIQUE EMP_FK_MGR
The index is (mgr,empno)
Jonathan LewisEOUG Jun 2000
Execution Plans
Parent and Child
select * from dept
where deptno = 10;
Id Pid Plan
1 0 TABLE ACCESS BY ROWID DEPT
2 1 INDEX UNIQUE SCAN UNIQUE DPT_PK
Jonathan LewisEOUG Jun 2000
Execution Plans
Parent, child, and grandchild
select * from emp
where deptno = 10;
IdPid Plan
1 0 TABLE ACCESS BY ROWID EMP
2 1 BITMAP CONVERSION TO ROWIDS
3 2 BITMAP INDEX SINGLE VALUE EMP_FK_DPT
Jonathan LewisEOUG Jun 2000
Execution Plans
Parent with two children
select *
from emp
where job='SALESMAN'
and sal=1250;
IdPid Pos Plan
1 0 1 TABLE ACCESS BY ROWID EMP
2 1 1 AND-EQUAL
3 2 1 INDEX RANGE SCAN NON-UNIQUE EMP_JOB
4 2 2 INDEX RANGE SCAN NON-UNIQUE EMP_SAL
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Data handling
select
max(sal), count(*)
from emp;
SORT AGGREGATE
TABLE ACCESS FULL EMP
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Data handling
select deptno,max(sal)
from empgroup by deptno;
SORT GROUP BY
TABLE ACCESS FULL EMP
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Data handling
select deptno,max(sal)
from empgroup by deptno;
SORT GROUP BY (NOSORT)
TABLE ACCESS BY ROWID EMP
INDEX RANGE SCAN NON-UNIQUE EMP_FK_DP
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Data handling
select max(empno) from emp
where mgr = 7698;
The index is emp_fk_mgr (mgr,empno)
sort (aggregate)
first row
index (range scan (min/max)) of emp_fk_mgr
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Data handling
select deptno,max(sal)from empgroup by deptnohaving max(sal) > 3000;
FILTER
SORT GROUP BY
TABLE ACCESS FULL EMP
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Data handling
select mgr,count(*)from emp where job = 'SALESMAN'group by mgrorder by count(*) desc;
SORT ORDER BY
SORT GROUP BY
TABLE ACCESS BY ROWID EMP
INDEX RANGE SCAN NON-UNIQUE EMP_FK_JOB
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Data handling
select * from emp where job='SALESMAN' or deptno = 10;
CONCATENATION
TABLE ACCESS BY ROWID EMP
BITMAP CONVERSION TO ROWIDS
BITMAP INDEX SINGLE VALUE EMP_FK_DPT
TABLE ACCESS BY ROWID EMP
INDEX RANGE SCAN NON-UNIQUE EMP_FK_JOB
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Data handling
select * from emp where job='SALESMAN' or deptno = 10;
CONCATENATION
TABLE ACCESS BY ROWID EMP
TABLE ACCESS BY ROWID EMP
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Data handling
select * from emp where job='SALESMAN' or deptno = 10;
CONCATENATION
TABLE ACCESS BY ROWID EMP
BITMAP CONVERSION TO ROWIDS
BITMAP INDEX SINGLE VALUE EMP_FK_DPT
TABLE ACCESS BY ROWID EMP
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Data handling
select * from emp where job='SALESMAN' or deptno = 10;
CONCATENATION
TABLE ACCESS BY ROWID EMP
TABLE ACCESS BY ROWID EMP
INDEX RANGE SCAN NON-UNIQUE EMP_FK_JOB
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Data handling
select * from emp where job='SALESMAN' or deptno = 10;
Id Pid Ps Plan
1 0 1 CONCATENATION
2 1 1 TABLE ACCESS BY ROWID EMP
3 2 1 BITMAP CONVERSION TO ROWIDS
4 3 1 BITMAP INDEX SINGLE VALUE EMP_FK_DPT
5 1 2 TABLE ACCESS BY ROWID EMP
6 5 1 INDEX RANGE SCAN NON-UNIQUE EMP_FK_JOB
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Data handling
select * from emp where job='SALESMAN' or job = 'CLERK'
INLIST ITERATOR
TABLE ACCESS BY ROWID EMP
INDEX RANGE SCAN NON-UNIQUE EMP_FK_JOB
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Data handling
select * from emp where exists (
select null from projects prjwhere prj.empno = emp.empnoand prj.date_completed is null
)
FILTER
TABLE ACCESS FULL EMP
TABLE ACCESS BY ROWID PROJECTS
INDEX RANGE SCAN NON-UNIQUE PRJ_FK_EMP
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Nested Loop
Nested Loops
[The first set of data]
[The second set of data]
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Nested Loop
Nested Loops
Table scan FULL the red pack
Table scan FULL the blue pack
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Nested Loop
Nested Loops
Table access by rowid DEPT
Index unique scan DPT_PK
Table access by rowid EMP
Index range scan EMP_FK_DPT
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Sort Merge
Merge Join
[The first sorted set of data]
[The second sorted set of data]
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Sort Merge
Merge Join
Sort join
Table access full DEPT
Sort join
Table access full EMP
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Sort Merge
Merge Join
Index Range Scan DPT_IDX
Sort join
Table access full EMP
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Hash
Hash
[The first set of data]
[The second set of data]
Jonathan LewisEOUG Jun 2000
Execution Plans
Mechanisms: Hash
Hash
Table access FULL DEPT
Table access FULL EMP
Jonathan LewisEOUG Jun 2000
Execution Plans
Understanding a complex plan
Nested Loops
[The first set of data]
[The second set of data]
Jonathan LewisEOUG Jun 2000
Execution Plans
Understanding a complex plan
Nested Loops
Table access by rowid DEPT
Index unique scan DPT_PK
Table access by rowid EMP
Index range scan EMP_FK_DPT
Jonathan LewisEOUG Jun 2000
Execution Plans
Understanding a complex plan
Table access by rowid SALGRADE
Index range scan SAL_PK
Jonathan LewisEOUG Jun 2000
Execution Plans
Understanding a complex plan
Nested Loops
Nested Loops
Table access by rowid DEPT
Index unique scan DPT_PK
Table access by rowid EMP
Index range scan EMP_FK_DPT
Table access by rowid SALGRADE
Index range scan SAL_PK
Jonathan LewisEOUG Jun 2000
Execution Plans
Understanding a complex plan
Nested Loops
Table access by rowid REGION
Index unique scan REG_PK
Table access by rowid DEPT
Index unique scan DPT_FK_REG
Jonathan LewisEOUG Jun 2000
Execution Plans
Understanding a complex plan
Nested Loops
Nested Loops
Nested Loops
Table access by rowid REGION
Index unique scan REG_PK
Table access by rowid DEPT
Index unique scan DPT_FK_REG
Table access by rowid EMP
Index range scan EMP_FK_DPT
Table access by rowid SALGRADE
Index range scan SAL_PK
Jonathan LewisEOUG Jun 2000
Execution Plans
Understanding a complex plan
Hash
[The first set of data]
[The second set of data]
Jonathan LewisEOUG Jun 2000
Execution Plans
Understanding a complex plan
Hash
Table scan full Medium_table
Table scan full Large_table
Jonathan LewisEOUG Jun 2000
Execution Plans
Understanding a complex plan
Table scan full Small_table
Jonathan LewisEOUG Jun 2000
Execution Plans
Understanding a complex plan
Hash
Hash
Table scan full Medium_table
Table scan full Large_table
Table scan full Small_table
Jonathan LewisEOUG Jun 2000
Execution Plans
Understanding a complex plan
Hash
Table scan full Small_table
Hash
Table scan full Medium_table
Table scan full Large_table
Execution Plans
Explain Plan
SELECT STATEMENT (first_rows)
HASH JOIN
TABLE ACCESS (analyzed) EP1 (full)
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Execution Plans
Explain Plan - top down
SELECT STATEMENT (first_rows)
HASH JOIN
TABLE ACCESS (analyzed) EP1 (full)
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Execution Plans
Explain Plan
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Execution Plans
Explain Plan
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
Execution Plans
Explain Plan
SELECT STATEMENT (first_rows)
HASH JOIN
TABLE ACCESS (analyzed) EP1 (full)
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Execution Plans
Explain Plan - Bottom up
SELECT STATEMENT (first_rows)
HASH JOIN
TABLE ACCESS (analyzed) EP1 (full)
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Execution Plans
Explain Plan
SELECT STATEMENT (first_rows)
HASH JOIN
TABLE ACCESS (analyzed) EP1 (full)
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Execution Plans
Explain Plan
SELECT STATEMENT (first_rows)
HASH JOIN
TABLE ACCESS (analyzed) EP1 (full)
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Execution Plans
Explain Plan
SELECT STATEMENT (first_rows)
HASH JOIN
TABLE ACCESS (analyzed) EP1 (full)
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Execution Plans
Explain Plan
SELECT STATEMENT (first_rows)
HASH JOIN
TABLE ACCESS (analyzed) EP1 (full)
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Execution Plans
Explain Plan
SELECT STATEMENT (first_rows)
HASH JOIN
TABLE ACCESS (analyzed) EP1 (full)
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Execution Plans
Explain Plan
SELECT STATEMENT (first_rows)
HASH JOIN
TABLE ACCESS (analyzed) EP1 (full)
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Execution Plans
Explain Plan
SELECT STATEMENT (first_rows)
HASH JOIN
TABLE ACCESS (analyzed) EP1 (full)
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Execution Plans
Explain Plan
SELECT STATEMENT (first_rows)
HASH JOIN
TABLE ACCESS (analyzed) EP1 (full)
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)
Execution Plans
Explain Plan
SELECT STATEMENT (first_rows)
HASH JOIN
TABLE ACCESS (analyzed) EP1 (full)
NESTED LOOPS
TABLE ACCESS (analyzed) EP3 (by index rowid)
BITMAP CONVERSION (to rowids)
BITMAP OR
BITMAP INDEX EP3_BI1 (single value)
BITMAP INDEX EP3_BI2 (single value)
TABLE ACCESS (analyzed) EP2 (by index rowid)
INDEX (analyzed) UNIQUE EP2_PK (unique scan)