MySQL进阶系列: 一文详解explain各字段含义,分层展示的架构图

本文详细解析MySQL的Explain工具,包括select_type、table、type等关键列的含义,帮助理解查询执行过程并进行性能优化。
摘要由CSDN通过智能技术生成

二,select_type列

============================================================================

主要用来分辨查询的类型,是普通查询还是联合查询还是子查询

1. sample: 简单的查询,不包含子查询和union

mysql> explain select * from emp;

  1. primary: 查询中若包含任何复杂的子查询,最外层查询则被标记为Primary

mysql> explain select * from emp e where e.deptno = (select d.deptno from dept d where d.dname = ‘SALES’);

  1. union: 在union,union all和子查询中的第二个和随后的select被标记为union

mysql> explain select * from emp where deptno = 10 union select * from emp where sal >2000;

4. dependent union: 在包含UNION或者UNION ALL的大查询中,如果各个小查询都依赖于外层查询的话,那除了最左边的那个小查询之外,其余的小查询的select_type的值就是DEPENDENT UNION。

mysql> explain select * from emp e where e.empno in ( select empno from emp where deptno = 10 union select empno from emp where sal >2000)

5. union result: 从union表获取结果的select。

mysql> explain select * from emp where deptno = 10 union select * from emp where sal >2000;

6. subquery: 在select或者where列表中包含子查询(不在from子句中)

mysql> explain select * from emp where sal > (select avg(sal) from emp) ;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值