MYSQL优化——索引覆盖

索引覆盖:如果查询的列恰好是索引的一部分,那么查询只需要在索引文件上进行,不需要进行到磁盘中找数据,若果查询得列不是索引的一部分则要到磁盘中找数据。

建表:

create table test_index(
id int primary key auto_increment,
name  char(10) not null default ``,
email  char(10) not null default ``,
index  c (`id`,`name`)
) engine = Innodb charset utf8;

insert into test_index (`name`,`email`) values ('datou','111@qq.com'); ,('datou','111@qq.com');

执行如下一条语句:

explain select id ,name from test_index ;

image

执行另一条语句看如何:

explain select id ,name ,email from test_index ;

image

原文地址:https://www.cnblogs.com/webph/p/6549285.html