mysql SQL优化的常用手段有哪些?

发布时间 2023-10-20 10:42:55作者: 大树2

mysql SQL优化的手段有哪些?

1.explain 输出执行计划
2.in 和 not in 要慎用
3.少用select *
4.where 及 order by涉及的列上建立索引,如果排序字段没有用到索引,就尽量少排序
5.可以在程序中排序。
6.where 子句中避免is null /is not null,
7.应尽量避免在 where!=或<> or,函数操作,%xxx式查询
8.尽量用union all代替union
9.可以选择 exists 代替 in
10.高效的分页select id,name,age from user id>10000 limit 20 丢弃查询前面10000条只需20条
11.join表不易超过3个、小表驱动大表
12.使用多列索引时主意顺序和查询条件保持一致,同时删除不必要的单列索引.