oracle分页查询慢
一张新闻表,有100多万条记录
用下列分页查询
select a2*
from (select rownum rsn,a1.*
from ( select id,title,sort,updt
from news
where sort = 1111
order by updt desc) a1
) a2
where a2.rsn < 10
sort updt 都创建了索引
查询这个表每次要8秒左右,是什么原因?
------解决方案-------------------- sort updt 都创建了索引,id,title建索引了么
------解决方案-------------------- 换成<=,然后排序是否可以放外面或者不要
------解决方案-------------------- 引用: 主要用于 第2页等,
select a2*
from (select rownum rsn,a1.*
from ( select id,title,sort,updt
from news
where sort = 1111
order by updt desc) a1
) a2
where a2.rsn > 10 and a2.rsn < 20
Quote: 引用:
你这语句写的。。。嵌套写的有何用。
试试
select a1.*
from ( select id,title,sort,updt
from news
where sort = 1111
order by updt desc) a1 where rownum <10
第二页也不该这样写,效率很慢
你那种方法是把> 和<都放最外面。你试试这个
select a1.*
from ( select id,title,sort,updt ,rownum rn
from news
where sort = 1111
and rownum<20
order by updt desc) a1 where rn>=10 ------解决方案-------------------- 楼主现在里面筛选一层。这个sql通用(嵌套)!
select a2.*
from (select rownum rsn, a1.*
from (select id,title,sort,updt
from base_student
where sort = 1111