码迷,mamicode.com
首页 > 数据库 > 详细

sql分页性能测试结果

时间:2014-07-24 21:32:32      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   os   数据   re   c   

--方案一:

declare @d datetime
set @d = getdate()
select top 10 * from Info where ID not in (select top 9990 ID from Info order by ID) order by ID 
select [not in方法升序分页执行花费时间(毫秒)]=datediff(ms,@d,getdate()) --430ms

 

--方案二:

declare @s datetime
set @s = getdate()
select top 10 * from info where ID >=(select max(ID) from (select top 9991 ID from info order by ID) as T) order by ID
select [Max方法升序分页执行花费时间(毫秒)]=datediff(ms,@s,getdate()) --13ms


--方案三:

declare @q datetime
set @q = getdate()
select top 10 * from Info where ID <=(select min(ID) from (select top 9991 ID from Info order by ID desc) as T) order by ID desc
select [Min方法降序分页执行花费时间(毫秒)]=datediff(ms,@q,getdate())--10ms

 

--方案四:

declare @r datetime
set @r = getdate()
select top 10 * from 
( 
select row_number()over( order by id desc) as rowNumber,* from info

) T
where T.rowNumber>0 
select [row_number()方法降序分页执行花费时间(毫秒)]=datediff(ms,@r,getdate())--3ms

 

--方案五:

with infos as
(
select r.*, row_number()over(order by r.id desc) as r 
from [Info]  r
) 
select * from infos where r between 1 and 30;

方案五没有采取top的形式取数据,而是用了between,相同点都用了row_number()函数。根据平常的分页习惯,方案四、五效率最高,且性能相当.

sql分页性能测试结果,布布扣,bubuko.com

sql分页性能测试结果

标签:des   style   blog   color   os   数据   re   c   

原文地址:http://www.cnblogs.com/paulhe/p/3499920.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!