explain 各列含义¶
一、查看索引使用¶
二、列¶
id¶
select 序号。
select_type¶
SIMPLE / PRIMARY / SUBQUERY 等。
table¶
哪张表。
type¶
访问类型,性能从好到差:
- system > const > eq_ref > ref > range > index > ALL
ALL 就是全表扫描,要优化。
possible_keys¶
可能用的索引。
key¶
实际用的索引。
key_len¶
用了索引的长度。
rows¶
预估扫描行数。
Extra¶
- Using where:过滤。
- Using index:覆盖索引。
- Using filesort:额外排序,要优化。
- Using temporary:临时表,要优化。
三、重点关注¶
- type 不能 ALL。
- key 不是 NULL。
- Extra 不要 Using filesort/temporary。
一句话
type、key、rows、Extra 是重点。