執行計劃的組成部分 正確的看執行計劃 DBMS_XPLAN 這個包是一個很好查看執行計劃,顯示很多格式,來分析執行計劃中存在的問題 format:控制詳細執行計劃輸出的格式,包含以下內容: BASIC:顯示最少的信息-ID,operation name TYPICAL :預設,在計劃中顯示最多相關信 ...
執行計劃的組成部分
正確的看執行計劃
DBMS_XPLAN 這個包是一個很好查看執行計劃,顯示很多格式,來分析執行計劃中存在的問題
format:控制詳細執行計劃輸出的格式,包含以下內容:
- BASIC:顯示最少的信息-ID,operation name
- TYPICAL :預設,在計劃中顯示最多相關信息(operation id,name,rows,bytes和cost),在適用時顯示pruning 、parallel和predicate 信息
- SERIAL:像typical 除了並行信息不顯示,即使在並行中執行
- ALL:最大用戶級別,包含信息顯示TYPICAL級別,在增加(PROJECTION、ALLAS和在分散式操作中REMOTE SQL)
format 關鍵字必須用逗號或者空格隔開
- ROWS-相關,顯示優化器評估的行數
- BYTES-顯示優化器評估的位元組數量
- COST-顯示優化器評估的代價信息
- PARATITION-顯示優化器的裁集信息
- PARALLEL-顯示PX信息(分配方法和表隊列的信息)
- PREDICATE-顯示謂詞章節信息(predicate )
- PROJECTION-顯示欄位定義信息(projection)
- ALLAS-顯示查詢塊名稱/對象別名(QUERY BLOCK NAME/OBJECT ALIAS)
- REMOTE-顯示分散式查詢信息(如遠程從分散式遠程SQL)
- NOTE-顯示計劃中NOTE信息
- IOSTATS-當SQL語句被執行時,假如基本的計劃統計信息被收集(使用gather_plan_statistics hint或設置statistics_level參數設置為ALL),用格式ALL來顯示IO統計信息(或僅用LAST顯示)對這個游標的執行
- MEMSTATS-假如PGA記憶體管理被啟用(這個是,pga_aggregate_target參數設置非為0),這個格式允許顯示記憶體的統計信息(如,操作者執行模式,記憶體被多少使用,多少的位元組數被寫入磁碟等),這些統計信息應用到記憶體敏感的操作如hash-join,排序或一些點陣圖操作。
- ALLSTATS-‘IOSTATS MEMSTATS’的縮寫
- LAST-預設,計劃統計信息被顯示游標中的全部的執行計劃,關鍵字LAST被指定僅查看語句的最後一次執行計劃
以下兩種已經過時,但是支持向後的相容性:
- RUNSTATS_TOT-跟IOSTATS類同,顯示IO統計信息指定游標的全部統計信息
- RUNSTATS_LAST跟 IOSTATS LAST ,顯示運行統計信息的游標最後一次統計信息
格式化關鍵字可以首碼通過標記‘-’排除指定的信息,如:‘-PROJECTION’就排除了projection 信息
類別分類和顯示
class level | alias | bytes | cost | note | predicate | parallel | partition | projection | outlines | peeked_binds | remote | rows |
BASIC | ||||||||||||
TYPICAL | Y | Y | Y | Y | Y | Y | Y | Y | ||||
SERIAL | Y | Y | Y | Y | Y | |||||||
ALL | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | |
ADVANCED | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y |
執行計劃的組成部分
- 目標SQL語句
- 執行計劃的主要部分:路徑、查詢塊命名、OUTline data、Predicate Information 、Column Projection Information
- 輔助信息:NOTE(11g的基數評估、sql profile、動態採樣)
找到SQL_ID,調用DBMS_XPLAN包,格式化執行計劃
SELECT SQL_ID, CHILD_NUMBER FROM V$SQL WHERE SQL_TEXT LIKE 'select * from GLL_OBJECT_0602 where object_id=7782%' AND SQL_TEXT NOT LIKE '%V$SQL%';
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('75nc852bx00ub',0,'ADVANCED')); SQL_ID 75nc852bx00ub, child number 0 ------------------------------------- select * from GLL_OBJECT_0602 where object_id=7782 Plan hash value: 2093672533 ----------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 2 (100)| | | 1 | TABLE ACCESS BY INDEX ROWID| GLL_OBJECT_0602 | 1 | 207 | 2 (0)| 00:00:01 | |* 2 | INDEX RANGE SCAN | IND_OBJECT | 1 | | 1 (0)| 00:00:01 | ----------------------------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$1 / GLL_OBJECT_0602@SEL$1 2 - SEL$1 / GLL_OBJECT_0602@SEL$1 Outline Data ------------- /*+ BEGIN_OUTLINE_DATA IGNORE_OPTIM_EMBEDDED_HINTS OPTIMIZER_FEATURES_ENABLE('11.2.0.3') DB_VERSION('11.2.0.3') ALL_ROWS OUTLINE_LEAF(@"SEL$1") INDEX_RS_ASC(@"SEL$1" "GLL_OBJECT_0602"@"SEL$1" ("GLL_OBJECT_0602"."OBJECT_ID")) END_OUTLINE_DATA */ Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("OBJECT_ID"=7782) Column Projection Information (identified by operation id): ----------------------------------------------------------- 1 - "GLL_OBJECT_0602"."OWNER"[VARCHAR2,30], "GLL_OBJECT_0602"."OBJECT_NAME"[VARCHAR2,128], "GLL_OBJECT_0602"."SUBOBJECT_NAME"[VARCHAR2,30], "OBJECT_ID"[NUMBER,22], "GLL_OBJECT_0602"."DATA_OBJECT_ID"[NUMBER,22], "GLL_OBJECT_0602"."OBJECT_TYPE"[VARCHAR2,19], "GLL_OBJECT_0602"."CREATED"[DATE,7], "GLL_OBJECT_0602"."LAST_DDL_TIME"[DATE,7], "GLL_OBJECT_0602"."TIMESTAMP"[VARCHAR2,19], "GLL_OBJECT_0602"."STATUS"[VARCHAR2,7], "GLL_OBJECT_0602"."TEMPORARY"[VARCHAR2,1], "GLL_OBJECT_0602"."GENERATED"[VARCHAR2,1], "GLL_OBJECT_0602"."SECONDARY"[VARCHAR2,1], "GLL_OBJECT_0602"."NAMESPACE"[NUMBER,22], "GLL_OBJECT_0602"."EDITION_NAME"[VARCHAR2,30] 2 - "GLL_OBJECT_0602".ROWID[ROWID,10], "OBJECT_ID"[NUMBER,22] Note ----- - dynamic sampling used for this statement (level=2)
輸出格式中真實ROWS
獲取SQL_ID
select /*+gather_plan_statistics*/ * from GLL_OBJECT_0602 where object_id=:id
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('3ap5ukwk8gs9g',0,'ALLSTATS LAST +PEEKED_BINDS +PROJECTION +ALIAS +PREDICATE +COST +BYTES')); SQL_ID 3ap5ukwk8gs9g, child number 0 ------------------------------------- select /*+gather_plan_statistics*/ * from GLL_OBJECT_0602 where object_id=:id Plan hash value: 3717822783 -------------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| A-Rows | A-Time | Buffers | -------------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | | | 293 (100)| 1 |00:00:00.01 | 1072 | |* 1 | TABLE ACCESS FULL| GLL_OBJECT_0602 | 1 | 872 | 176K| 293 (1)| 1 |00:00:00.01 | 1072 | -------------------------------------------------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$1 / GLL_OBJECT_0602@SEL$1 Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("OBJECT_ID"=TO_NUMBER(:ID)) Column Projection Information (identified by operation id): ----------------------------------------------------------- 1 - "GLL_OBJECT_0602"."OWNER"[VARCHAR2,30], "GLL_OBJECT_0602"."OBJECT_NAME"[VARCHAR2,128], "GLL_OBJECT_0602"."SUBOBJECT_NAME"[VARCHAR2,30], "OBJECT_ID"[NUMBER,22], "GLL_OBJECT_0602"."DATA_OBJECT_ID"[NUMBER,22], "GLL_OBJECT_0602"."OBJECT_TYPE"[VARCHAR2,19], "GLL_OBJECT_0602"."CREATED"[DATE,7], "GLL_OBJECT_0602"."LAST_DDL_TIME"[DATE,7], "GLL_OBJECT_0602"."TIMESTAMP"[VARCHAR2,19], "GLL_OBJECT_0602"."STATUS"[VARCHAR2,7], "GLL_OBJECT_0602"."TEMPORARY"[VARCHAR2,1], "GLL_OBJECT_0602"."GENERATED"[VARCHAR2,1], "GLL_OBJECT_0602"."SECONDARY"[VARCHAR2,1], "GLL_OBJECT_0602"."NAMESPACE"[NUMBER,22], "GLL_OBJECT_0602"."EDITION_NAME"[VARCHAR2,30]
查詢塊的輸出,可以把內聯視圖的信息,在主查詢中去定義全表掃描還是索引訪問
SQL_ID 896fbd4yjghj8, child number 0 ------------------------------------- select /*+ FULL(@strange dept) */ ENAME from emp e, (select /*+ QB_NAME(strange) */* from dept where deptno=20) d where e.deptno=d.deptno and d.loc= 'DALLAS' Plan hash value: 4192419542 --------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 6 (100)| | | 1 | NESTED LOOPS | | 1 | 31 | 6 (0)| 00:00:01 | |* 2 | TABLE ACCESS FULL| DEPT | 1 | 11 | 3 (0)| 00:00:01 | |* 3 | TABLE ACCESS FULL| EMP | 5 | 100 | 3 (0)| 00:00:01 | --------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$DB579D14 2 - SEL$DB579D14 / DEPT@STRANGE 3 - SEL$DB579D14 / E@SEL$1
首碼 | 行源操作 |
CRI$ | CREATE INDEX statement |
DEL$ | DELETE STATEMENT |
INS$ | INSERT statement |
MISC$ | miesc SQL 類似 lock table |
MRG$ | Merge Statement |
SEL$ | SELECT statement |
SET$ | Set operators |
UPD$ | Update statement |
STARTS 實際執行行源的次數
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('bv3a5xts1cuh2',0,'ALLSTATS +PEEKED_BINDS +COST -PREDICATE')); SQL_ID 0v8h8ka3hr0bp, child number 0 ------------------------------------- select /*+gather_plan_statistics*/ ENAME from emp e, (select * from dept where deptno=20) d where e.deptno=d.deptno and d.loc= 'DALLAS' Plan hash value: 568005898 --------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers | --------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | | 4 (100)| 5 |00:00:00.01 | 9 | | 1 | NESTED LOOPS | | 1 | 5 | 4 (0)| 5 |00:00:00.01 | 9 | | 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 1 | 1 | 1 (0)| 1 |00:00:00.01 | 2 | | 3 | INDEX UNIQUE SCAN | PK_DEPT | 1 | 1 | 0 (0)| 1 |00:00:00.01 | 1 | | 4 | TABLE ACCESS FULL | EMP | 1 | 5 | 3 (0)| 5 |00:00:00.01 | 7 | --------------------------------------------------------------------------------------------------------------- Note ----- - dynamic sampling used for this statement (level=2)
remote的信息展示
PARALLEL信息展示
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('1ms60dn34wyy0',0,'ADVANCED')); SQL_ID 1ms60dn34wyy0, child number 0 ------------------------------------- select /*+PARALLEL(4)*/ ENAME from emp e, DEPT d where e.deptno=d.deptno Plan hash value: 2873591275 -------------------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib | -------------------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | | 2 (100)| | | | | | 1 | PX COORDINATOR | | | | | | | | | | 2 | PX SEND QC (RANDOM)| :TQ10000 | 14 | 280 | 2 (0)| 00:00:01 | Q1,00 | P->S | QC (RAND) | | 3 | PX BLOCK ITERATOR | | 14 | 280 | 2 (0)| 00:00:01 | Q1,00 | PCWC | | |* 4 | TABLE ACCESS FULL| EMP | 14 | 280 | 2 (0)| 00:00:01 | Q1,00 | PCWP | | -------------------------------------------------------------------------------------------------------------- Query Block Name / Object Alias (identified by operation id): ------------------------------------------------------------- 1 - SEL$F7859CDE 4 - SEL$F7859CDE / E@SEL$1 Outline Data ------------- /*+ BEGIN_OUTLINE_DATA IGNORE_OPTIM_EMBEDDED_HINTS OPTIMIZER_FEATURES_ENABLE('11.2.0.3') DB_VERSION('11.2.0.3') ALL_ROWS SHARED(4) OUTLINE_LEAF(@"SEL$F7859CDE") ELIMINATE_JOIN(@"SEL$1" "D"@"SEL$1") OUTLINE(@"SEL$1") FULL(@"SEL$F7859CDE" "E"@"SEL$1") END_OUTLINE_DATA */ Predicate Information (identified by operation id): --------------------------------------------------- 4 - access(:Z>=:Z AND :Z<=:Z) filter("E"."DEPTNO" IS NOT NULL) Column Projection Information (identified by operation id): ----------------------------------------------------------- 1 - "ENAME"[VARCHAR2,10] 2 - (#keys=0) "ENAME"[VARCHAR2,10] 3 - "ENAME"[VARCHAR2,10] 4 - "ENAME"[VARCHAR2,10] Note ----- - dynamic sampling used for this statement (level=2) - Degree of Parallelism is 4 because of hint
note信息
Note ----- - dynamic sampling used for this statement (level=2) - Degree of Parallelism is 4 because of hint Note ----- - SQL profile “SQL_PROF_896fbd4yjghj8" used for this statement 11g出現的基數評估 Note ----- - Cardinality feedback used
輸出指標的全部說明
指標參數 | 說明 |
通用內容 | |
ID | 執行計劃中每個步驟的標識符,如果首碼*,在謂詞部分有謂詞信息 |
operation | 行源的操作方式 |
name | 對象名稱:表、索引、視圖等 |
CB0 解析時間信息 | |
rows | 通過行源操作優化器評估的行返回的數量,來源操作對象的統計信息 |
Bytes | 優化器評估的返回的數據量 |
tempspc | 優化器評估臨時空間的使用率 |
Cost(%CPU) | 優化器行源操作的代價,CPU百分比代價給於()中獨立的行源操作 |
time | 評估需要執行這個操作的時間量,單位HH:MI: SS |
分區 | |
Pstart | 第一個分區數目被訪問 |
Pstop | 最後一個分區數目被訪問 |
並行處理 | |
TQ | 表隊列使用處理 |
IN-OUT | 並行操作的關聯 |
PQ Distrib | 由伺服器端使用分配併發送數據給客戶端 |
真正運行統計信息 | |
Starts | 多少次數數目操作被執行(核對更多嵌套迴圈操作) |
A-ROWS | 行返回的真實數目 |
A-TIMES | 真實的時間量花費在執行這個操作上 |
I/O統計信息 | |
buffers | 當每個步驟執行,邏輯讀取操作執行 |
read | 物理讀取執行每個操作步驟 |
write | 物理寫入執行 |
DBMS_XPLAN.DISPLAY_AWR輸出awr中的歷史執行計劃,不在重覆說明
限制說明
DISPLAY_AWR不能存儲謂詞信息
awr中沒有存儲全部的SQL語句,導致一些語句無法查看到歷史的執行計劃
DISPLAY_CURor在rac環境下,不能全部顯示,只顯示連接的節點,需要查看另外節點的話,連接到另一個節點
顯示真實時間的統計信息需要SQL語句運行完成(需要長時間運行查詢)