- 使用多表连接查询代替子查询
- 使用union 代替or
- 对于分页查询
--Mysql在进行分页查询时越往后效率越低 select * from student limit 1000000,10 --1.在索引上完成排序分页操作,最后根据主键关联回原表查询所需要的其他列内容 select a.* from student a, (select sid FROM student LIMIT 1000000, 10) b where a.sid = b.sid --2.先利用主键查找出分页区间,然后在进行分页操作 select * from student where sid > 1000000 limit 10
- 可以指定使用那个索引
--建议 select * from student use index(索引名) --忽略 select * from student ignore index(索引名) --强制 select * from student force index(索引名)
其他优化方向
最新推荐文章于 2024-07-03 10:00:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)