Oracle檢視執行計劃(三)
如果某條SQL已經執行過了,且其執行計劃還在記憶體中,則後續可以使用dbms.xplan.display_cursor來檢視。
語法:
select * from table(dbms_xplan.display_cursor('sql_id/hash_values',child_cursor_number,'advanced'));
SQL> select employee_id,last_name,salary from employees where employee_id=100;
EMPLOYEE_ID LAST_NAME SALARY
----------- ------------------------- ----------
100 King 24000
直接檢視剛剛執行過的SQL的執行計劃:
SQL> select * from table(dbms_xplan.display_cursor(null,null,'advanced'));
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID ftsw1cm8qh6nq, child number 0
-------------------------------------
select employee_id,last_name,salary from employees where employee_id=100
Plan hash value: 1833546154
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 1 (100)| |
| 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)| |
---------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / EMPLOYEES@SEL$1
2 - SEL$1 / EMPLOYEES@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
DB_VERSION('11.2.0.4')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
INDEX_RS_ASC(@"SEL$1" "EMPLOYEES"@"SEL$1" ("EMPLOYEES"."EMPLOYEE_ID"))
END_OUTLINE_DATA
*/
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EMPLOYEE_ID"=100)
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - "EMPLOYEE_ID"[NUMBER,22], "LAST_NAME"[VARCHAR2,25], "SALARY"[NUMBER,22]
2 - "EMPLOYEES".ROWID[ROWID,10], "EMPLOYEE_ID"[NUMBER,22]
45 rows selected.
如果SQL已經執行過了,則需要透過先查詢V$SQL,找到該SQL的SQL_ID再來檢視執行計劃。
SQL> select sql_text,sql_id from v$sql where sql_text like 'select employee_id,last_name%';
SQL_TEXT SQL_ID
-------------------------------------------------------------------------------- -------------
select employee_id,last_name,salary from employees where employee_id=100 ftsw1cm8qh6nq
SQL> select * from table(dbms_xplan.display_cursor('ftsw1cm8qh6nq',0,'advanced'));
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID ftsw1cm8qh6nq, child number 0
-------------------------------------
select employee_id,last_name,salary from employees where employee_id=100
Plan hash value: 1833546154
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 1 (100)| |
| 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)| |
---------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / EMPLOYEES@SEL$1
2 - SEL$1 / EMPLOYEES@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
DB_VERSION('11.2.0.4')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
INDEX_RS_ASC(@"SEL$1" "EMPLOYEES"@"SEL$1" ("EMPLOYEES"."EMPLOYEE_ID"))
END_OUTLINE_DATA
*/
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EMPLOYEE_ID"=100)
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - "EMPLOYEE_ID"[NUMBER,22], "LAST_NAME"[VARCHAR2,25], "SALARY"[NUMBER,22]
2 - "EMPLOYEES".ROWID[ROWID,10], "EMPLOYEE_ID"[NUMBER,22]
45 rows selected.
如果目標SQL有多個執行計劃,需要檢視某個執行計劃,只需要指定目標SQL的child_cursor_number就可以了。
SQL> conn sh/sh
Connected.
SQL> create table employees as select * from hr.employees;
Table created.
SQL> select employee_id,last_name,salary from employees where employee_id=100;
EMPLOYEE_ID LAST_NAME SALARY
----------- ------------------------- ----------
100 King 24000
SQL> conn hr/hr
Connected.
SQL> select sql_text,sql_id,child_number from v$sql where sql_text like 'select employee_id,last_name%';
SQL_TEXT SQL_ID CHILD_NUMBER
-------------------------------------------------------------------------------- ------------- ------------
select employee_id,last_name,salary from employees where employee_id=100 ftsw1cm8qh6nq 0
select employee_id,last_name,salary from employees where employee_id=100 ftsw1cm8qh6nq 1
SQL> select * from table(dbms_xplan.display_cursor('ftsw1cm8qh6nq',1,'advanced'));
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID ftsw1cm8qh6nq, child number 1
-------------------------------------
select employee_id,last_name,salary from employees where employee_id=100
Plan hash value: 1445457117
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 3 (100)| |
|* 1 | TABLE ACCESS FULL| EMPLOYEES | 1 | 40 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / EMPLOYEES@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
DB_VERSION('11.2.0.4')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "EMPLOYEES"@"SEL$1")
END_OUTLINE_DATA
*/
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("EMPLOYEE_ID"=100)
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - "EMPLOYEE_ID"[NUMBER,22], "LAST_NAME"[VARCHAR2,25],
"SALARY"[NUMBER,22]
Note
-----
- dynamic sampling used for this statement (level=2)
47 rows selected.
當然也可以不指定child_cursor_number,獲取所有版本的執行計劃。
SQL> select * from table(dbms_xplan.display_cursor('ftsw1cm8qh6nq',null,'advanced'));
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID ftsw1cm8qh6nq, child number 0
-------------------------------------
select employee_id,last_name,salary from employees where employee_id=100
Plan hash value: 1833546154
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 1 (100)| |
| 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)| |
---------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / EMPLOYEES@SEL$1
2 - SEL$1 / EMPLOYEES@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
DB_VERSION('11.2.0.4')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
INDEX_RS_ASC(@"SEL$1" "EMPLOYEES"@"SEL$1" ("EMPLOYEES"."EMPLOYEE_ID"))
END_OUTLINE_DATA
*/
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EMPLOYEE_ID"=100)
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - "EMPLOYEE_ID"[NUMBER,22], "LAST_NAME"[VARCHAR2,25], "SALARY"[NUMBER,22]
2 - "EMPLOYEES".ROWID[ROWID,10], "EMPLOYEE_ID"[NUMBER,22]
SQL_ID ftsw1cm8qh6nq, child number 1
-------------------------------------
select employee_id,last_name,salary from employees where employee_id=100
Plan hash value: 1445457117
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 3 (100)| |
|* 1 | TABLE ACCESS FULL| EMPLOYEES | 1 | 40 | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / EMPLOYEES@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
DB_VERSION('11.2.0.4')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "EMPLOYEES"@"SEL$1")
END_OUTLINE_DATA
*/
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("EMPLOYEE_ID"=100)
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - "EMPLOYEE_ID"[NUMBER,22], "LAST_NAME"[VARCHAR2,25],
"SALARY"[NUMBER,22]
Note
-----
- dynamic sampling used for this statement (level=2)
92 rows selected.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28536251/viewspace-2139242/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle檢視執行計劃(五)Oracle
- Oracle檢視執行計劃(六)Oracle
- Oracle檢視執行計劃(一)Oracle
- Oracle檢視執行計劃(二)Oracle
- Oracle檢視執行計劃(四)Oracle
- ORACLE執行計劃的檢視Oracle
- oracle如何檢視執行計劃Oracle
- 檢視oracle執行計劃 - 轉Oracle
- Oracle檢視執行計劃的命令Oracle
- oracle檢視執行計劃的方法Oracle
- Oracle 檢視SQL的執行計劃OracleSQL
- Oracle檢視執行計劃常用方法Oracle
- 檢視執行計劃
- ORACLE資料庫檢視執行計劃Oracle資料庫
- 檢視ORACLE的實際執行計劃Oracle
- 檢視執行計劃(一)
- 檢視執行計劃(二)
- 檢視sql執行計劃SQL
- Oracle檢視正在執行的SQL以及執行計劃分析OracleSQL
- 多種方法檢視Oracle SQL執行計劃OracleSQL
- oracle10g 檢視SQL執行計劃OracleSQL
- Oracle如何檢視真實執行計劃(一)Oracle
- 檢視歷史執行計劃
- 檢視執行計劃的方法
- 檢視 OceanBase 執行計劃
- 檢視Oracle SQL執行計劃方法比較、分析OracleSQL
- oracle dbms_xplan.display_cursor檢視執行計劃Oracle
- SQLPLUS檢視oracle sql執行計劃命令SQLOracle
- 使用10046事件檢視oracle執行計劃事件Oracle
- Oracle檢視sql_id 的歷史執行計劃OracleSQL
- Oracle 9i 開啟autotrace on 檢視執行計劃Oracle
- 如何檢視SQL的執行計劃SQL
- DBMS_XPLAN檢視執行計劃
- 檢視SQL的執行計劃方法SQL
- 使用PL/SQL檢視執行計劃SQL
- db2檢視執行計劃DB2
- 檢視sql執行計劃--set autotraceSQL
- TOAD檢視執行計劃表