Do You Know The 11g Plan?

5,636 views

Published on

This paper describes the evolution of the Plan table and DBMSX_PLAN in 11g and some of the features that can be used to troubelshoot SQL performance effectively and efficiently.

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,636
On SlideShare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
401
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Do You Know The 11g Plan?

  1. 1. Do you know the 11g Plan? Mahesh Vallampati
  2. 2. About the Speaker <ul><li>Mahesh Vallampati </li></ul><ul><ul><li>Senior Practice Manager at SmartDog Services </li></ul></ul><ul><ul><li>Senior Sales Consulting Manager at Hotsos. </li></ul></ul><ul><ul><li>Director of IT Database Services at a company in Houston </li></ul></ul><ul><ul><li>Worked at Oracle for nine years </li></ul></ul><ul><ul><li>Published in Oracle magazine </li></ul></ul>
  3. 3. Agenda <ul><li>Plan Table </li></ul><ul><li>V$SQL_PLAN and Related Views </li></ul><ul><li>DBMS_XPLAN </li></ul><ul><li>Key Performance Takeaways </li></ul>
  4. 4. The Plan Table
  5. 5. Plan Table <ul><li>When Oracle parses a query, it creates a plan to execute the query </li></ul><ul><li>The plan is a set of row source operations </li></ul><ul><li>Row source operations are specific data access and join/sort method’s Oracle is going to execute to fulfill the request done by the query </li></ul><ul><li>Some of the row source operations are </li></ul><ul><ul><li>Index Scan’s (Unique, Range, Skip etc.) </li></ul></ul><ul><ul><li>Table Access (By Index Rowid, Full Table Scan’s) </li></ul></ul><ul><ul><li>Joins (Nested Loops, Hash, Sort-Merge) </li></ul></ul><ul><ul><li>Sort Operations </li></ul></ul>
  6. 6. Explain Plan Example - I select empno, ename, sal, deptno from emp where empno = 7654 ; ----------------------------------------------------------------------------------- |Id | Operation | Name |Rows|Bytes|Cost (%CPU)|Time | ----------------------------------------------------------------------------------- | 0| SELECT STATEMENT | | 1| 17| 1 (0)|00:00:01 | | 1| TABLE ACCESS BY INDEX ROWID| EMP | 1| 17| 1 (0)|00:00:01 | |* 2| INDEX UNIQUE SCAN | EMP_EMPNO_PK | 1| | 0 (0)|00:00:01 | ----------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access(&quot;EMPNO&quot;=7654)
  7. 7. Explain Plan Example - II select ename from emp where comm is not null; -------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 4 | 32 | 4 (0)| 00:00:01 | |* 1 | TABLE ACCESS FULL| EMP | 4 | 32 | 4 (0)| 00:00:01 | -------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter(&quot;COMM&quot; IS NOT NULL)
  8. 8. How to read an indented, ordered Oracle execution plan… <ul><li>An execution plan line represents a row source operation (RSO) </li></ul><ul><li>An indented RSO is the child of the first prior less-indented RSO </li></ul><ul><li>A child RSO must complete before its parent can </li></ul><ul><li>Order of execution </li></ul><ul><ul><li>RSOs begin in top-down order at step 0 </li></ul></ul><ul><ul><li>RSOs complete only after their children complete </li></ul></ul>
  9. 9. Plan Table <ul><li>The typical name for a plan table is PLAN_TABLE , but you may use any name you wish </li></ul><ul><li>Create the plan table by running utlxplan.sql , located in $ORACLE_HOME/rdbms/admin </li></ul><ul><ul><li>Create one per instance or one per schema </li></ul></ul>
  10. 10. Explain Plan Examples select empno, ename, sal, deptno from emp where empno = 7654 ; ----------------------------------------------------------------------------------- |Id | Operation | Name |Rows|Bytes|Cost (%CPU)|Time | ----------------------------------------------------------------------------------- | 0| SELECT STATEMENT | | 1| 17| 1 (0)|00:00:01 | | 1| TABLE ACCESS BY INDEX ROWID| EMP | 1| 17| 1 (0)|00:00:01 | |* 2| INDEX UNIQUE SCAN | EMP_EMPNO_PK | 1| | 0 (0)|00:00:01 | ----------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access(&quot;EMPNO&quot;=7654)
  11. 11. Divide and Conquer for Bigger Plans <ul><li>select d.dname, e.ename, s.grade, e.sal from dept d, emp e, salgrade s </li></ul><ul><li>where d.deptno = e.deptno and e.sal between s.losal and s.hisal ; </li></ul><ul><li>-------------------------------------------------------------------------------------- </li></ul><ul><li>| Id | PID | Operation | Name | Rows | Bytes | Cost | </li></ul><ul><li>-------------------------------------------------------------------------------------- </li></ul><ul><li>| 0 | | SELECT STATEMENT | | 1 | 28 | 7 | </li></ul><ul><li>| 1 | 0 | NESTED LOOPS | | 1 | 28 | 7 | </li></ul><ul><li>| 2 | 1 | MERGE JOIN | | 1 | 17 | 6 | </li></ul><ul><li>| 3 | 2 | SORT JOIN | | 13 | 117 | 2 | </li></ul><ul><li>|* 4 | 3 | TABLE ACCESS BY INDEX ROWID| EMP | 13 | 117 | 2 | </li></ul><ul><li>| 5 | 4 | INDEX FULL SCAN | EMP_SAL | 14 | | 1 | </li></ul><ul><li>|* 6 | 2 | FILTER | | | | | </li></ul><ul><li>|* 7 | 6 | SORT JOIN | | | | | </li></ul><ul><li>| 8 | 7 | TABLE ACCESS FULL | SALGRADE | 5 | 40 | 2 | </li></ul><ul><li>| 9 | 1 | TABLE ACCESS BY INDEX ROWID | DEPT | 1 | 11 | 1 | </li></ul><ul><li>|* 10 | 9 | INDEX UNIQUE SCAN | DEPT_DEPTNO_PK | 1 | | | </li></ul><ul><li>-------------------------------------------------------------------------------------- </li></ul><ul><li>Predicate Information (identified by operation id): </li></ul><ul><li>--------------------------------------------------- </li></ul><ul><li>4 - filter(&quot;E&quot;.&quot;DEPTNO&quot; IS NOT NULL) </li></ul><ul><li>6 - filter(&quot;E&quot;.&quot;SAL&quot;<=&quot;S&quot;.&quot;HISAL&quot;) </li></ul><ul><li>7 - access(&quot;E&quot;.&quot;SAL&quot;>=&quot;S&quot;.&quot;LOSAL&quot;) </li></ul><ul><li>filter(&quot;E&quot;.&quot;SAL&quot;>=&quot;S&quot;.&quot;LOSAL&quot;) </li></ul><ul><li>10 - access(&quot;D&quot;.&quot;DEPTNO&quot;=&quot;E&quot;.&quot;DEPTNO&quot;) </li></ul>
  12. 12. Plan Table Evolution <ul><li>The Plan Table Contains the information about the forecasted row source operations for the execution of the SQL statements </li></ul><ul><li>The changes in the PLAN_TABLE across versions. </li></ul><ul><li>Introduced in 9i </li></ul><ul><ul><li>Access Predicates </li></ul></ul><ul><ul><li>Filter Predicates </li></ul></ul><ul><li>9i to 10.1 </li></ul><ul><ul><li>Projection </li></ul></ul><ul><ul><li>Time </li></ul></ul><ul><ul><li>QBlock_name </li></ul></ul><ul><ul><li>Plan_id </li></ul></ul><ul><ul><li>Object_Alias </li></ul></ul><ul><ul><li>Depth </li></ul></ul><ul><li>10.1 to 10.2 </li></ul><ul><ul><li>other_xml </li></ul></ul><ul><li>10.2 to 11g </li></ul><ul><ul><li>No Changes </li></ul></ul>
  13. 13. DBMS_XPLAN
  14. 14. DBMS_XPLAN <ul><li>Introduced in 9iR2 </li></ul><ul><li>Easy way of viewing the output of the EXPLAIN PLAN command in several, predefined formats </li></ul><ul><li>10g has some enhanced functionality </li></ul><ul><li>We will use the DISPLAY function of DBMS_XPLAN available in 9iR2, 10g and 11g </li></ul>
  15. 15. DBMS_XPLAN <ul><li>Ensure that you are using the right version of the </li></ul><ul><ul><li>PLAN_TABLE </li></ul></ul><ul><ul><li>DBMS_XPLAN </li></ul></ul><ul><li>Version incompatibilities may cause some issues </li></ul><ul><li>Where is plan table and DBMS_XPLAN? </li></ul><ul><ul><li>Plan Table - $ORACLE_HOME/rdbms/admin/utlxplan.sql </li></ul></ul><ul><ul><li>DBMS_XPLAN - $ORACLE_HOME/rdbms/admin/dbmsxpln.sql </li></ul></ul>
  16. 16. Using DBMS_XPLAN <ul><li>EXPLAIN PLAN </li></ul><ul><li>SET STATEMENT_ID = 'abc' </li></ul><ul><li>FOR </li></ul><ul><li>select object_type, count(1) </li></ul><ul><li>from dba_objects </li></ul><ul><li>where owner= 'SCOTT' </li></ul><ul><li>group by object_type; </li></ul>
  17. 17. DBMS_XPLAN.DISPLAY Options <ul><li>Format parameter for this function choices are </li></ul><ul><li>BASIC – Just displays the minimum information in the plan </li></ul><ul><li>TYPICAL – Displays the relevant information in the plan and predicate information (PX information if applicable) </li></ul><ul><li>SERIAL – Like typical, but no parallel execution information even if applicable </li></ul><ul><li>ALL – All of typical including projections, alias, etc. </li></ul>
  18. 18. DBMS_XPLAN. DISPLAY Examples <ul><li>SELECT * FROM TABLE(dbms_xplan.display('PLAN_TABLE', 'abc','BASIC')); </li></ul><ul><li>SELECT * FROM TABLE(dbms_xplan.display('PLAN_TABLE', ‘abc','TYPICAL')); </li></ul><ul><li>SELECT * FROM TABLE(dbms_xplan.display('PLAN_TABLE', </li></ul><ul><li>'abc','ALL')); </li></ul><ul><li>These are display formats for DBMS_XPLAN </li></ul>
  19. 19. DBMS_XPLAN.DISPLAY Output
  20. 20. DBMS_XPLAN Package - # of Procedures and Functions
  21. 21. Recap <ul><li>DBMS_XPLAN has been around since 9.2 </li></ul><ul><li>It is an elegant way of looking at EXPLAIN PLAN outputs </li></ul><ul><li>The “TYPICAL” option of DBMS_XPLAN.DISPLAY is most useful because it ties predicate information (access and filters) back to the predicted row source operation lines in the explained plan </li></ul><ul><li>11g introduced XML as an output option for plans </li></ul>
  22. 22. V$ SQL_PLAN Views
  23. 23. V$SQL and Related views View Name Description V$SQL The SQL Statement that is being executed and its non-plan details V$SQL_PLAN Contains the execution plan information for each child cursor loaded in the library cache V$SQL_PLAN_STATISTICS* Provides execution statistics at the row source level for each child cursor V$SQL_PLAN_STATISTICS_ALL*(Merges V$SQL_PLAN_STATISTICS with V$SQL_AREA) Contains memory usage statistics for row sources that use SQL memory (sort or hash-join)
  24. 24. V$SQL – New Columns in 11g Column Data Type Comment TYPECHECK_MEM NUMBER ??? IS_BIND_SENSITIVE VARCHAR2(1) Indicates whether the cursor is bind sensitive (Y) or not (N). A query is considered bind-sensitive if the optimizer peeked at one of its bind variable values when computing predicate selectivities and where a change in a bind variable value may cause the optimizer to generate a different plan. IS_BIND_AWARE VARCHAR2(1) Indicates whether the cursor is bind aware (Y) or not (N). A query is considered bind-aware if it has been marked to use extended cursor sharing. The query would already have been marked as bind-sensitive. IS_SHAREABLE VARCHAR2(1) Indicates whether the cursor can be shared (Y) or not (N) SQL_PATCH VARCHAR2(30) SQL patch used for this statement, if any SQL_PLAN_BASELINE VARCHAR2(30) SQL plan baseline used for this statement, if any
  25. 25. V$SQL and Related views in 11g View Name 11g enhancement V$SQL_PLAN Added child address and timestamp column V$SQL_PLAN_STATISTICS* Added child address column V$SQL_PLAN_STATISTICS_ALL*(Merges V$SQL_PLAN_STATISTICS with V$SQL_AREA) Added child address column
  26. 26. Viewing V$SQL_PLAN Data <ul><li>DBMS_XPLAN has made it easier to look at the data underlying the V$SQL_PLAN and V$SQL_PLAN_STATISTICS data </li></ul><ul><li>Available starting 10g </li></ul><ul><li>Lets you view the run time plan or the execution plan of a SQL Statement </li></ul><ul><li>Also, lets you view the execution statistics for a run of the SQL Statement or all prior runs </li></ul>
  27. 27. Key Performance Takeaways
  28. 28. New in 11g
  29. 29. SQL Plan Baselines
  30. 30. SQL Plan Baselines <ul><li>DBMS_XPLAN.DISPLAY_SQL_PLAN_BASELINE takes in three arguments. </li></ul><ul><li>SQL_HANDLE  SQL_HANDLE from dba_sql_plan_baselines </li></ul><ul><li>PLAN_NAME  Name of the plan </li></ul><ul><li>FORMAT  BASIC, TYPICAL, ALL </li></ul><ul><li>Init.ora paramter optimizer_capture_sql_plan_baselines = true </li></ul><ul><li>  </li></ul><ul><li>FUNCTION DBMS_XPLAN.DISPLAY_SQL_PLAN_BASELINE RETURNS DBMS_XPLAN_TYPE_TABLE </li></ul><ul><li>Argument Name Type In/Out Default? </li></ul><ul><li>------------------------------ ----------------------- ------ -------- </li></ul><ul><li>SQL_HANDLE VARCHAR2 IN DEFAULT </li></ul><ul><li>PLAN_NAME VARCHAR2 IN DEFAULT </li></ul><ul><li>FORMAT VARCHAR2 IN DEFAULT </li></ul>
  31. 31. SQL Plan Baselines <ul><li>select * from table(dbms_xplan.display_sql_plan_baseline('SYS_SQL_8bab62f0bc1db3bc'))  </li></ul><ul><li>PLAN_TABLE_OUTPUT </li></ul><ul><li>---------------------------------------------------------------- </li></ul><ul><li>SQL handle: SYS_SQL_8bab62f0bc1db3bc </li></ul><ul><li>SQL text: select /*+ full(t1) */ * from t1 where c1 = 1 </li></ul><ul><li>---------------------------------------------------------------- </li></ul>
  32. 32. SQL Plan Baselines <ul><li>Plan name: SYS_SQL_PLAN_bc1db3bc750635c2 </li></ul><ul><li>Enabled: YES Fixed: NO Accepted: YES Origin: MANUAL-LOAD </li></ul><ul><li>------------------------------------------------------------------------------------- </li></ul><ul><li>Plan hash value: 1420382924 </li></ul><ul><li>------------------------------------------------------------------------------------- </li></ul><ul><li>| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | </li></ul><ul><li>------------------------------------------------------------------------------------- </li></ul><ul><li>| 0 | SELECT STATEMENT | | 1 | 9 | 2 (0)| 00:00:01 | </li></ul><ul><li>| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1 | 9 | 2 (0)| 00:00:01 | </li></ul><ul><li>|* 2 | INDEX RANGE SCAN | T1_N1 | 1 | | 1 (0)| 00:00:01 | </li></ul><ul><li>------------------------------------------------------------------------------------- </li></ul><ul><li>Predicate Information (identified by operation id): </li></ul><ul><li>2 - access(&quot;C1&quot;=1) </li></ul>
  33. 33. SQL Plan Baselines <ul><li>Plan name: SYS_SQL_PLAN_bc1db3bcdbd90e8e </li></ul><ul><li>Enabled: YES Fixed: NO Accepted: YES Origin: AUTO-CAPTURE </li></ul><ul><li>-------------------------------------------------------------------------- </li></ul><ul><li>Plan hash value: 3617692013 </li></ul><ul><li>-------------------------------------------------------------------------- </li></ul><ul><li>| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | </li></ul><ul><li>-------------------------------------------------------------------------- </li></ul><ul><li>| 0 | SELECT STATEMENT | | 1 | 9 | 59 (6)| 00:00:01 | </li></ul><ul><li>|* 1 | TABLE ACCESS FULL| T1 | 1 | 9 | 59 (6)| 00:00:01 | </li></ul><ul><li>-------------------------------------------------------------------------- </li></ul><ul><li>Predicate Information (identified by operation id): </li></ul><ul><li>--------------------------------------------------- </li></ul><ul><li>1 - filter(&quot;C1&quot;=1) </li></ul>
  34. 34. Plan Output in XML Format
  35. 35. DBMS_XPLAN.BUILD_PLAN_XML <ul><li>dbms_xplan.build_plan_xml( </li></ul><ul><li>table_name IN VARCHAR2 DEFAULT 'PLAN_TABLE', </li></ul><ul><li>statement_id IN VARCHAR2 DEFAULT NULL, </li></ul><ul><li>plan_id IN NUMBER DEFAULT NULL, </li></ul><ul><li>format IN VARCHAR2 DEFAULT 'TYPICAL', </li></ul><ul><li>filter_preds IN VARCHAR2 DEFAULT NULL, </li></ul><ul><li>plan_tag IN VARCHAR2 DEFAULT 'plan', </li></ul><ul><li>report_ref IN VARCHAR2 DEFAULT NULL) </li></ul>
  36. 36. Example Output <ul><li>EXPLAIN PLAN </li></ul><ul><li>SET STATEMENT_ID = 'abc' </li></ul><ul><li>FOR </li></ul><ul><li>select object_type, count(1) </li></ul><ul><li>from dba_objects </li></ul><ul><li>where owner= 'SCOTT' </li></ul><ul><li>group by object_type; </li></ul><ul><li>The SQL Statement </li></ul><ul><li>SELECT dbms_xplan.build_plan_xml(statement_id => 'abc') AS XPLAN FROM dual; </li></ul><ul><li>accomplishes this . </li></ul>
  37. 37. Still the good stuff…
  38. 38. Access Predicates / Filter Predicates
  39. 39. Access and Filter Predicates <ul><li>select attribute1 </li></ul><ul><li>from bom </li></ul><ul><li>where item_id=11 </li></ul><ul><li>and org_id=2 </li></ul><ul><li>and designator is null; </li></ul><ul><li>The Explain plan shows </li></ul><ul><li>-------------------------------------------------------------------------------------- </li></ul><ul><li>| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | </li></ul><ul><li>-------------------------------------------------------------------------------------- </li></ul><ul><li>| 0 | SELECT STATEMENT | | 196 | 10584 | 142 (1)| 00:00:02 | </li></ul><ul><li>|* 1 | TABLE ACCESS BY INDEX ROWID| BOM | 196 | 10584 | 142 (1)| 00:00:02 | </li></ul><ul><li>|* 2 | INDEX RANGE SCAN | BOM_N1 | 11961 | | 31 (0)| 00:00:01 | </li></ul><ul><li>-------------------------------------------------------------------------------------- </li></ul><ul><li>Predicate Information (identified by operation id): </li></ul><ul><li>--------------------------------------------------- </li></ul><ul><li>1 - filter(&quot;DESIGNATOR&quot; IS NULL) </li></ul><ul><li>2 - access(&quot;ITEM_ID&quot;=11 AND &quot;ORG_ID&quot;=2) </li></ul><ul><li>The Stat Lines Show </li></ul><ul><li>STAT #4 id=1 cnt=4889 pid=0 pos=1 obj=70702 op='TABLE ACCESS BY INDEX ROWID BOM (cr=787 pr=150 pw=0 time=194697 us)' </li></ul><ul><li>STAT #4 id=2 cnt=11961 pid=1 pos=1 obj=70704 op='INDEX RANGE SCAN BOM_N1 (cr=357 pr=37 pw=0 time=91948 us)' </li></ul>
  40. 40. Access and Filter Predicates <ul><li>select attribute1 </li></ul><ul><li>from bom where </li></ul><ul><li>item_id=11 </li></ul><ul><li>and org_id=2 </li></ul><ul><li>and designator is null </li></ul><ul><li>-------------------------------------------------------------------------------------- </li></ul><ul><li>| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | </li></ul><ul><li>-------------------------------------------------------------------------------------- </li></ul><ul><li>| 0 | SELECT STATEMENT | | 196 | 10584 | 4 (0)| 00:00:01 | </li></ul><ul><li>| 1 | TABLE ACCESS BY INDEX ROWID| BOM | 196 | 10584 | 4 (0)| 00:00:01 | </li></ul><ul><li>|* 2 | INDEX RANGE SCAN | BOM_U1 | 1 | | 3 (0)| 00:00:01 | </li></ul><ul><li>-------------------------------------------------------------------------------------- </li></ul><ul><li>Predicate Information (identified by operation id): </li></ul><ul><li>--------------------------------------------------- </li></ul><ul><li>2 - access(&quot;ITEM_ID&quot;=11 AND &quot;ORG_ID&quot;=2 AND &quot;DESIGNATOR&quot; IS NULL) </li></ul><ul><li>STAT Lines </li></ul><ul><li>STAT #12 id=1 cnt=4889 pid=0 pos=1 obj=70702 op='TABLE ACCESS BY INDEX ROWID BOM (cr=713 pr=0 pw=0 time=50184 us)' </li></ul><ul><li>STAT #12 id=2 cnt=4889 pid=1 pos=1 obj=72016 op='INDEX RANGE SCAN BOM_U1 (cr=339 pr=0 pw=0 time=19590 us)' </li></ul>
  41. 41. Takeaway <ul><li>Look for row source operation that are filtering a lot of rows </li></ul><ul><li>When a row source operation is filtering a lot of rows, it is accessing those rows and then applying the filter to discard rows that do not match the predicate qualifier </li></ul><ul><li>Evaluate indexes to access the data and not filter it </li></ul>
  42. 42. Query Blocks
  43. 43. Query Blocks <ul><li>Useful when trouble shooting </li></ul><ul><ul><li>Nested SQL Statements </li></ul></ul><ul><ul><li>Complex SQL Statements </li></ul></ul><ul><ul><li>Inline Views </li></ul></ul><ul><ul><li>Sub-Queries </li></ul></ul><ul><ul><li>Repeated Visits to Table </li></ul></ul><ul><li>10g allows you to name Query Blocks </li></ul><ul><ul><li>QB_NAME Hint </li></ul></ul><ul><ul><ul><li>e.g. /*+ QB_NAME(dept_subquery) */ </li></ul></ul></ul><ul><ul><li>When people write complex SQL statements, require them to name Query Blocks </li></ul></ul><ul><li>Query Blocks </li></ul><ul><ul><li>Add clarity to execution and explain plans </li></ul></ul>
  44. 44. Example <ul><li>SELECT /*+ QB_NAME(outer) */ </li></ul><ul><li>e.ename </li></ul><ul><li>, e.sal </li></ul><ul><li>FROM ( </li></ul><ul><li>SELECT /*+ QB_NAME(inline_view) */ </li></ul><ul><li>* </li></ul><ul><li>FROM emp e </li></ul><ul><li>WHERE e.sal > 300 </li></ul><ul><li>AND e.deptno IN ( SELECT /*+ QB_NAME(dept_subquery) */ d.deptno </li></ul><ul><li>FROM dept d </li></ul><ul><li>WHERE d.dname IN ('SALES','ACCOUNTING') </li></ul><ul><li>) </li></ul><ul><li>) e; </li></ul>
  45. 45. Query Block with DBMS_XPLAN <ul><li>SQL> SELECT plan_table_output </li></ul><ul><li>2 FROM TABLE(DBMS_XPLAN.DISPLAY('PLAN_TABLE','qb_name','ALL')); </li></ul><ul><li>PLAN_TABLE_OUTPUT </li></ul><ul><li>----------------------------------------------------------------------------------------- </li></ul><ul><li>Plan hash value: 844388907 </li></ul><ul><li>---------------------------------------------------------------------------------------- </li></ul><ul><li>| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | </li></ul><ul><li>---------------------------------------------------------------------------------------- </li></ul><ul><li>| 0 | SELECT STATEMENT | | 7 | 182 | 6 (17)| 00:00:01 | </li></ul><ul><li>| 1 | MERGE JOIN | | 7 | 182 | 6 (17)| 00:00:01 | </li></ul><ul><li>|* 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 2 | 26 | 2 (0)| 00:00:01 | </li></ul><ul><li>| 3 | INDEX FULL SCAN | PK_DEPT | 4 | | 1 (0)| 00:00:01 | </li></ul><ul><li>|* 4 | SORT JOIN | | 14 | 182 | 4 (25)| 00:00:01 | </li></ul><ul><li>|* 5 | TABLE ACCESS FULL | EMP | 14 | 182 | 3 (0)| 00:00:01 | </li></ul><ul><li>---------------------------------------------------------------------------------------- </li></ul><ul><li>Query Block Name / Object Alias (identified by operation id): </li></ul><ul><li>------------------------------------------------------------- </li></ul><ul><li>1 - SEL$B9DAFA34 </li></ul><ul><li>2 - SEL$B9DAFA34 / D@DEPT_SUBQUERY </li></ul><ul><li>3 - SEL$B9DAFA34 / D@DEPT_SUBQUERY </li></ul><ul><li>5 - SEL$B9DAFA34 / E@INLINE_VIEW </li></ul>
  46. 46. DBMS_XPLAN.DISPLAY_AWR
  47. 47. DBMS_XPLAN.DISPLAY_AWR <ul><li>DBMS_XPLAN.DISPLAY_AWR takes in four arguments. </li></ul><ul><li>SQL_ID  The SQL_ID of the statement in AWR </li></ul><ul><li>PLAN_HASH_VALUE  The Plan Hash value if available </li></ul><ul><li>DB_ID  The Database Id </li></ul><ul><li>FORMAT  Format Options. </li></ul>
  48. 48. Need Data From… <ul><li>dba_hist_sql_plan </li></ul><ul><li>dba_hist_sqltext </li></ul><ul><li>v_$database </li></ul><ul><li>SELECT * FROM TABLE </li></ul><ul><li>(dbms_xplan.display_awr('24033vh7b098h')); </li></ul>
  49. 49. DBMS_XPLAN.DISPLAY_SQLSET
  50. 50. DBMS_XPLAN.DISPLAY_SQLSET <ul><li>FUNCTION DISPLAY_SQLSET RETURNS DBMS_XPLAN_TYPE_TABLE </li></ul><ul><li>Argument Name Type In/Out Default? </li></ul><ul><li>------------------------------ ----------------------- ------ -------- </li></ul><ul><li>SQLSET_NAME VARCHAR2 IN </li></ul><ul><li>SQL_ID VARCHAR2 IN </li></ul><ul><li>PLAN_HASH_VALUE NUMBER(38) IN DEFAULT </li></ul><ul><li>FORMAT VARCHAR2 IN DEFAULT </li></ul><ul><li>SQLSET_OWNER VARCHAR2 IN DEFAULT </li></ul><ul><li>Need to license </li></ul><ul><li>Diagnostic Pack </li></ul><ul><li>Tuning Pack </li></ul>
  51. 51. DBMS_XPLAN.DISPLAY_SQLSET <ul><li>For example, a SQL Tuning set named ‘MY_TUNING_SET’ for the sql statement with the sql_id 'g1pz63cqh5qbf', the following will displays all the execution plans. </li></ul><ul><li>An example: </li></ul><ul><li>SELECT * FROM table (DBMS_XPLAN.DISPLAY_SQLSET('MY_TUNING_SET,'g1pz63cqh5qbf')); </li></ul>
  52. 52. DBMS_XPLAN.DISPLAY_CURSOR
  53. 53. DBMS_XPLAN.DISPLAY_CURSOR <ul><li>FUNCTION DISPLAY_CURSOR RETURNS DBMS_XPLAN_TYPE_TABLE </li></ul><ul><li>Argument Name Type In/Out Default? </li></ul><ul><li>----------------- ------------- ------ -------- </li></ul><ul><li>SQL_ID VARCHAR2 IN DEFAULT </li></ul><ul><li>CURSOR_CHILD_NO NUMBER(38) IN DEFAULT </li></ul><ul><li>FORMAT VARCHAR2 IN DEFAULT </li></ul><ul><li>SQL_ID  SQL_ID From V$SQL </li></ul><ul><li>CURSOR_CHILD_NO  CHILD_NUMBER in V$SQL </li></ul>
  54. 54. Obtaining SQL_ID and Cursor Child Num. <ul><li>SELECT sql_id, </li></ul><ul><li>child_number, </li></ul><ul><li>sql_text </li></ul><ul><li>FROM </li></ul><ul><li>v$sql </li></ul><ul><li>WHERE </li></ul><ul><li>LOWER(sql_text) LIKE </li></ul><ul><li>‘ <begin sql statement string>%' </li></ul>
  55. 55. FORMAT <ul><li>BASIC, TYPICAL, SERIAL, ALL </li></ul><ul><ul><li>To view the execution plans alone </li></ul></ul><ul><li>Viewing Stats about the plan </li></ul><ul><ul><li>Introduced in 10g R1 </li></ul></ul><ul><ul><li>Enhanced in 10g R2 </li></ul></ul><ul><ul><li>Set STATISTICS_LEVEL=ALL at the session level </li></ul></ul><ul><ul><ul><li>OR </li></ul></ul></ul><ul><ul><li>Set the GATHER_PLAN_STATISTICS hint </li></ul></ul>
  56. 56. Viewing the execution plan in V$SQL <ul><li>SELECT plan_table_output </li></ul><ul><li>FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('3a3dz5yva4vnf',0,'ALL')); </li></ul>
  57. 57. Viewing the Run Time Stats of the Execution Plan <ul><li>SELECT plan_table_output </li></ul><ul><li>FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('3a3dz5yva4vnf',0,‘<Various Options>')); </li></ul><ul><li>IOSTATS </li></ul><ul><li>MEMSTATS </li></ul><ul><li>ALLSTATS </li></ul><ul><li>IOSTATS LAST </li></ul><ul><li>MEMSTATS LAST </li></ul><ul><li>ALLSTATS LAST </li></ul>
  58. 58. Demo <ul><li>Demo.sql </li></ul>
  59. 59. Q & Q U E S T I O N S A N S W E R S

×