查看 mysql 5.6 的执行计划
这里是针对 SELECT
语句的执行计划,执行计划优先看 type
字段,type
的效率从上到下性能越好,如下:
ALL
: 全表扫描index
: 索引全扫描range
: 索引范围扫描ref
: 非唯一索引扫描eq_ref
: 唯一索引扫描const,system
: 单表最多有一个匹配行NULL
: 不用扫描表或索引
接着再看 rows
,预计扫描的行数,越少越好。
最后再看看 Extra
,有出现 Using index
,或者 Using where; Using index
,或者 Using index condition
,效果都是相对较好的,如果出现 Using filesort
或者其他较少见过的值,都是需要 mysql 做额外的优化,具体的 Extra
可能出现的值,见官方文档 EXPLAIN Extra Information。
If you want to make your queries as fast as possible, look out for Extra column values of
Using filesort
andUsing temporary,
or, in JSON-formatted EXPLAIN output, forusing_filesort
andusing_temporary_table
properties equal to true.
MySQL 执行计划中Extra(Using where,Using index,Using index condition,Using index,Using where)的浅析