大数据量的分页查询优化方案
背景
随着业务发展越来越快,原来的数据从几万突破到几百万,分页的查询策略是否需要调整一下?
数据准备
1、表名:order_history
2、描述:某个业务的订单历史表
3、主要字段:unsigned int id,tinyint(4) int type
4、字段情况:该表一共37个字段,不包含text等大型数据,最大为varchar(500),id字段为索引,且为递增。
5、数据量:5709294
6、MySQL版本:5.7.16
select count(*) from orders_history;
返回结果:5709294
三次查询时间分别为:
◾8903 ms
◾8323 ms
◾8401 ms
一般我们会这么做
select * from orders_history where type=8 limit 1000,10;
select * from orders_history where type=8 order by id limit 10000,10;
三次查询时间分别为:
◾3040 ms
◾3063 ms
◾3018 ms
针对这种查询方式,下面测试查询记录量对时间的影响:
select * from orders_history where type=8 limit 10000,1;
<

本文探讨了大数据量下分页查询的效率问题,通过对比不同查询策略,提出了使用id定位和id范围查询的方法,显著提高了查询速度。

2319

被折叠的 条评论
为什么被折叠?



