[20230130]toad看執行計劃注意.txt
[20230130]toad看執行計劃注意.txt
--//同事給我看一條sql語句,說生產系統執行8秒,而在toad執行需要1秒,實際上toad如果快,可能並沒有完成整個結果集合,也就是先
--//fetch 500條.這樣看起來很快,實際上可能執行很慢.
--//做一個例子演示出來.
1.環境:
SCOTT@test01p> @ ver1
PORT_STRING VERSION BANNER CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0 12.2.0.1.0 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
SCOTT@test01p> create table t as select * from all_objects;
Table created.
SCOTT@test01p> @ gts t
Gather Table Statistics for table t...
exec dbms_stats.gather_table_stats(null, upper('t'), null, method_opt=>'FOR TABLE FOR ALL COLUMNS SIZE REPEAT', cascade=>true, no_invalidate=>false)
PL/SQL procedure successfully completed.
2.在toad下執行:
--//先在sqlplus下執行如下,保證執行計劃已經存在共享池子.
alter session set statistics_level = all;
select * from t;
--//然後在toad下執行如下:
alter session set statistics_level = all;
select * from t;
--//然後在toad下檢視真實的執行計劃,參考連結:
--// http://blog.itpub.net/267265/viewspace-2130781/=> [20161216]toad下顯示真實的執行計劃.txt
SQL_ID 7hsd86dsfbba6, child number 0
-------------------------------------
SELECT * FROM t
Plan hash value: 1601196873
--------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 97 (100)| | 501 |00:00:00.01 | 21 |
| 1 | TABLE ACCESS FULL| T | 1 | 18725 | 2212K| 97 (2)| 00:00:01 | 501 |00:00:00.01 | 21 |
--------------------------------------------------------------------------------------------------------------------
--//注意看A-Rows僅僅取了501條記錄,buffers=21.這樣執行相對較快.
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / T@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('12.2.0.1')
DB_VERSION('12.2.0.1')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "T"@"SEL$1")
END_OUTLINE_DATA
*/
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - "T"."OWNER"[VARCHAR2,128], "T"."OBJECT_NAME"[VARCHAR2,128], "T"."SUBOBJECT_NAME"[VARCHAR2,128],
"T"."OBJECT_ID"[NUMBER,22], "T"."DATA_OBJECT_ID"[NUMBER,22], "T"."OBJECT_TYPE"[VARCHAR2,23],
"T"."CREATED"[DATE,7], "T"."LAST_DDL_TIME"[DATE,7], "T"."TIMESTAMP"[VARCHAR2,19], "T"."STATUS"[VARCHAR2,7],
"T"."TEMPORARY"[VARCHAR2,1], "T"."GENERATED"[VARCHAR2,1], "T"."SECONDARY"[VARCHAR2,1],
"T"."NAMESPACE"[NUMBER,22], "T"."EDITION_NAME"[VARCHAR2,128], "T"."SHARING"[VARCHAR2,18],
"T"."EDITIONABLE"[VARCHAR2,1], "T"."ORACLE_MAINTAINED"[VARCHAR2,1], "T"."APPLICATION"[VARCHAR2,1],
"T"."DEFAULT_COLLATION"[VARCHAR2,100], "T"."DUPLICATED"[VARCHAR2,1], "T"."SHARDED"[VARCHAR2,1],
"T"."CREATED_APPID"[NUMBER,22], "T"."CREATED_VSNID"[NUMBER,22], "T"."MODIFIED_APPID"[NUMBER,22],
"T"."MODIFIED_VSNID"[NUMBER,22]
--//如果要看完整的執行計劃統計:在sql編輯介面上選上auto trace,再次執行,檢視執行計劃:
SQL_ID 7hsd86dsfbba6, child number 0
-------------------------------------
SELECT * FROM t
Plan hash value: 1601196873
--------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 97 (100)| | 18725 |00:00:00.01 | 368 |
| 1 | TABLE ACCESS FULL| T | 1 | 18725 | 2212K| 97 (2)| 00:00:01 | 18725 |00:00:00.01 | 368 |
--------------------------------------------------------------------------------------------------------------------
--//注意看A-Rows取了18725條記錄,buffers=368.這樣執行相對較慢.
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / T@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('12.2.0.1')
DB_VERSION('12.2.0.1')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "T"@"SEL$1")
END_OUTLINE_DATA
*/
Column Projection Information (identified by operation id):
-----------------------------------------------------------
1 - "T"."OWNER"[VARCHAR2,128], "T"."OBJECT_NAME"[VARCHAR2,128], "T"."SUBOBJECT_NAME"[VARCHAR2,128],
"T"."OBJECT_ID"[NUMBER,22], "T"."DATA_OBJECT_ID"[NUMBER,22], "T"."OBJECT_TYPE"[VARCHAR2,23],
"T"."CREATED"[DATE,7], "T"."LAST_DDL_TIME"[DATE,7], "T"."TIMESTAMP"[VARCHAR2,19], "T"."STATUS"[VARCHAR2,7],
"T"."TEMPORARY"[VARCHAR2,1], "T"."GENERATED"[VARCHAR2,1], "T"."SECONDARY"[VARCHAR2,1],
"T"."NAMESPACE"[NUMBER,22], "T"."EDITION_NAME"[VARCHAR2,128], "T"."SHARING"[VARCHAR2,18],
"T"."EDITIONABLE"[VARCHAR2,1], "T"."ORACLE_MAINTAINED"[VARCHAR2,1], "T"."APPLICATION"[VARCHAR2,1],
"T"."DEFAULT_COLLATION"[VARCHAR2,100], "T"."DUPLICATED"[VARCHAR2,1], "T"."SHARDED"[VARCHAR2,1],
"T"."CREATED_APPID"[NUMBER,22], "T"."CREATED_VSNID"[NUMBER,22], "T"."MODIFIED_APPID"[NUMBER,22],
"T"."MODIFIED_VSNID"[NUMBER,22]
--//另外注意兩個執行計劃的A-time都是00:00:00.01,理論要看完整個結果集合,第2次執行至少要等上2,3秒,而實際看到的
--//A-Time=00:00:00.01,也就是我做的例子兩者看執行計劃時間差不多.第2個慢主要原因在於輸出這個結果集上,會出現
--//大部分時間浪費在網路傳輸結果上.SQL*Net message from client,明天測試生產系統的情況.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2933497/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20181120]toad看真實的執行計劃.txt
- [20210114]toad檢視真實執行計劃問題.txt
- [20240313]toad gather_plan_statistics執行計劃相關問題.txt
- [20210205]toad檢視真實執行計劃問題3.txt
- [20210119]看執行計劃可以使用hash_value.txt
- [20220414]toad呼叫執行指令碼問題.txt指令碼
- [20190111]執行計劃bitmap and.txt
- [20210926]並行執行計劃疑問.txt並行
- [20190111]執行計劃走位與.txt
- [20191220]格式化執行計劃.txt
- [20181201]奇怪的INDEX SKIP SCAN執行計劃.txtIndex
- [20231210]執行計劃與繫結變數.txt變數
- 執行計劃-1:獲取執行計劃
- MySQL 5.7 優化不能只看執行計劃MySql優化
- [20230921]為什麼執行計劃不再awr中.txt
- [20190720]12cR2顯示執行計劃.txt
- [20221104]執行計劃一樣Plan hash value不同.txt
- [20211229]toad下優化sql語句注意的問題.txt優化SQL
- 分析執行計劃優化SQLORACLE的執行計劃(轉)優化SQLOracle
- MySQL Cases-執行計劃向Oracle看齊(FORMAT=tree)MySqlOracleORM
- MySQL執行計劃MySql
- SYBASE執行計劃
- MySQL 執行計劃MySql
- 【執行計劃】Oracle獲取執行計劃的幾種方法Oracle
- MySQL執行計劃解析MySql
- mysql explain 執行計劃MySqlAI
- explain執行計劃分析AI
- mysql執行計劃explainMySqlAI
- oracle 固定執行計劃Oracle
- Oracle sql執行計劃OracleSQL
- 執行計劃執行步驟原則
- 20200909]為什麼執行計劃不是出現hash join semi.txt
- 【PG執行計劃】Postgresql資料庫執行計劃統計資訊簡述SQL資料庫
- [20181206]toad 12小問題.txt
- mongodb執行計劃解釋MongoDB
- 檢視 OceanBase 執行計劃
- MySQL執行計劃解析(四)MySql
- 讀懂MySQL執行計劃MySql