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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM