EXPLAIN语句提供了有关 MySQL 如何执行语句的信息,EXPLAIN适用于 SELECT, DELETE, INSERT, REPLACE 和 UPDATE语句;当EXPLAIN与可解释的语句一起使用时,MySQL 会显示来自优化器的有关语句执行计划的信息。
id 列
id是select查询的序列号,sql按照id从大到小执行,id相同的为一组,从上到下执行。
# 查询顾客的email、地址
select customer_id, email, a.address
from customer c
left join address a on c.address_id = a.address_id;
# 查询支付次数最多的顾客的email
select customer_id, email
from customer
where customer_id = (select customer_id
from payment
group by customer_id
order by count(*) desc
limit 1);
id | select_type | table | Extra | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
2 | SUBQUERY | payment | NULL | Index | 16086 | 100 | 2 | index | idx_customer_id | idx_customer_id | Using index; Using temporary; Using filesort |
select_type