惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog
WordPress大学
WordPress大学
Jina AI
Jina AI
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
N
Netflix TechBlog - Medium
腾讯CDC
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
Google DeepMind News
Google DeepMind News
月光博客
月光博客
博客园 - Franky
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Martin Fowler
Martin Fowler
雷峰网
雷峰网
小众软件
小众软件
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - BB_Coder

rsync --include-from --exclude-from的理解 CruiseControl 安装配置 使用Common.Logging+log4net规范日志管理 我也表达式一回 sqlserver2005系统表、视图研究2 SQLServer2005新分页方法 关于SQLServer的小技巧 应该多了解一些工具 正则表达式网上学习资料 用最简单的方法实现Ajax - BB_Coder - 博客园 关于onMouseOver出现提示文字的多行处理办法 验证码缓存问题完美解决方案 由于登录失败而无法启动服务的解决方案 邮件发送不成功的问题 最近项目是跟框架有关的两个问题 自己写的一些小函数.用正则表达式实现一些小功能~ 数据库还原后连接不上 未与信任 SQL Server 连接相关联 IIS配置问题:出现了Failed to access IIS metabase的错误
三种SQL分页方法性能分析
BB_Coder · 2009-03-20 · via 博客园 - BB_Coder

--下面是三种分页方法性能测试。
--与网上所说的测试结果不一致
--(网上有人认为颠倒顺序top法 性能要比Row_number函数编号分页法要快10倍。。。)
--测试的表只有3000多行数据这可能是个问题

set statistics profile on
set statistics io on
set statistics time on
go

--第一名
--Row_number函数编号分页法(SQLServer新提供的函数)
--按SQLServer每一步的执行过程来看:
--用Row_number分页的执行过程步骤要比用top分页的执行步骤要多
--但用Row_number分页第三步(前两步是一样的是结果集的查询)
----也就是分页开始后的开销基本上等于0。
----可能是row_Number函数在查询的结果集上建了一个索引。
--而用top如果排序不是按索引来排的话每次排序都会花费不少时间
select * from (
select
--top 3020 --加不加top执行过程是一样的。。。
ROW_NUMBER()over(order by ProductCode DESC ) as rowNum,*
from Clothes where Sex='男')
results
--where rowNum between 3001 and 3020
--改成下面的写法要快一些。上面的写法在实际执行的时候是与下面写法执行是一样的。
where rowNum >= 3001 and rowNum <= 3020

--第二名
--用颠倒顺序top法
select * from (
select top 20 * from (
select top 3020 *
from Clothes where Sex='男'
order by ProductCode DESC
) pageResult order by ProductCode ASC )
pageSort order by ProductCode DESC

--第三名
--用top加outer join 法执行12步
select toPage.* from
(
select top 3020 *
from Clothes where Sex='男'
order by ProductCode DESC
)
toPage
left outer join
(
select top 3000 * from Clothes where Sex='男'
order by ProductCode DESC
) before
on toPage.clothescode=before.clothescode
where before.clothescode is null

go
set statistics profile off
set statistics io off
set statistics time off