查看历史执行计划_ITPUB博客

如果要查看过去历史真实的执行计划,而不是使用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博客)