explain
深入理解explain
sql执行计划详解
联合索引
explain得到的字段含义:
- id: 值越大先被执行,值相同从上到下。
- select_type
- simple
- primary+subquery+derived(from之后的派生表) 嵌套类型
- union+union result
- table
- type
- system: 表中只有一行数据
- const: where中是primary/unique key,且只选一行
- eq_ref:也常见于primary/unique key扫描
- ref:普通索引或者唯一索引的部分前缀,可匹配多行
- range: 检索给定范围的行,用索引匹配
- index: 遍历索引树
- all:遍历全表
- possible keys
- key
- key_len:使用索引的长度(表中定义得到)
- ref:表查找值所用的列或常量
- rows:找到所需记录,所要读取的行数
- extra:
- using filesort: 对数据使用一个外部的索引排序,即无法用表中的索引order by
- using temporary: 用了临时表
- using index: 使用了covering index(覆盖索引),无需回表。如果同时出现using where,说明索引用来查找