现在的位置: 首页 > 综合 > 正文

mysql分页查询

2018年01月09日 ⁄ 综合 ⁄ 共 450字 ⁄ 字号 评论关闭

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
经测试,一万条数据以内一般的分页作法比较快
超过一万条后优化过的作法优势就呈现出来
当数据量愈多,优化的分页查询速度愈快

抱歉!评论已关闭.