存储过程优化mssql分页性能
MSsql分页效率: mysql分页,一般使用的方法有3中(这里不再重复),公认效率较好的是使用 id < min(id)的这一种,于是我平时也在使用这种。但在半年前,测试网站时,总感觉着分页显示速度跟理论值相差太大,于是做下面的测试:
msSQL2005 300万数据,mid,rid为索引。
在我的机器上比较明显(AMD1.4G。448M内存)
在公司比较好的服务器运行,这2种写法区别不出来——弱机器的优点在这里体现出来了。。
-------------写法1 (0秒) 巨快。
Declare @top2 int
select @top2=min(mid) from (select top 1 mid from [musicbox] where rid='87503' order by mid desc) as db2
SELECT top 20 mid,rid,mname,mauthor,madddate FROM [musicbox] as a where rid='87503' and a.mid <=@top2
-------------写法2 (40秒) 巨慢。
SELECT top 20 mid,rid,mname,mauthor,madddate FROM [musicbox] as a where rid='87503' and
a.mid <=(
select min(mid) from (select top 1 mid from [musicbox] where rid='87503' order by mid desc
) as db2)
order by mid desc
--------------------------

0 条评论:
发表评论
指向此帖子的链接:
创建链接
<< 主页