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

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
Intezer
C
Cyber Attacks, Cyber Crime and Cyber Security
The Register - Security
The Register - Security
量子位
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
MyScale Blog
MyScale Blog
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
Jina AI
Jina AI
博客园 - 【当耐特】
P
Palo Alto Networks Blog
Last Week in AI
Last Week in AI
SecWiki News
SecWiki News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
G
GRAHAM CLULEY
宝玉的分享
宝玉的分享
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
有赞技术团队
有赞技术团队
T
Tor Project blog
H
Hacker News: Front Page
A
Arctic Wolf
NISL@THU
NISL@THU
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
V
V2EX
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
I
InfoQ
D
Docker
L
LINUX DO - 最新话题
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42

博客园 - 菜鸟吴迪

Lucene搜索结果排序问题(按时间倒序排的替代解决方法) 利用Lucene.net搜索引擎进行多条件搜索的做法 (转) (转)Razor引擎学习:RenderBody,RenderPage和RenderSection 读取txt文本,批量插入到数据库中! ASP.NET MVC3 返回多个实体或泛型 MySQL数据库集群Master-Slave模式安装摘要 使用HtmlAgilityPack批量抓取网页数据 Jquery each - 菜鸟吴迪 - 博客园 堆?栈?(转) 数据库并发控制!!! Velocity脚本简明教程 Visual Studio的调试技巧 《C#与.NET3.5高级程序设计(第4版)》笔记10 sql查询连续三天之内都有记录的人员!! Asp.net Mvc Controller接收可控的数组或字典类型的实现方法: SELECT INTO 和 INSERT INTO SELECT 两种表复制语句 (转) httpContext里面的东西!!! c#闭包!! c#新特性!!!
sql分页问题,老话题!!
菜鸟吴迪 · 2010-09-13 · via 博客园 - 菜鸟吴迪

老话题了,主要是看下测试数据,不同数量级的效率是不一样的,具体差别很大滴!!,看许多人都说是row number效率最低,但是本人测试结果有点出入。10万级别的基本没啥差距,百万级别的差距不是太明显,但是not in变慢,千万级别的差距就很明显了,not in明显跟不上了。总体比较而言,还是max(id)效率最高,但是不通用。row number比较通用。

PS:上亿的就别玩了,还是分表吧!!

方法1:
适用于 SQL Server 2000/2005

SELECT TOP 页大小 *
FROM table1
WHERE id NOT IN
          (
          
SELECT TOP 页大小*(-1) id FROM table1 ORDER BY id
          )
ORDER BY id

方法2:
适用于 SQL Server 2000/2005

SELECT TOP 页大小 *
FROM table1
WHERE id >
          (
          
SELECT ISNULL(MAX(id),0
          FROM 
                (
               
SELECT TOP 页大小*(-1) id FROM table1 ORDER BY id
                ) 
A
          )
ORDER BY id

方法3:
适用于 SQL Server 2005

SELECT TOP 页大小 * 
FROM 
        (
        
SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNumber,* FROM table1
        ) A
WHERE RowNumber > 页大小*(页数-1)

每页20条记录,取第10000条以后的

表结构:id(int)  name(varchar) insertTime(datetime)

测试数据:10万级别的数据

 

三种方式几乎没有区别。

2百万级别

第一种方法:

第二种方法:

第三种方法:

3千万级别

第一种:

第二种:

第三种: