使用autotrace查看执行计划

发布时间:2020-08-11 04:31:12 作者:banana_62
来源:ITPUB博客 阅读:122
set autotrace off
不产生autotrace报告,默认值
set autotrace on explain
autotrace报告只展示最优的执行方式(optimizer execution path)
SQL> set autotrace on explain;
—插入数据测试是否执行了sql
SQL> insert into scott.emp values('5566','explain','','','','','','');

1 row created.
—已经表明执行了sql
—只展示了执行计划
Execution Plan
----------------------------------------------------------
---------------------------------------------------------------------------------
| Id  | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
|   0 | INSERT STATEMENT | |     1 |   100 |     1   (0)| ss00:00:01 |
|   1 |  LOAD TABLE CONVENTIONAL | EMP | | |     | |
---------------------------------------------------------------------------------

SQL> select * from scott.emp where empno=5566;
     EMPNO ENAME      JOB       MGR HIREDATE    SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      5566 explain

Execution Plan
----------------------------------------------------------
Plan hash value: 2949544139
--------------------------------------------------------------------------------------
| Id  | Operation    | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |     |   1 |  87 |   2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |   1 |  87 |   2   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN    | PK_EMP |   1 |     |   1   (0)| 00:00:01 |
--------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   2 - access("EMPNO"=5566)

set autotrace on statistics
autotrace报告sql执行统计信息(SQL  statement execution statistics. )
SQL> set autotrace on statistics;
SQL> insert into scott.emp values('6677','statistics','','','','','','');

1 row created.
—说明执行了sql
—只展示sql执行的统计信息
Statistics
----------------------------------------------------------
52  recursive calls
 5  db block gets
80  consistent gets
 0  physical reads
520  redo size
839  bytes sent via SQL*Net to client
826  bytes received via SQL*Net from client
 3  SQL*Net roundtrips to/from client
10  sorts (memory)
 0  sorts (disk)
 1  rows processed

SQL> select * from scott.emp where empno=6677;
     EMPNO ENAME      JOB       MGR HIREDATE    SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      6677 statistics

Statistics
----------------------------------------------------------
 1  recursive calls
 0  db block gets
 2  consistent gets
 0  physical reads
 0  redo size
869  bytes sent via SQL*Net to client
512  bytes received via SQL*Net from client
 1  SQL*Net roundtrips to/from client
 0  sorts (memory)
 0  sorts (disk)
 1  rows processed
set autotrace on
autotrace报告包含了最优执行方式和sql执行统计信息
SQL> set autotrace on;
SQL> insert into scott.emp  values('8899','on','','','','','','');

1 row created.

—相当于set autotrace on explain和set autotrace on statistics的和,既输出执行计划,也输出统计信息,同时也执行sql
Execution Plan
----------------------------------------------------------

---------------------------------------------------------------------------------
| Id  | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
|   0 | INSERT STATEMENT | |     1 |   100 |     1   (0)| 00:00:01 |
|   1 |  LOAD TABLE CONVENTIONAL | EMP | | |     | |
---------------------------------------------------------------------------------

Statistics
----------------------------------------------------------
45  recursive calls
 5  db block gets
77  consistent gets
 0  physical reads
512  redo size
839  bytes sent via SQL*Net to client
816  bytes received via SQL*Net from client
 3  SQL*Net roundtrips to/from client
10  sorts (memory)
 0  sorts (disk)
 1  rows processed

SQL> select * from scott.emp where empno=8899;
     EMPNO ENAME      JOB       MGR HIREDATE    SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      8899 on

Execution Plan
----------------------------------------------------------
Plan hash value: 2949544139
--------------------------------------------------------------------------------------
| Id  | Operation    | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |     |   1 |  87 |   2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |   1 |  87 |   2   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN    | PK_EMP |   1 |     |   1   (0)| 00:00:01 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   2 - access("EMPNO"=8899)
Statistics
----------------------------------------------------------
 9  recursive calls
 0  db block gets
18  consistent gets
 0  physical reads
 0  redo size
861  bytes sent via SQL*Net to client
512  bytes received via SQL*Net from client
 1  SQL*Net roundtrips to/from client
 0  sorts (memory)
 0  sorts (disk)
 1  rows processed
set autotrace traceonly
和set autotrace on类似,但是不输出用户查询的结果
SQL> set autotrace traceonly;
SQL> insert into scott.emp values('9900','traceonly','','','','','','');
1 row created.
—与set autotrace on 类似,都会输出执行计划和统计信息
Execution Plan
----------------------------------------------------------
---------------------------------------------------------------------------------
| Id  | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
|   0 | INSERT STATEMENT | |     1 |   100 |     1   (0)| 00:00:01 |
|   1 |  LOAD TABLE CONVENTIONAL | EMP | | |     | |
---------------------------------------------------------------------------------

Statistics
----------------------------------------------------------
108  recursive calls
 5  db block gets
191  consistent gets
 1  physical reads
520  redo size
839  bytes sent via SQL*Net to client
825  bytes received via SQL*Net from client
 3  SQL*Net roundtrips to/from client
15  sorts (memory)
 0  sorts (disk)
 1  rows processed

SQL> select * from scott.emp where empno=9900;
—与set autotrace on不同的是,没有输出查询结果
Execution Plan
----------------------------------------------------------
Plan hash value: 2949544139
--------------------------------------------------------------------------------------
| Id  | Operation    | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |     |   1 |  87 |   2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |   1 |  87 |   2   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN    | PK_EMP |   1 |     |   1   (0)| 00:00:01 |
--------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------
   2 - access("EMPNO"=9900)
Statistics
----------------------------------------------------------
 9  recursive calls
 0  db block gets
18  consistent gets
 0  physical reads
 0  redo size
867  bytes sent via SQL*Net to client
512  bytes received via SQL*Net from client
 1  SQL*Net roundtrips to/from client
 0  sorts (memory)
 0  sorts (disk)
 1  rows processed

SQL> 


推荐阅读:
  1. Oracle 查看执行计划问题
  2. oracle查看执行计划

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

autotrace 使用 查看

上一篇:在 SSH 中使用 RSA 和 DSA 认证(详解)

下一篇:[JIRA]Linux版本jira6.3.6安装汉化破解以及数据迁移

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》