3种分页方式,分别是max方案,top方案,row方案
效率:
第1:row
第2:max
第3:top
缺点:
max:必须用户编写复杂Sql,不支持非唯一列排序
top:必须用户编写复杂Sql,不支持复合主键
row:不支持sqlServer2000
测试数据:
共320万条数据,每页显示10条数据,分别测试了2万页、15万页和32万页。
页码,top方案,max方案,row方案
2万,60ms,46ms,33ms
15万,453ms,343ms,310ms
32万,953ms,720ms,686ms
具体操作SQL代码如下 :
TOP:
select top 10 * from Table1
where Id not in(select top 开始的位置 Id from Table1)
MAX:
select top 10 * from Table1
where Id>(select max(Id)
from (select top 开始位置 Id from Table1order by Id)tt)
ROW:
select *
from (
select row_number()over(order by tempColumn)tempRowNumber,*
from (select top 开始位置+10 tempColumn=0,* from Table1)t
)tt
where tempRowNumber>开始位置