檢視歷史執行計劃

hooca發表於2016-04-21
如果要檢視過去歷史真實的執行計劃,而不是使用explain plan命令即時解析,需要檢視相關檢視。

如果當前執行計劃仍然儲存在library cache,則可以從v$sql_plan中看到。

點選(此處)摺疊或開啟

  1. SELECT plan_hash_value,
  2.        TO_CHAR(RAWTOHEX(child_address)),
           TO_NUMBER(child_number),
           id,
           LPAD(' ', DEPTH) || operation operation,
           options,
           object_owner,
           object_name,
           optimizer,
           cost,
           access_predicates,
           filter_predicates
      FROM V$SQL_PLAN
      where sql_id = 'abcd'
     ORDER BY 1, 3, 2, 4
黃色文字部分為sql_id

如果執行計劃已經不在library cache中了,則需要去DBA_HIST_SQL_PLAN中尋找。

點選(此處)摺疊或開啟

  1. set linesize 500
  2. set pagesize 500
    col plan_hash_value format 9999999999
    col id format 999999
    col operation format a30
    col options format a15
    col object_owner format a15
    col object_name format a20
    col optimizer format a15
    col cost format 9999999999
    col access_predicates format a15
    col filter_predicates format a15

    SELECT plan_hash_value,
             id,
             LPAD (' ', DEPTH) || operation operation,
             options,
             object_owner,
             object_name,
             optimizer,
             cost,
             access_predicates,
             filter_predicates
       FROM dba_hist_sql_plan
       WHERE sql_id = 'fahv8x6ngrb50'
    ORDER BY plan_hash_value, id;

通常,在AWR中發現的可疑語句可以通過如上方式操作。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22621861/viewspace-2085396/,如需轉載,請註明出處,否則將追究法律責任。

相關文章