這篇文章主要介紹了Oracle怎么查看sql執(zhí)行計(jì)劃的歷史變更,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比肥城網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式肥城網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋肥城地區(qū)。費(fèi)用合理售后完善,十載實(shí)體公司更值得信賴。
突然接收到active session 數(shù)目飆高的報(bào)警,查看數(shù)據(jù)庫,對(duì)于一個(gè)OLTP 類型的查詢本應(yīng)該走index range scan 卻變成全部是 direct path read ,所有的sql 走了全表掃描。悲劇的是那個(gè)表是一個(gè)歷史表 185G。。故造成了許多session堆積,前臺(tái)應(yīng)用受到影響。回到問題本身,如果查看sql執(zhí)行計(jì)劃的變更??
oracle 10G 以后可以通過下面的三個(gè)視圖查詢到sql執(zhí)行計(jì)劃的歷史信息:
DBA_HIST_SQL_PLAN
DBA_HIST_SQLSTAT
DBA_HIST_SNAPSHOT
查看語句的歷史執(zhí)行信息,是否發(fā)生變化,何時(shí)發(fā)生了變化。如果發(fā)生了變化,找出以前的執(zhí)行計(jì)劃,與當(dāng)前的執(zhí)行計(jì)劃進(jìn)行對(duì)比,有什么不同。
使用如下sql 可以發(fā)現(xiàn)某個(gè)sql的執(zhí)行計(jì)劃什么時(shí)候發(fā)生了變化!
select distinct SQL_ID,PLAN_HASH_VALUE,to_char(TIMESTAMP,'yyyymmdd hh34:mi:ss') TIMESTAMP
from dba_hist_sql_plan
where SQL_ID='68wnxdjxwwn2h' order by TIMESTAMP;
SQL_ID PLAN_HASH_VALUE TIMESTAMP
------------- --------------- -----------------
68wnxdjxwwn2h 235510920 20111020 21:25:23
68wnxdjxwwn2h 1542630049 20120612 11:57:23
68wnxdjxwwn2h 2754593971 20120612 12:43:34
查看出來執(zhí)行計(jì)劃的變化之后 可以使用如下sql查看發(fā)生了那些變化!
col options for a15
col operation for a20
col object_name for a20
select plan_hash_value,id,operation,options,object_name,depth,cost,to_char(TIMESTAMP,'yyyymmdd hh34:mi:ss')
from DBA_HIST_SQL_PLAN
where sql_id ='68wnxdjxwwn2h'
and plan_hash_value in (1542630049,2754593971,2620382595)
order by ID,TIMESTAMP;
PLAN_HASH_VALUE ID OPERATION OPTIONS OBJECT_NAME COST TO_CHAR(TIMESTAMP
--------------- ---------- --------------------- --------------- --------------------- ---------- -----------------
235510920 0 SELECT STATEMENT 39 20111020 21:25:23
235510920 1 NESTED LOOPS 20111020 21:25:23
235510920 2 NESTED LOOPS 39 20111020 21:25:23
235510920 3 VIEW 11 20111020 21:25:23
235510920 4 WINDOW SORT PUSHED RANK 11 20111020 21:25:23
235510920 5 TABLE ACCESS FULL C_ETL_DATA_VALIDITY 10 20111020 21:25:23
235510920 6 PARTITION LIST ITERATOR 2 20111020 21:25:23
235510920 7 INDEX RANGE SCAN IDX_C_MEM_XXXXXXXX_ID 2 20111020 21:25:23
235510920 8 TABLE ACCESS BY LOCAL INDEX C_MEM_XXXXXXXX_FATDT0 4 20111020 21:25:23
ROWID
1542630049 0 SELECT STATEMENT 7854 20120612 11:57:23
1542630049 1 NESTED LOOPS 7854 20120612 11:57:23
1542630049 2 VIEW 28 20120612 11:57:23
1542630049 3 WINDOW SORT PUSHED RANK 28 20120612 11:57:23
1542630049 4 TABLE ACCESS FULL C_ETL_DATA_VALIDITY 27 20120612 11:57:23
1542630049 5 PARTITION LIST ITERATOR 7826 20120612 11:57:23
1542630049 6 TABLE ACCESS FULL C_MEM_XXXXXXXX_FATDT0 7826 20120612 11:57:23
2754593971 0 SELECT STATEMENT 43 20120612 12:43:34
2754593971 1 PX COORDINATOR 20120612 12:43:34
2754593971 2 PX SEND QC (RANDOM) :TQ10001 20120612 12:43:34
2754593971 3 NESTED LOOPS 20120612 12:43:34
2754593971 4 NESTED LOOPS 43 20120612 12:43:34
2754593971 5 BUFFER SORT 20120612 12:43:34
2754593971 6 PX RECEIVE 20120612 12:43:34
2754593971 7 PX SEND BROADCAST :TQ10000 20120612 12:43:34
2754593971 8 VIEW 28 20120612 12:43:34
2754593971 9 WINDOW SORT PUSHED RANK 28 20120612 12:43:34
2754593971 10 TABLE ACCESS FULL C_ETL_DATA_VALIDITY 27 20120612 12:43:34
2754593971 11 PX PARTITION LIST ITERATOR 2 20120612 12:43:34
2754593971 12 INDEX RANGE SCAN IDX_C_MEM_XXXXXXXX_ID 2 20120612 12:43:34
2754593971 13 TABLE ACCESS BY LOCAL INDEX C_MEM_XXXXXXXX_FATDT0 15 20120612 12:43:34
ROWID
2620382595 0 SELECT STATEMENT 5 20120612 18:27:37
2620382595 1 TABLE ACCESS BY INDEX ROWID C_MEM_XXXXXXXX_BAKUP 5 20120612 18:27:37
2620382595 2 INDEX RANGE SCAN IDX_C_MEM_XXXXXXXX_BA 3 20120612 18:27:37
KUP_ID
33 rows selected.
從上面的結(jié)果中可以看出 執(zhí)行計(jì)劃在11:57 時(shí)出現(xiàn)改變 C_MEM_XXXXXXXX_FATDT0有之前的index range scan 變?yōu)榱薴ull table scan!!
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“Oracle怎么查看sql執(zhí)行計(jì)劃的歷史變更”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!