執行計劃的組成部分
正確的看執行計劃
DBMS_XPLAN 這個包是一個很好查看執行計劃,顯示很多格式,來分析執行計劃中存在的問題
format:控制詳細執行計劃輸出的格式,包含以下內容:
format 關鍵字必須用逗號或者空格隔開
以下兩種已經過時,但是支持向後的兼容性:
格式化關鍵字可以前綴通過標記‘-’排除指定的信息,如:‘-PROJECTION’就排除了projection 信息
執行計劃的組成部分
找到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)
獲取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
DBMS_XPLAN.DISPLAY_AWR輸出awr中的歷史執行計劃,不在重復說明
限制說明
DISPLAY_AWR不能存儲謂詞信息
awr中沒有存儲全部的SQL語句,導致一些語句無法查看到歷史的執行計劃
DISPLAY_CURor在rac環境下,不能全部顯示,只顯示連接的節點,需要查看另外節點的話,連接到另一個節點
顯示真實時間的統計信息需要SQL語句運行完成(需要長時間運行查詢)