display_cursor函数显示当前会话最后一条SQL语句的执行计划

DBMS_XPLAN.DISPLAY_CURSOR(
   sql_id           IN  VARCHAR2  DEFAULT  NULL,
   cursor_child_no  IN  NUMBER    DEFAULT  0, 
   format           IN  VARCHAR2  DEFAULT  'TYPICAL');
sql_id:  指定位于库缓存执行计划中SQL语句的父游标。默认值为null。当使用默认值时当前会话的最后一条SQL语句的执行计划将被返回
            可以通过查询V$SQL 或V$SQLAREA的SQL_ID列来获得SQL语句的SQL_ID。
child_number : 指定父游标下子游标的序号。即指定被返回执行计划的SQL语句的子游标。默认值为0。如果为null,则sql_id所指父游标下所有子游    标 的执行计划都将被返回。
format:   控制SQL语句执行计划的输出部分,即哪些可以显示哪些不显示。使用与display函数的format参数与修饰符在这里同样适用。
    除此之外当在开启statistics_level=all时或使用gather_plan_statistics提示可以获得执行计划中实时的统计信息
   有关详细的format格式描述请参考:dbms_xplan之display函数的使用 中format参数的描述

Controls the level of details for the plan. It accepts four values:

  • BASIC: Displays the minimum information in the plan—the operation ID, the operation name and its option.

  • TYPICAL: This is the default. Displays the most relevant information in the plan (operation id, name and option, #rows, #bytes and optimizer cost). Pruning, parallel and predicate information are only displayed when applicable. Excludes only PROJECTIONALIAS and REMOTE SQL information (see below).

  • SERIAL: Like TYPICAL except that the parallel information is not displayed, even if the plan executes in parallel.

  • ALL: Maximum user level. Includes information displayed with the TYPICAL level with additional information (PROJECTIONALIAS and information about REMOTE SQL if the operation is distributed).


Format keywords must be separated by either a comma or a space:

  • ROWS - if relevant, shows the number of rows estimated by the optimizer

  • BYTES - if relevant, shows the number of bytes estimated by the optimizer

  • COST - if relevant, shows optimizer cost information

  • PARTITION - if relevant, shows partition pruning information

  • PARALLEL - if relevant, shows PX information (distribution method and table queue information)

  • PREDICATE - if relevant, shows the predicate section

  • PROJECTION -if relevant, shows the projection section

  • ALIAS - if relevant, shows the "Query Block Name / Object Alias" section

  • REMOTE - if relevant, shows the information for distributed query (for example, remote from serial distribution and remote SQL)

  • NOTE - if relevant, shows the note section of the explain plan

  • IOSTATS - assuming that basic plan statistics are collected when SQL statements are executed (either by using the gather_plan_statistics hint or by setting the parameter statistics_level to ALL), this format shows IO statistics for ALL (or only for the LAST as shown below) executions of the cursor.

  • MEMSTATS - Assuming that PGA memory management is enabled (that is, pga_aggregate_target parameter is set to a non 0 value), this format allows to display memory management statistics (for example, execution mode of the operator, how much memory was used, number of bytes spilled to disk, and so on). These statistics only apply to memory intensive operations like hash-joins, sort or some bitmap operators.

  • ALLSTATS - A shortcut for 'IOSTATS MEMSTATS'

  • LAST - By default, plan statistics are shown for all executions of the cursor. The keyword LAST can be specified to see only the statistics for the last execution.

The following two formats are deprecated but supported for backward compatibility:

  • RUNSTATS_TOT - Same as IOSTATS, that is, displays IO statistics for all executions of the specified cursor.

  • RUNSTATS_LAST - Same as IOSTATS LAST, that is, displays the runtime statistics for the last execution of the cursor




不传递任何参数给display_cursor函数,显示当前会话最后一条SQL语句的执行计划

QL> select * From  emp;

SQL> select * from table(dbms_xplan.display_cursor(null,null)); 
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID 1jd3putvkn38k, child number 0
-------------------------------------
select * From  emp

Plan hash value: 3956160932
--------------------------------------------------------------------------
| Id  | Operation  | Name | Rows  | Bytes | Cost (%CPU)| Time|
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  | |||     3 (100)| |
|   1 |  TABLE ACCESS FULL| EMP  |    14 |   532 |     3   (0)| 00:00:01 |

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------
13 rows selected.

SQL> SELECT * FROM table (DBMS_XPLAN.DISPLAY_CURSOR('69511w1wm1v9f', NULL, 'ALLSTATS LAST'));

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID 69511w1wm1v9f, child number 0
-------------------------------------
select * From emp
Plan hash value: 3956160932
-------------------------------------------
| Id  | Operation  | Name | E-Rows |
-------------------------------------------
|   0 | SELECT STATEMENT  | | |
|   1 |  TABLE ACCESS FULL| EMP  |     14 |

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
-------------------------------------------

Note
-----
   - Warning: basic plan statistics not available. 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

SQL> select * from table(dbms_xplan.display_cursor(null,0,'allstats last'));

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID	69511w1wm1v9f, child number 1
-------------------------------------
select * From emp

Plan hash value: 3956160932

------------------------------------------------------------------------------------
| Id  | Operation	  | Name | Starts | E-Rows | A-Rows |	A-Time	 | Buffers |
------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |	 |	1 |	   |	 14 |00:00:00.01 |	 8 |
|   1 |  TABLE ACCESS FULL| EMP  |	1 |	14 |	 14 |00:00:00.01 |	 8 |

PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------

13 rows selected.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值