SQL SERVER 分页方式

 

use master
go
set nocount on
go
set showplan_text on
go
--2012的OFFSET分页方式
select number 
from spt_values
where type='p'
order by number offset 10 rows fetch next 5 rows only;
go
--2005的ROW_NUMBER分页方式
select number from (
select number,row_number() over(order by number) as num from spt_values where type='p'
) t where num between 11 and 15
order by number asc
go
--2000的TOP分页方式
select number from (
select top 5 number from (
select top 15 number from spt_values where type='p' order by number asc
) t
order by number desc
) t 
order by number asc
go
set showplan_text off
go

   从查询计划来看,2012的查询计划中,offset直接操作了top迭代器,分页计划十分简单,看起来也比后两种简单明了,而在系统预估的查询开销中,OFFSET占9%,ROW_NUMBER占45%,TOP占47%(加起来101% -_-||),OFFSET占了绝对的优势。

你可能感兴趣的:(SQL Server 2000,2005,2012)