Mysql问题总结
1、分页查询优化
分页查询徒弟列表:
select * from user_friends where master_id = #{masterId} and status = #{status} order by create_time desc limit #{start},#{pageSize}
使用limit offset,size的方式,查询页数越靠后查询速度会越慢,应该加查询条件来减少扫描的数据量,如查询水滴明细:
select * from " + DbMaintainJob.WATER_INCOME + "${date} where user_id = #{userId} and create_time < #{lastTime} order by create_time desc limit 10
通过create_time来过滤掉一些数据。
参考文章:https://www.toutiao.com/i6830723067849736716/?tt_from=weixin&utm_campaign=client_share&wxshare_count=1×tamp=1598075612&app=news_article&utm_source=weixin&utm_medium=toutiao_ios&use_new_style=1&req_id=202008221353320100140472080E08C9B8&group_id=6830723067849736716
2、explain字段含义
参考文章:https://www.cnblogs.com/xujunkai/p/12491583.html