覆盖索引---MyISAM 与 InnoDB
2017-10-08 00:23
441 查看
覆盖索引—MyISAM 与 InnoDB
如果索引包含满足查询的所有数据,就称为覆盖索引。覆盖索引是一种非常强大的工具,能大大提高查询性能。只需要读取索引而不用读取数据有以下一些优点:
(1)索引项通常比记录要小,所以MySQL访问更少的数据;
(2)索引都按值的大小顺序存储,相对于随机访问记录,需要更少的I/O;
(3)大多数据引擎能更好的缓存索引。比如MyISAM只缓存索引。
(4)覆盖索引对于InnoDB表尤其有用,因为InnoDB使用聚集索引组织数据,如果二级索引中包含查询所需的数据,就不再需要在聚集索引中查找了。
覆盖索引不能是任何索引,只有B-TREE索引存储相应的值。而且不同的存储引擎实现覆盖索引的方式都不同,并不是所有存储引擎都支持覆盖索引(Memory和Falcon就不支持)。
对于索引覆盖查询(index-covered query),使用EXPLAIN时,可以在Extra一列中看到“Using index”。
MyISAM
create table people( pid int not null auto_increment, pname varchar(50) not null, age int not null, primary key (pid), key (pname) ) engine MyISAM; insert into people (pname,age) values ('a',11); insert into people (pname,age) values ('b',12); insert into people (pname,age) values ('c',13);
explain select pid, pname from people where pname='a';
InnoDB
create table man( mmid int not null auto_increment, mname varchar(50) not null, mage int not null, primary key (mmid), key (mname) ) engine InnoDB; insert into man (mname,mage) values ('a',11); insert into man (mname,mage) values ('b',12); insert into man (mname,mage) values ('c',13);
explain select mmid, mname from man where mname='a';
通过上面的结果对比可以看出InnoDB用到了覆盖索引而MyISAM没有!!!
相关文章推荐
- mysql索引覆盖之innodb和myisam效率问题
- <转>MyISAM和InnoDB的索引实现
- MySQL原理研究:myisam和innodb索引实现的不同
- myisam与innodb索引比较
- MySQL中myisam和innodb的主键索引有什么区别?
- MyISAM和InnoDB索引引擎的B+树索引实现
- MySQL的MyISAM与InnoDB的索引方式
- Myisam索引和Innodb索引的区别
- MySQL8.0的InnoDB和MyISAM是否支持hash索引
- MySQL中myisam和innodb的主键索引有什么区别?
- MySQL在Innodb和MyISAM中的二级索引
- MyISAM和InnoDB的索引在实现上的不同
- MyISAM 和InnoDB 的区别.(存储,索引, 事务, 锁)
- 8.3.7 InnoDB and MyISAM Index Statistics Collection InnoDB 和MyISAM 索引统计信息搜集
- MySQL8.0的InnoDB和MyISAM是否支持hash索引
- B树和B+树 及 MyISAM和InnoDB存储引擎的B+树存储索引的实现
- MySQL中myisam和innodb的主键索引有什么区别?
- MyISAM和InnoDB的索引在实现上的不同
- MyISAM和InnoDB索引实现对比
- 深入浅出分析MySQL MyISAM与INNODB索引原理、优缺点分析