【最佳化】explain plan for 方式存取執行計劃
如果要分析某條SQL的效能問題,通常我們要先看SQL的執行計劃,看看SQL的每一步執行是否存在問題。 如果一條SQL平時執行的好好的,卻有一天突然效能很差,如果排除了系統資源和阻塞的原因,那麼基本可以斷定是執行計劃出了問題。
explain plan for 方式存取sql的執行計劃檢視的只是最近的Plan table中的資訊
實驗:
1.以explain plan for 的方式進行操作存入sql執行計劃;
SYS@ORA11GR2>conn hr/hr
Connected.
HR@ORA11GR2>explain plan for select count(*) from employees;
Explained.
2.檢視dbms_xplan包
SYS@ORA11GR2>desc dbms_xplan
3.以basic模式檢視執行計劃:
HR@ORA11GR2>select * from table(dbms_xplan.display(null,null,'basic'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3580537945
-----------------------------------------
| Id | Operation | Name |
-----------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT AGGREGATE | |
| 2 | INDEX FULL SCAN| EMP_EMAIL_UK |
-----------------------------------------
9 rows selected.
4.以typical模式檢視執行計劃:(預設是typical)
HR@ORA11GR2>select * from table(dbms_xplan.display(null,null,'typical'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3580537945
-------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FULL SCAN| EMP_EMAIL_UK | 107 | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------
9 rows selected
5. 以serial模式檢視執行計劃:
HR@ORA11GR2>select * from table(dbms_xplan.display(null,null,'serial'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3580537945
-------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FULL SCAN| EMP_EMAIL_UK | 107 | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------
9 rows selected.
6. 以all模式檢視執行計劃:
HR@ORA11GR2>select * from table(dbms_xplan.display(null,null,'all'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3580537945
-------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FULL SCAN| EMP_EMAIL_UK | 107 | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / EMPLOYEES@SEL$1
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - (#keys=0) COUNT(*)[22]
20 rows selected.
7. 以advanced模式檢視執行計劃:
HR@ORA11GR2>select * from table(dbms_xplan.display(null,null,'advanced'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 3580537945
-------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FULL SCAN| EMP_EMAIL_UK | 107 | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
-------------------------------------------------------------
1 - SEL$1
2 - SEL$1 / EMPLOYEES@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
INDEX(@"SEL$1" "EMPLOYEES"@"SEL$1" ("EMPLOYEES"."EMAIL"))
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
OUTLINE_LEAF(@"SEL$1")
ALL_ROWS
DB_VERSION('11.2.0.4')
OPTIMIZER_FEATURES_ENABLE('11.2.0.4')
IGNORE_OPTIM_EMBEDDED_HINTS
END_OUTLINE_DATA
*/
Column Projection Information (identified by operation id):
-----------------------------------------------------------
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
1 - (#keys=0) COUNT(*)[22]
34 rows selected.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31397003/viewspace-2126497/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle執行計劃Explain Plan 如何使用OracleAI
- Oracle 執行計劃(Explain Plan) 說明OracleAI
- Oracle 執行計劃(Explain Plan) 說明OracleAI
- 使用EXPLAIN PLAN來檢視執行計劃AI
- TOAD中檢視執行計劃(Explain Plan)AI
- 配置oracle 解釋執行計劃--explain planOracleAI
- 【Explain Plan】檢視SQL的執行計劃AISQL
- autotrace 和explain plan for可能導致執行計劃錯誤AI
- oracle explain plan for獲取執行計劃並不可靠.OracleAI
- 檢視執行計劃方法總結之一:explain plan命令AI
- 【執行計劃】格式化EXPLAIN PLAN的輸出結果AI
- 資料庫執行計劃和資料存取方式資料庫
- explain執行計劃分析AI
- mysql執行計劃explainMySqlAI
- mysql explain 執行計劃MySqlAI
- 使用 EXPLAIN PLAN 獲取SQL語句執行計劃 (R0.1)AISQL
- Explain執行計劃詳解AI
- explain 查詢執行計劃AI
- MySQL Explain執行計劃 - 詳解MySqlAI
- 十六、Mysql之Explain執行計劃MySqlAI
- mysql explain 執行計劃詳解MySqlAI
- MySQL執行計劃EXPLAIN詳解MySqlAI
- ORACLE執行計劃 explain說明OracleAI
- oracle執行計劃的使用(EXPLAIN)OracleAI
- Oracle的執行計劃及資料存取方式 (ROWID,掃描方式等)Oracle
- mysql調優之——執行計劃explainMySqlAI
- (4) MySQL中EXPLAIN執行計劃分析MySqlAI
- MongoDb學習之Explain執行計劃MongoDBAI
- Explain For理論執行計劃相關AI
- sql中使用函式導致explain plan for和set autotrace得到執行計劃不準確SQL函式AI
- MySQL explain執行計劃詳細解釋MySqlAI
- mysql之 explain、optimizer_trace 執行計劃MySqlAI
- oracle10g_11g_繫結變數bind_與最優執行計劃explain planOracle變數AI
- 分析執行計劃最佳化SQLORACLE的執行計劃(轉)SQLOracle
- Hive底層原理:explain執行計劃詳解HiveAI
- MySQL——通過EXPLAIN分析SQL的執行計劃MySqlAI
- MySQL執行計劃explain輸出列結果解析MySqlAI
- MySQL執行計劃explain的key_len解析MySqlAI