For mysql execution plan can be added before the select Explain to implement, it can tell us how your statement performance.
The following is a detailed description of explain, are also official, a reference in the future.
id | SELECT identifier. This is a SELECT query sequence number |
select_type | SELECT type, which can be any of the following:
|
table | Output line table referenced |
type | Join type. Various types of coupling are given below, in accordance with the type ordered from best to worst type:
|
possible_keys | It indicates which indexes MySQL could use to find the rows in the table |
key | Display key (index) MySQL actually decided to use. If you do not select an index, the key is NULL. |
key_len | Display MySQL decided to use key lengths. If the key is NULL, the length is NULL. |
ref | Shows which columns or constants are selected together with a key from a table using the row. |
rows | Display the number of rows MySQL believes it must examine the query execution. Of data between a plurality of lines can be estimated by multiplying the number of rows to be processed. |
filtered | It shows the percentage of the estimated value of the number of rows filtered through conditions. |
Extra | This column contains the MySQL query to resolve details
|
type:这是重要的列,显示连接使用了何种类型。从最好到最差的连接类型为const、eq_reg、ref、range、index和ALL
type显示的是访问类型,是较为重要的一个指标,结果值从好到坏依次是:system > const > eq_ref > ref > fulltext > ref_or_null > index_merge > unique_subquery > index_subquery > range > index > ALL
一般来说,得保证查询至少达到range级别,最好能达到ref。
我们在进行条件查询时,建议使用索引,否则将引起全表扫描,IO的开销和程序的性能都没法保证!
对于mysql的执行计划可以在select前添加Explain来实现,它可以告诉我们你的语句性能如何。
下面是对explain的具体说明,也都是官方的,以后进行参考。
id | SELECT识别符。这是SELECT的查询序列号 |
select_type | SELECT类型,可以为以下任何一种:
|
table | 输出的行所引用的表 |
type | 联接类型。下面给出各种联接类型,按照从最佳类型到最坏类型进行排序:
|
possible_keys | 指出MySQL能使用哪个索引在该表中找到行 |
key | 显示MySQL实际决定使用的键(索引)。如果没有选择索引,键是NULL。 |
key_len | 显示MySQL决定使用的键长度。如果键是NULL,则长度为NULL。 |
ref | 显示使用哪个列或常数与key一起从表中选择行。 |
rows | 显示MySQL认为它执行查询时必须检查的行数。多行之间的数据相乘可以估算要处理的行数。 |
filtered | 显示了通过条件过滤出的行数的百分比估计值。 |
Extra | 该列包含MySQL解决查询的详细信息
|
type:这是重要的列,显示连接使用了何种类型。从最好到最差的连接类型为const、eq_reg、ref、range、index和ALL
type显示的是访问类型,是较为重要的一个指标,结果值从好到坏依次是:system > const > eq_ref > ref > fulltext > ref_or_null > index_merge > unique_subquery > index_subquery > range > index > ALL
一般来说,得保证查询至少达到range级别,最好能达到ref。
我们在进行条件查询时,建议使用索引,否则将引起全表扫描,IO的开销和程序的性能都没法保证!