暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

oracle查询V$ARCHIVE_GAP慢的问题解决--转瞻Derek

nirvana 2024-08-01
364


在 Oracle 11.2.0.4 或更高版本中,查询 V$ARCHIVE_GAP 视图可能由于执行计划中使用了内部涉及 X$KCCLH 和 X$KCCAL 的 MERGE JOIN CARTESIAN 操作而导致性能下降或抛出 ORA-1220 错误。为了避免这种情况,可以使用重构后的查询直接进行操作。

select * from gv$archive_gap;

INST_ID   THREAD# LOW_SEQUENCE# HIGH_SEQUENCE#
---------- ---------- ------------- --------------
   1     1     580       581
         
         
select USERENV('Instance'), high.thread#, low.lsq, high.hsq
 from
  (select a.thread#, rcvsq, min(a.sequence#)-1 hsq
   from v$archived_log a,
        (select lh.thread#, lh.resetlogs_change#, max(lh.sequence#) rcvsq
           from v$log_history lh, v$database_incarnation di
          where lh.resetlogs_time = di.resetlogs_time
            and lh.resetlogs_change# = di.resetlogs_change#
            and di.status = 'CURRENT'
            and lh.thread# is not null
            and lh.resetlogs_change# is not null
            and lh.resetlogs_time is not null
         group by lh.thread#, lh.resetlogs_change#
        ) b
   where a.thread# = b.thread#
     and a.resetlogs_change# = b.resetlogs_change#
     and a.sequence# > rcvsq
   group by a.thread#, rcvsq) high,
 (select srl_lsq.thread#, nvl(lh_lsq.lsq, srl_lsq.lsq) lsq
   from
     (select thread#, min(sequence#)+1 lsq
      from
        v$log_history lh, x$kccfe fe, v$database_incarnation di
      where to_number(fe.fecps) <= lh.next_change#
        and to_number(fe.fecps) >= lh.first_change#
        and fe.fedup!=0 and bitand(fe.festa, 12) = 12
        and di.resetlogs_time = lh.resetlogs_time
        and lh.resetlogs_change# = di.resetlogs_change#
        and di.status = 'CURRENT'
      group by thread#) lh_lsq,
     (select thread#, max(sequence#)+1 lsq
      from
        v$log_history
      where (select min( to_number(fe.fecps))
             from x$kccfe fe
             where fe.fedup!=0 and bitand(fe.festa, 12) = 12)
      >= next_change#
      group by thread#) srl_lsq
   where srl_lsq.thread# = lh_lsq.thread#(+)
  ) low
 where low.thread# = high.thread#
 and lsq < = hsq
 and hsq > rcvsq;
 
USERENV('INSTANCE')  THREAD#   LSQ    HSQ
------------------- ---------- ---------- ----------
1           1     580      581
或者收集视图的统计信息。BEGIN DBMS_STATS.GATHER_TABLE_STATS( ownname => 'SYS', -- 视图所有者通常是SYS tabname => 'X$KCCLE', -- 视图名称 cascade => TRUE, -- 是否收集相关的索引和列的统计信息 estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, -- 采样百分比,AUTO_SAMPLE_SIZE会根据表大小自动决定采样大小 method_opt => 'FOR ALL COLUMNS SIZE AUTO'); -- 为所有列自动决定采样大小 DBMS_STATS.GATHER_TABLE_STATS( ownname => 'SYS', tabname => 'X$KCCLH', cascade => TRUE, estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE, method_opt => 'FOR ALL COLUMNS SIZE AUTO'); END; /


「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论