Home > Database > Mysql Tutorial > body text

使用hint优化Oracle的执行计划

WBOY
Release: 2016-06-07 16:49:58
Original
1367 people have browsed it

背景: 某表忽然出现查询非常缓慢的情况,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?

本文永久更新链接地址:

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template