mysql分页查询

MySQL中一般的分页作法大多利用Limit限制回传的资料笔数来达成分页效果
例如下面的代码
Select * From news limit 0, 100第一页
Select * From news limit 100,100第二页
Select * From news limit 200,100第三页
今天突然来了一个思路
和前作上下页查询优化
的思路略同
定位到id值后再用id值作条件
优化的作法
第一页
Select * From news Where id >=(
Select id From news Order By id limit 0,1
) limit 100
第二页
Select * From news Where id >=(
Select id From news Order By id limit 100,1
) limit 100
第三页
Select * From news Where id >=(
Select id From news Order By id limit 200,1
) limit 100
经测试,一万条数据以内一般的分页作法比较快
超过一万条后优化过的作法优势就呈现出来
当数据量愈多,优化的分页查询速度愈快 本文来自Sqlclub

本篇文章来源于 SQL学习社区 原文链接:http://www.sqlclub.cn/Optimi/2009-04/2626.htm

你可能感兴趣的:(sql,mysql)