请说明 MySQL EXPLAIN 输出中 id、type、key、rows、Extra 等关键字段的含义,以及哪些值代表性能隐患。
system > const > eq_ref > ref > range > index > ALL。
生产 SQL 出现 ALL(全表扫描) 或 index(扫全索引) 通常要优化;eq_ref/ref 表示通过索引定位。
- Using index:覆盖索引,无需回表,好;
- Using where:服务层再过滤;
- Using filesort:需要额外排序(order by 未走索引顺序),隐患;
- Using temporary:用了临时表(group by/distinct 常见),隐患;
- Using index condition:索引下推 ICP 生效。
题目与答案就在本页;收藏、批注和错题重练在应用内