您好,欢迎访问一九零五行业门户网

使用hint优化Oracle的执行计划

背景: 某表忽然出现查询非常缓慢的情况,cost 100+ 秒以上;严重影响生产。 oracle入门教程:leading vs ordered hint http://
背景:
某表忽然出现查询非常缓慢的情况,,cost 100+ 秒以上;严重影响生产。
oracle入门教程:leading vs ordered hint 
oracle hint 实践一列 leanding 驱动表和hash多块读取
oracle优化常用hint语句
oracle调优hint提示
原sql:
explain plan for
select * from (
select id id,ret_no retno, from_sys fromsy, to_sys tosys, command_code commandcode, command, status,
ext_code, orign_code origncode,error_message errormessage, re_f, ret_msg retmsg
from interface_table where ((command_code in('aasss')
   and  status in('f','e') and (re_f = 'n') and from_sys = 'mee')
   or (command_code in('xxxx','xxxx9') and from_sys = 'ext' and re_f = 'n')
   ) and mod(id, 1) = 0  order by id) where rownum
查看其执行计划:
select plan_table_output from table(dbms_xplan.display('plan_table'));
优化后的sql:
explain plan for
select * from (
select /*+ index(int_table ix_int_table_2)*/ id id,ret_no retno, from_sys fromsy, to_sys tosys, command_code commandcode, command, status,
ext_code, orign_code origncode,error_message errormessage, re_f, ret_msg retmsg
from interface_table where ((command_code in('aasss')
   and  status in('f','e') and (re_f = 'n') and from_sys = 'mee')
   or (command_code in('xxxx','xxxx9') and from_sys = 'ext' and re_f = 'n')
   ) and mod(id, 1) = 0 order by id) where rownum
查看其执行计划:
select plan_table_output from table(dbms_xplan.display('plan_table'));
比较:
查看执行计划,原来是使用 full scan - 当数据量大时非常慢;优化后oracle优先走range scan,hint 的 index 是未处理标识字段的索引,正常情况下这个数据集合相对较小--------所以可以达到优化目的。
具体情况具体分析,我们必须要看实际的表存的业务数据,分析其业务关系找到最小业务集合;后者要看懂执行计划,根据rows, bytes, cost, time 找到最优项目。这个分析顺序不能倒置。
问题:为何使用 rownum 后,oracle执行计划会走full scan?
本文永久更新链接地址:
其它类似信息

推荐信息