
select_type
包括范围: simple. primary,subquery, derived, union, union result 查询类型主要是用于区别普通查询,联合查询,子查询等复杂的查询
-
simple,简单的select 语句,查询中不包含自查询或者 union
-
primary, 查询若包含任何复杂的子部分,最外层查询则被标记为primary
-
subquery, 在 select 或 where 列表中包含子查询
-
derived,在 from 列表中包含自查询被标记为 derived (衍生)MySQL 会递归执行这些自查询,把结果放在临时表中。
-
union,若第二个 select 出现在 union 之后,则被标记为 union. 若 union 包含在 from 子句子查询中,外层 select 将别标记为 derived
-
union result, 从 union 表中获取结果的 select
table
- 这行数据是关于那种表的
type
类型: all , index , range, ref, eq_ref, const, system ,null type 显示的是防卫类型,是较为重要的一个指标,结果从好到坏依次是: system > count > eq_ref > range > index > all
sytem > const > eq_ref > ref > fulltext > ref_or_null > index_merge >> unique_subquery > index_subquery > range > index > ALL
system
表只有一行记录(等于系统表),这是 const 类型的特列, 平时不会出现,这个也可以忽略不计
count
explain select * from (select * from t1 where id =1) d1;
表示通过索引一次就找到了, const 用于比较 primary key 或者 unique 索引。 因为只匹配一行数据,所以很快如将主键置于where 列表中, MySQL 就能将该查询转换为一个常量。

eq_ref
explain select * from t1, t2 where t1.id = t2.id
唯一性索引扫描,对于每个索引键,表中只有一条记录与之匹配。常见于主键或唯一索引扫描. 查询案例:

ref
tb_emp ddl
CREATE TABLE tb_emp (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(30) DEFAULT NULL,
dept_id int(11) DEFAULT NULL,
PRIMARY KEY (id),
) ;
#员工表添加年龄列
alter table tb_emp add column age int(11) default null after name;
#添加复合索引
create index idx_emp_name_age on tb_emp(name, age);
explain select * from t

最低0.47元/天 解锁文章
495

被折叠的 条评论
为什么被折叠?



