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语句的执行计划将被返回
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 PROJECTION
, ALIAS
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 (PROJECTION
, ALIAS
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.