大数据量分页(百万级别):
1.建立索引
2.分两次查询(两句sql)
3.扩展
1.select * from a where type=1 order by createdate limit 1000000,10
=> 建立一个复合索引(type,createdate)(反正要符合最佳左前缀)
注释:仍然存在的问题=>回表查询(注意select *...)导致大量数据的情况下查询效率仍然很慢
2.分为两句
=>
select id from a where type=1 order by createdate limit 1000000,10
select * from a where id in (第一句查询中的结果集) limit 1
注释:第一句所有使用的字段均为索引,并且避免回表查询(注意select * ...);第二句使用了主键索引
3.扩展自己使用执行计划分析一下
截图
0赞 · 0采集
笑春风_0003
2019-07-28
大表查询优化
截图
1赞 · 0采集
GrowingFox
2019-07-28
提高分页查询效率:
1. 增加索引.
2. select * 有索引依然慢
思路: 避免回表, 一分为二, 先找id, select id, 再根据id找出row内容 select * from table where id in (id_list)