最初由 jimmylee 发布
[B]
我按照你的建议,将语句改为:
select a.rowid , a.MONI_TIME,a.MONI_TYPE,a.MONI_APERRCODE,a.MONI_CONSTANT,
SubStr(a.MONI_USERINFO,1,50) MONI_USERINFO
from cstmonilog2 a ,
(select rid from ( select rownum rno,rowid /*+ INDEX(cstmonilog2 index1 ) */ rid
from cstmonilog2
where MONI_AREA = '9'
and MONI_TYPEID = '1' and MONI_FLAG = '1'
and rownum <990035 -- 1
order by MONI_TIME ) -- 1
where rNo >=990000) b
where a.rowid=b.rid
order by a.moni_time
不知道是否正确。这个语句与lwxian的执行的时间基本一样,相互差别不超过20ms。所以没有明显的改善。另外你说的cursor方式如何去做?如何对最终的结果集排序? [/B]
The Statement given above has 4 problems at least:
1. the resultset is not what you want: the line mared with '--1' shows that the statement will cut down the result set to 990035 before order them. the resultset from this statement is uncertain. It will be diffrent according the indexes used or something else. Is it you want? I doubt.
2. the hints location is not proper. it should only be setted after select/update/insert directly except push_predicates. However, in this problem, it will use the index1 even you don't have hints in the subquery.
3. this statement added more logic while it actually not need. NESTED LOOP
4. why don't u use CBO. it should work much smarter in you problem.
but I aggree this statement has improved, it at lease omit the unnessary unique operation when using IN.
|