set au..."/>
溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時間:2020-08-11 04:31:12 來源:ITPUB博客 閱讀:122 作者:banana_62 欄目:關(guān)系型數(shù)據(jù)庫
set autotrace off
不產(chǎn)生autotrace報告,默認(rèn)值
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í)行計(jì)劃
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)計(jì)信息(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)計(jì)信息
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)計(jì)信息
SQL> set autotrace on;
SQL> insert into scott.emp  values('8899','on','','','','','','');

1 row created.

—相當(dāng)于set autotrace on explain和set autotrace on statistics的和,既輸出執(zhí)行計(jì)劃,也輸出統(tǒng)計(jì)信息,同時也執(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í)行計(jì)劃和統(tǒng)計(jì)信息
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> 


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI