EXPLAIN语句提供了有关 MySQL 如何执行语句的信息,EXPLAIN适用于 SELECT, DELETE, INSERT, REPLACE 和 UPDATE语句;当EXPLAIN与可解释的语句一起使用时,MySQL 会显示来自优化器的有关语句执行计划的信息。

tex-img-1

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);

tex-img-3

idselect_typetable Extra
2SUBQUERYpaymentNULLIndex160861002indexidx_customer_ididx_customer_idUsing index; Using temporary; Using filesort

select_type

最后修改:2022 年 12 月 08 日
如果觉得我的文章对你有用,请随意赞赏