首页 > 其他分享 >explian type extra补充

explian type extra补充

时间:2024-09-19 18:46:09浏览次数:1  
标签:name extra -- 索引 user explian type id

drop table  if EXISTS user;
create table user(
	id int primary key,name VARCHAR(20),age int
);
insert into user values (1,'xz',10),(2,'xz2',12);

-- innodb主键id聚集索引,数据和索引放到一块存储
-- 不会发生回表查询,即使extra=null,
-- type=const,extra=null
explain select * from user where id=1;

-- type=ALL,extra=Using where
-- 发生回表查询,where筛选条件不是索引列
-- 查询条件name不是索引列
explain select id,name from user where name='xz';

-- name索引
create index idx_name on user(name);
-- type=ref,extra=Using index
-- 索引覆盖,不会回表查询
explain select id,name from user where name='xz';

-- type=ref,extra=null
-- extra=null这意味着用到了索引,但是部分字段未被索引覆盖,
-- 必须通过“回表”来实现,不是纯粹地用到了索引,也不是完全没用到索引,Extra中为NULL。
explain select id,name,age from user where name='xz';

标签:name,extra,--,索引,user,explian,type,id
From: https://www.cnblogs.com/goodluckxiaotuanzi/p/18421146

相关文章