我正在使用以下模板进行分页查询:
select * from (select rownumber() over
( order by aaa.x ) as rownum, aaa.abc, aaa.bcd,bbb.cde from aaa as aaa
left join bbb on aaa.colx= bbb.coly where aaa.where1 = 'xxx'
) as tempresult where rownum between 101 and 200
假设页面大小为100个项目,则第一页查询将是相同的,替换rownum条件:
where rownum <= 100
我面临的情况是第一页表现非常好(&lt; 1s),但是当我们从第二页向前移动时,查询大约需要5-6秒。
其他信息:
答案 0 :(得分:2)
您需要查看两个查询&#39;执行计划,看看是否有任何差异 - 只有这可以给你一个明确的答案。
您可以尝试重写查询,如下所示:
select * from (
select rownumber() over ( order by aaa.x ) as rownum, aaa.abc, aaa.bcd
from aaa as aaa
where aaa.where1 = 'xxx'
) as tempresult
left join bbb on tempresult.colx= bbb.coly
and tempresult.rownum between 101 and 200
修改强>
在最终选择中,没有什么可以阻止您使用bbb
中的列:
select tempresult.*, bbb.cde
from (
select rownumber() over ( order by aaa.x ) as rownum, aaa.abc, aaa.bcd
from aaa as aaa
where aaa.where1 = 'xxx'
) as tempresult
left join bbb on tempresult.colx= bbb.coly
and tempresult.rownum between 101 and 200