Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jonathan Lewis EOUG Jun 2000 Execution Plans Agenda What are execution plans Where do you find execution plans Key mechanisms of execution Understanding.

Similar presentations


Presentation on theme: "Jonathan Lewis EOUG Jun 2000 Execution Plans Agenda What are execution plans Where do you find execution plans Key mechanisms of execution Understanding."— Presentation transcript:

1 Jonathan Lewis EOUG Jun 2000 Execution Plans Agenda What are execution plans Where do you find execution plans Key mechanisms of execution Understanding a complex plan Conclusion

2 Jonathan Lewis EOUG Jun 2000 Execution Plans What are execution plans Show me all clients accounts which are holding at least one position andhave no unsettled positions

3 Jonathan Lewis EOUG Jun 2000 Execution Plans What are execution plans Select * from accounts a where 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 )

4 Jonathan Lewis EOUG 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

5 Execution Plans Where do plans come from ? selectep1.v1, ep2.v2, ep3.n2 fromep3,ep2,ep1 where( ep3.v1 = 'TV Region1' orep3.v2 = 'Newspaper2' ) andep2.n1 = ep3.n1 andep2.n2 = ep3.n2 andep1.n1 = ep2.n1;

6 Jonathan Lewis EOUG Jun 2000 Execution Plans Autotrace SQL*Plus set autotrace on set autotrace on explain set autotrace traceonly explain set autotrace traceonly statistics

7 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)

8 Jonathan Lewis EOUG 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

9 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)

10 Jonathan Lewis EOUG Jun 2000 Execution Plans tkprof alter session set sql_trace true; tkprof {file stem} {file stem}\ explain=userid/password\ sort=\(options\)

11 Execution Plans tkprof (1) 301HASH 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 303 TABLE ACCESS BY INDEX ROWID EP2 606 INDEX UNIQUE SCAN (object id 21464)

12 Execution Plans tkprof (2) 0SELECT 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)

13 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 '

14 Jonathan Lewis EOUG Jun 2000 Execution Plans Key mechanisms of execution Data access methods Data manipulation methods

15 Jonathan Lewis EOUG Jun 2000 Execution Plans Data access select * from dept where dname = 'SALES'; TABLE ACCESS FULL DEPT

16 Jonathan Lewis EOUG 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)

17 Jonathan Lewis EOUG Jun 2000 Execution Plans Parent and Child select * from dept where deptno = 10; IdPidPlan 10TABLE ACCESS BY ROWID DEPT 21 INDEX UNIQUE SCAN UNIQUE DPT_PK

18 Jonathan Lewis EOUG Jun 2000 Execution Plans Parent, child, and grandchild select * from emp where deptno = 10; IdPidPlan 10TABLE ACCESS BY ROWID EMP 21 BITMAP CONVERSION TO ROWIDS 32 BITMAP INDEX SINGLE VALUE EMP_FK_DPT

19 Jonathan Lewis EOUG Jun 2000 Execution Plans Parent with two children select* fromemp wherejob='SALESMAN' andsal=1250; IdPidPos Plan 101 TABLE ACCESS BY ROWID EMP 211 AND-EQUAL 321 INDEX RANGE SCAN NON-UNIQUE EMP_JOB 422 INDEX RANGE SCAN NON-UNIQUE EMP_SAL

20 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms: Data handling select max(sal),count(*) from emp; SORT AGGREGATE TABLE ACCESS FULL EMP

21 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms: Data handling select deptno,max(sal) from emp group by deptno; SORT GROUP BY TABLE ACCESS FULL EMP

22 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms: Data handling select deptno,max(sal) from emp group by deptno; SORT GROUP BY (NOSORT) TABLE ACCESS BY ROWID EMP INDEX RANGE SCAN NON-UNIQUE EMP_FK_DP

23 Jonathan Lewis EOUG 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

24 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms: Data handling select deptno,max(sal) from emp group by deptno having max(sal) > 3000; FILTER SORT GROUP BY TABLE ACCESS FULL EMP

25 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms: Data handling select mgr,count(*) from emp where job = 'SALESMAN' group by mgr order by count(*) desc; SORT ORDER BY SORT GROUP BY TABLE ACCESS BY ROWID EMP INDEX RANGE SCAN NON-UNIQUE EMP_FK_JOB

26 Jonathan Lewis EOUG 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

27 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms: Data handling select * from emp where job='SALESMAN' or deptno = 10; CONCATENATION TABLE ACCESS BY ROWID EMP

28 Jonathan Lewis EOUG 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

29 Jonathan Lewis EOUG 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

30 Jonathan Lewis EOUG 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

31 Jonathan Lewis EOUG 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

32 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms: Data handling select * from emp where exists ( select null from projects prj where prj.empno = emp.empno and prj.date_completed is null ) FILTER TABLE ACCESS FULL EMP TABLE ACCESS BY ROWID PROJECTS INDEX RANGE SCAN NON-UNIQUE PRJ_FK_EMP

33 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms: Joins Nested Loops Sort Merge Hash

34 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms:Nested Loop Nested Loops [The first set of data] [The second set of data]

35 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms:Nested Loop Nested Loops Table scan FULL the red pack Table scan FULL the blue pack

36 Jonathan Lewis EOUG 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

37 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms:Sort Merge Merge Join [The first sorted set of data] [The second sorted set of data]

38 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms:Sort Merge Merge Join Sort join Table access full DEPT Sort join Table access full EMP

39 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms:Sort Merge Merge Join Index Range Scan DPT_IDX Sort join Table access full EMP

40 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms:Hash Hash [The first set of data] [The second set of data]

41 Jonathan Lewis EOUG Jun 2000 Execution Plans Mechanisms:Hash Hash Table access FULL DEPT Table access FULL EMP

42 Jonathan Lewis EOUG Jun 2000 Execution Plans Understanding a complex plan Nested Loops [The first set of data] [The second set of data]

43 Jonathan Lewis EOUG 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

44 Jonathan Lewis EOUG Jun 2000 Execution Plans Understanding a complex plan Table access by rowid SALGRADE Index range scan SAL_PK

45 Jonathan Lewis EOUG 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 Table access by rowid SALGRADE Index range scan SAL_PK

46 Jonathan Lewis EOUG 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

47 Jonathan Lewis EOUG 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 Table access by rowid EMP Index range scan EMP_FK_DPT Table access by rowid SALGRADE Index range scan SAL_PK

48 Jonathan Lewis EOUG Jun 2000 Execution Plans Understanding a complex plan Hash [The first set of data] [The second set of data]

49 Jonathan Lewis EOUG Jun 2000 Execution Plans Understanding a complex plan Hash Table scan full Medium_table Table scan full Large_table

50 Jonathan Lewis EOUG Jun 2000 Execution Plans Understanding a complex plan Table scan full Small_table

51 Jonathan Lewis EOUG Jun 2000 Execution Plans Understanding a complex plan Hash Table scan full Medium_table Table scan full Large_table Table scan full Small_table

52 Jonathan Lewis EOUG 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

53 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)

54 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)

55 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)

56 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)

57 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)

58 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)

59 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)

60 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)

61 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)

62 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)

63 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)

64 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)

65 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)

66 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)

67 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)

68 Jonathan Lewis EOUG Jun 2000 Execution Plans Conclusion Execution plans are important How much effort do you take Break complex plans down


Download ppt "Jonathan Lewis EOUG Jun 2000 Execution Plans Agenda What are execution plans Where do you find execution plans Key mechanisms of execution Understanding."

Similar presentations


Ads by Google