您的位置:首页 > 数据库 > Oracle

获得执行计划方法-一 ORACLE AUTOTRACE

2014-06-27 15:50 423 查看
ORACLE sql trace

AUTOTRACE 命令

1 SET AUTOTRACE OFF 此为默认值,即关闭Autotrace
2 SET AUTOTRACE ON 产生结果集和解释计划并列出统计
3 SET AUTOTRACE ON EXPLAIN 显示结果集和解释计划不显示统计
4 SETAUTOTRACE TRACEONLY 显示解释计划和统计,尽管执行该语句但您将看不到结果集
5 SET AUTOTRACE TRACEONLY STATISTICS 只显示统计

SQL> set autotrace on
SQL> select * from dual
2 ;

D
-
X

Execution Plan
----------------------------------------------------------
Plan hash value: 272002086

--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| DUAL | 1 | 2 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------

Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
407 bytes sent via SQL*Net to client
385 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed

各统计信息含义
db block gets 从buffer cache中读取的block的数量
consistent gets 从buffer cache中读取的undo数据的block的数量
physical reads 从磁盘读取的block的数量
redo size DML生成的redo的大小
sorts (memory) 在内存执行的排序量
sorts (disk) 在磁盘上执行的排序量

db block gets 是取得current mode下的buffer cache
consistent gets 取的是consistent mode 下buffer cache ,其中consistent read 需要undo block 构造一致读块

官方文档如下

Current mode
A current mode get, also called a db block get, is a retrieval of a block as it currently appears in the buffer cache.
current mode 也叫 db block get ,是对buffer cache 中当前块的检索。
For example, if an uncommitted transaction has updated two rows in
a block, then a current mode get retrieves the block with these
uncommitted rows.
例如,如果一个尚未提交的事物修改了一个块的两行,current模式个检索块时,包括两个尚未提交的行
The database uses db block gets most frequently during modification
statements, which must update only the current version of the block.
数据库通常在使用修改语句时 使用db block get ,哪个必须修改当前块的版本。

Consistent mode
A consistent read get is a retrieval of a read-consistent version of a block. This retrieval may use undo data.
一致读读取的是块的一致性版本,这通常要使用undo 块。

For example, if an uncommitted transaction has updated two rows in
a block, and if a query in a separate session requests the block,
例如 一个未提交事物修改了一个块的两行,另一个session查询这个块
then the database uses undo data to create a read-consistent
version of this block (called a consistent read clone) that does not
include the uncommitted updates.
数据库使用undo,创建一个一致读版本的块(被称为一致读的块克隆),不包含未提交的update。
Typically, a query retrieves blocks in consistent mode.
典型的,查询在一致读模式下进行检索

本文出自 “道行尚浅(老道)的空间” 博客,请务必保留此出处http://daoye.blog.51cto.com/4190423/1431647
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: