查看執(zhí)行計(jì)劃的方法
創(chuàng)新互聯(lián)建站秉承實(shí)現(xiàn)全網(wǎng)價(jià)值營(yíng)銷的理念,以專業(yè)定制企業(yè)官網(wǎng),成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作,成都微信小程序,網(wǎng)頁(yè)設(shè)計(jì)制作,移動(dòng)網(wǎng)站建設(shè),營(yíng)銷型網(wǎng)站建設(shè)幫助傳統(tǒng)企業(yè)實(shí)現(xiàn)“互聯(lián)網(wǎng)+”轉(zhuǎn)型升級(jí)專業(yè)定制企業(yè)官網(wǎng),公司注重人才、技術(shù)和管理,匯聚了一批優(yōu)秀的互聯(lián)網(wǎng)技術(shù)人才,對(duì)客戶都以感恩的心態(tài)奉獻(xiàn)自己的專業(yè)和所長(zhǎng)。
D:\instantclient_12_2>sqlplus scott/tiger@clonepdb_plug
SQL*Plus: Release 12.2.0.1.0 Production on Fri Jan 12 13:54:31 2018
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Last Successful login time: Fri Jan 12 2018 11:18:59 +08:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SCOTT@clonepdb_plug>set linesize 180
SCOTT@clonepdb_plug>set pagesize 0
SCOTT@clonepdb_plug>alter session set STATISTICS_LEVEL = ALL;
Session altered.
SCOTT@clonepdb_plug>select * from emp where ename='SMITH';
7369 SMITH CLERK 7902 1980-12-17 00:00:00 800 20
select * from emp where ename='SMITH'
Plan hash value: 3956160932
1 - filter("ENAME"='SMITH')
18 rows selected.
SCOTT@clonepdb_plug>
需要授權(quán)
grant select on v$session to scott;
grant select on v$sql to scott;
grant select on v_$sqlplan to scott;
grant select on v$sql_plan_statistics_all to scott;
Id 執(zhí)行計(jì)劃中每一個(gè)操作(行)的標(biāo)識(shí)符。如果數(shù)字前面帶有星號(hào),意味著將在隨后提供這行包含的謂詞信息
Operation 對(duì)應(yīng)執(zhí)行的操作。也叫行源操作
Name 操作的對(duì)象名稱
2.查詢優(yōu)化器評(píng)估信息
Rows(E-Rows) 預(yù)估操作返回的記錄條數(shù)
Bytes(E-Bytes) 預(yù)估操作返回的記錄字節(jié)數(shù)
TempSpc 預(yù)估操作使用臨時(shí)表空間的大小
Cost(%CPU) 預(yù)估操作所需的開(kāi)銷。在括號(hào)中列出了CPU開(kāi)銷的百分比。注意這些值是通過(guò)執(zhí)行計(jì)劃計(jì)算出來(lái)的。換句話說(shuō),父操作的開(kāi)銷包含子操作的開(kāi)銷
Time 預(yù)估執(zhí)行操作所需要的時(shí)間(HH:MM:SS)
3.分區(qū)(僅當(dāng)訪問(wèn)分區(qū)表時(shí)下列字段可見(jiàn))
Pstart 訪問(wèn)的第一個(gè)分區(qū)。如果解析時(shí)不知道是哪個(gè)分區(qū)就設(shè)為KEY,KEY(I),KEY(MC),KEY(OR),KEY(SQ)
Pstop 訪問(wèn)的最后一個(gè)分區(qū)。如果解析時(shí)不知道是哪個(gè)分區(qū)就設(shè)為KEY,KEY(I),KEY(MC),KEY(OR),KEY(SQ)
4.并行和分布式處理(僅當(dāng)使用并行或分布式操作時(shí)下列字段可見(jiàn))
Inst 在分布式操作中,指操作使用的數(shù)據(jù)庫(kù)鏈接的名字
TQ 在并行操作中,用于從屬線程間通信的表隊(duì)列
IN-OUT 并行或分布式操作間的關(guān)系
PQ Distrib 在并行操作中,生產(chǎn)者為發(fā)送數(shù)據(jù)給消費(fèi)者進(jìn)行的分配
5.運(yùn)行時(shí)統(tǒng)計(jì)(當(dāng)設(shè)定參數(shù)statistics_level為all或使用gather_plan_statistics提示時(shí),下列字段可見(jiàn))
Starts 指定操作執(zhí)行的次數(shù)
A-Rows 操作返回的真實(shí)記錄數(shù)
A-Time 操作執(zhí)行的真實(shí)時(shí)間(HH:MM:SS.FF)
6.I/O 統(tǒng)計(jì)(當(dāng)設(shè)定參數(shù)statistics_level為all或使用gather_plan_statistics提示時(shí),下列字段可見(jiàn))
Buffers 執(zhí)行期間進(jìn)行的邏輯讀操作數(shù)量
Reads 執(zhí)行期間進(jìn)行的物理讀操作數(shù)量
Writes 執(zhí)行期間進(jìn)行的物理寫(xiě)操作數(shù)量
7.內(nèi)存使用統(tǒng)計(jì)
OMem 最優(yōu)執(zhí)行所需內(nèi)存的預(yù)估值
1Mem 一次通過(guò)(one-pass)執(zhí)行所需內(nèi)存的預(yù)估值
0/1/M 最優(yōu)/一次通過(guò)/多次通過(guò)(multipass)模式操作執(zhí)行的次數(shù)
Used-Mem 最后一次執(zhí)行時(shí)操作使用的內(nèi)存量
Used-Tmp 最后一次執(zhí)行時(shí)操作使用的臨時(shí)空間大小。這個(gè)字段必須擴(kuò)大1024倍才能和其他衡量?jī)?nèi)存的字段一致(比如,32k意味著32MB)
Max-Tmp 操作使用的最大臨時(shí)空間大小。這個(gè)字段必須擴(kuò)大1024倍才能和其他衡量?jī)?nèi)存的字段一致(比如,32k意味著32MB)
例
SCOTT@clonepdb_plug>explain plan for
2 select * from emp e,dept d
3 where e.deptno=d.deptno
4 and e.ename='SMITH';
Explained.
3 - SEL$1 / E@SEL$1 -E@SEL$1,對(duì)應(yīng)到執(zhí)行計(jì)劃中的操作ID為3上,即在表E上的查詢,E為別名,下面類同 SEL$為select 的縮寫(xiě),位于塊1,相應(yīng)的還有DEL$,INS$,UPD$等
4 - SEL$1 / D@SEL$1
5 - SEL$1 / D@SEL$1
/+
BEGIN_OUTLINE_DATA
NLJ_BATCHING(@"SEL$1" "D"@"SEL$1") --指示優(yōu)化器以嵌套循環(huán)關(guān)聯(lián)預(yù)提取的方式訪問(wèn)表
USE_NL(@"SEL$1" "D"@"SEL$1") --使用USE_NL提示,即嵌套循環(huán)
LEADING(@"SEL$1" "E"@"SEL$1" "D"@"SEL$1") --指明前導(dǎo)表
INDEX(@"SEL$1" "D"@"SEL$1" ("DEPT"."DEPTNO"))-指明對(duì)于D上的訪問(wèn)方式為使用索引
FULL(@"SEL$1" "E"@"SEL$1") --指明對(duì)于E上的訪問(wèn)方式為全表掃描 OUTLINE_LEAF(@"SEL$1")
br/>OUTLINE_LEAF(@"SEL$1")
DB_VERSION('12.2.0.1')
OPTIMIZER_FEATURES_ENABLE('12.2.0.1')
IGNORE_OPTIM_EMBEDDED_HINTS
END_OUTLINE_DATA
/
3 - filter("E"."ENAME"='SMITH')
4 - access("E"."DEPTNO"="D"."DEPTNO")
1 - (#keys=0) "E"."EMPNO"[NUMBER,22], "E"."ENAME"[VARCHAR2,10],
"E"."JOB"[VARCHAR2,9], "E"."MGR"[NUMBER,22], "E"."HIREDATE"[DATE,7],
"E"."SAL"[NUMBER,22], "E"."COMM"[NUMBER,22], "E"."DEPTNO"[NUMBER,22],
"D"."DEPTNO"[NUMBER,22], "D"."DNAME"[VARCHAR2,14], "D"."LOC"[VARCHAR2,13]
2 - (#keys=0) "E"."EMPNO"[NUMBER,22], "E"."ENAME"[VARCHAR2,10],
"E"."JOB"[VARCHAR2,9], "E"."MGR"[NUMBER,22], "E"."HIREDATE"[DATE,7],
"E"."SAL"[NUMBER,22], "E"."COMM"[NUMBER,22], "E"."DEPTNO"[NUMBER,22],
"D".ROWID[ROWID,10], "D"."DEPTNO"[NUMBER,22]
3 - "E"."EMPNO"[NUMBER,22], "E"."ENAME"[VARCHAR2,10], "E"."JOB"[VARCHAR2,9],
"E"."MGR"[NUMBER,22], "E"."HIREDATE"[DATE,7], "E"."SAL"[NUMBER,22],
"E"."COMM"[NUMBER,22], "E"."DEPTNO"[NUMBER,22]
4 - "D".ROWID[ROWID,10], "D"."DEPTNO"[NUMBER,22]
5 - "D"."DNAME"[VARCHAR2,14], "D"."LOC"[VARCHAR2,13]
64 rows selected.
例
SCOTT@clonepdb_plug>select /+ gather_plan_statistics / * from emp e,dept d
2 where e.deptno=d.deptno
3 and e.ename='SMITH';
--注意此處增加了提示gather_plan_statistics并且該語(yǔ)句被執(zhí)行 等同于alter session set STATISTICS_LEVEL = ALL;
7369 SMITH CLERK 7902 1980-12-17 00:00:00 800 20 20 RESEARCH
DALLAS
select /+ gather_plan_statistics / * from emp e,dept d
where e.deptno=d.deptno and e.ename='SMITH'
Plan hash value: 3625962092
3 - filter("E"."ENAME"='SMITH')
4 - access("E"."DEPTNO"="D"."DEPTNO")
this is an adaptive plan
28 rows selected.
select /+ gather_plan_statistics / * from emp e,dept d
where e.deptno=d.deptno and rownum<20 and ename like
'%I%'
Plan hash value: 2662388210
1 - SEL$1
3 - SEL$1 / E@SEL$1
4 - SEL$1 / D@SEL$1
/+
BEGIN_OUTLINE_DATA
FULL(@"SEL$1" "D"@"SEL$1")
USE_HASH(@"SEL$1" "D"@"SEL$1")IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('12.2.0.1')
DB_VERSION('12.2.0.1')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
br/>IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('12.2.0.1')
DB_VERSION('12.2.0.1')
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
LEADING(@"SEL$1" "E"@"SEL$1" "D"@"SEL$1")
END_OUTLINE_DATA
/
1 - filter(ROWNUM<20)
2 - access("E"."DEPTNO"="D"."DEPTNO")
3 - filter(("ENAME" LIKE '%I%' AND "ENAME" IS NOT NULL))
1 - "E"."DEPTNO"[NUMBER,22], "D"."DEPTNO"[NUMBER,22], "E"."EMPNO"[NUMBER,22], "ENAME"[VARCHAR2,10], "E"."JOB"[VARCHAR2,9],
"E"."MGR"[NUMBER,22], "E"."HIREDATE"[DATE,7], "E"."SAL"[NUMBER,22], "E"."COMM"[NUMBER,22], "D"."LOC"[VARCHAR2,13],
"D"."DEPTNO"[NUMBER,22], "D"."DNAME"[VARCHAR2,14], "D"."LOC"[VARCHAR2,13], "D"."DNAME"[VARCHAR2,14]
2 - (#keys=1) "E"."DEPTNO"[NUMBER,22], "D"."DEPTNO"[NUMBER,22], "E"."EMPNO"[NUMBER,22], "ENAME"[VARCHAR2,10], "E"."JOB"[VARCHAR2,9],
"E"."MGR"[NUMBER,22], "E"."HIREDATE"[DATE,7], "E"."SAL"[NUMBER,22], "E"."COMM"[NUMBER,22], "D"."LOC"[VARCHAR2,13],
"D"."DEPTNO"[NUMBER,22], "D"."DNAME"[VARCHAR2,14], "D"."LOC"[VARCHAR2,13], "D"."DNAME"[VARCHAR2,14]
3 - "E"."EMPNO"[NUMBER,22], "ENAME"[VARCHAR2,10], "E"."JOB"[VARCHAR2,9], "E"."MGR"[NUMBER,22], "E"."HIREDATE"[DATE,7],
"E"."SAL"[NUMBER,22], "E"."COMM"[NUMBER,22], "E"."DEPTNO"[NUMBER,22]
4 - "D"."DEPTNO"[NUMBER,22], "D"."DNAME"[VARCHAR2,14], "D"."LOC"[VARCHAR2,13]
66 rows selected.
SCOTT@clonepdb_plug>