Oracle檢視執行計劃(二)

stonebox1122發表於2017-05-16

如果使用sqlplus,可以使用set autotrace命令來得到後續執行sql的執行計劃。
語法如下:
SET AUTOT[RACE] {OFF|ON|TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]    

SQL> set autotrace traceonly
--以上表示只生成執行計劃,不將SQL結果顯示出來。
SQL> select employee_id,last_name,salary from employees where employee_id=100;


Execution Plan
----------------------------------------------------------
Plan hash value: 1833546154

---------------------------------------------------------------------------------------------
| Id  | Operation                   | Name          | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |               |     1 |    16 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| EMPLOYEES     |     1 |    16 |     1   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN         | EMP_EMP_ID_PK |     1 |       |     0   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("EMPLOYEE_ID"=100)


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

可以看到使用這種方式還可以得到sql執行所耗費的物理讀、邏輯讀等統計資訊。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28536251/viewspace-2139181/,如需轉載,請註明出處,否則將追究法律責任。

相關文章