使用autotrace查看執(zhí)行計劃

set autotrace off
不產(chǎn)生autotrace報告,默認值
set autotrace on explain
autotrace報告只展示最優(yōu)的執(zhí)行方式(optimizer execution path)
SQL> set autotrace on explain;
—插入數(shù)據(jù)測試是否執(zhí)行了sql
SQL> insert into scott.emp values('5566','explain','','','','','','');

1 row created.
—已經(jīng)表明執(zhí)行了sql
—只展示了執(zhí)行計劃
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執(zhí)行統(tǒng)計信息(SQL  statement execution statistics. )
SQL> set autotrace on statistics;
SQL> insert into scott.emp values('6677','statistics','','','','','','');

1 row created.
—說明執(zhí)行了sql
—只展示sql執(zhí)行的統(tǒng)計信息
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報告包含了最優(yōu)執(zhí)行方式和sql執(zhí)行統(tǒng)計信息
SQL> set autotrace on;
SQL> insert into scott.emp  values('8899','on','','','','','','');

1 row created.

—相當于set autotrace on explain和set autotrace on statistics的和,既輸出執(zhí)行計劃,也輸出統(tǒng)計信息,同時也執(zhí)行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類似,但是不輸出用戶查詢的結(jié)果
SQL> set autotrace traceonly;
SQL> insert into scott.emp values('9900','traceonly','','','','','','');
1 row created.
—與set autotrace on 類似,都會輸出執(zhí)行計劃和統(tǒng)計信息
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不同的是,沒有輸出查詢結(jié)果
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> 


網(wǎng)頁題目:使用autotrace查看執(zhí)行計劃
鏈接URL:http://muchs.cn/article0/ihsjio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作網(wǎng)站排名、自適應(yīng)網(wǎng)站面包屑導(dǎo)航、動態(tài)網(wǎng)站、企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化