display_cursor函数显示当前会话最后一条SQL语句的执行计划
2013-09-30 16:47
423 查看
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
PROJECTION,
ALIASand
REMOTE
SQLinformation
(see below).
SERIAL: Like
TYPICALexcept that the parallel information is not displayed, even if the plan executes in parallel.
ALL: Maximum user level. Includes information displayed with the
TYPICALlevel with additional information (
PROJECTION,
ALIASand
information about
REMOTE
SQLif 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_statisticshint
or by setting the parameter statistics_level to ALL), this format shows IO statistics for
ALL(or only for the
LASTas shown below) executions of the cursor.
MEMSTATS- Assuming that PGA memory management is enabled (that is,
pga_aggregate_targetparameter 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
LASTcan 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.
相关文章推荐
- dbms_xplan.display_cursor 查看已执行SQL的执行计划(10g后)
- 使用Oracle自带的系统包和过程监控其它会话SQL语句的执行计划等信息
- 获取隐含参数, 当前trace文件名称,sql语句的执行计划的脚本
- 巧用DISPLAY_AWR函数与dba_hist_sqlstat结合查询SQL语句在指定节点指定时间范围内的历史执行计划
- dbms_xplan.display_cursor 获取执行过的sql的执行计划
- dbms_xplan.display_cursor 获取执行过的sql的执行计划
- 巧用DISPLAY_AWR函数与dba_hist_sqlstat结合查询SQL语句在指定节点指定时间范围内的历史执行计划
- Thinkphp5中执行最后一条SQL语句
- 一条SQL 语句执行后返回2笔受影响--如果没有触发器,那就是点到"包括实际的执行计划"!
- SQL Server 第四堂课,创建存储过程。存储过程是一组编译在单个执行计划中的transact-SQL语句。存储过程相当于C#函数,可以允许模块化程序设计,允许更快执行如果某操作需要大量transct-SQL代码或需要重复执行,将在创建存储过程中对其进行分析和优化。
- 一次数据库不繁忙时一条sql语句2个执行计划导致业务超时的故障处理
- 查看PostgreSQL数据库中SQL语句的执行计划
- 查看sql当前的执行计划
- 一条sql,在我机器上执行700多秒,最后优化成3秒多
- 根据当前记录获取前一条与下一条记录常用 sql语句
- 利用pl/sql执行计划评估SQL语句的性能简析
- 使用mysql profiles 来查看sql 语句执行计划
- sqlplus中显示sql执行计划和统计信息
- mysql怎么终止当前正在执行的sql语句
- 用编程的方式将当前服务器上SQL SERVER中正执行的所有T-SQL语句记录下来 <转>