欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

[MySQL] 联合索引与using index condition

程序员文章站 2022-04-15 16:56:04
1.测试联合索引的最左原则的时候, 发现了5.6版本后的新特性Index Condition Pushdown 2.含义就是存储引擎层根据索引尽可能的过滤数据,然后在返回给服务器层根据where其他条件进行过滤 3.比如我有这样的联合索引 KEY `name_gid_age_index` (`nam ......

1.测试联合索引的最左原则的时候, 发现了5.6版本后的新特性index condition pushdown

2.含义就是存储引擎层根据索引尽可能的过滤数据,然后在返回给服务器层根据where其他条件进行过滤

3.比如我有这样的联合索引 key `name_gid_age_index` (`name`,`gid`,`age`) , 查询的时候where name='taoshihan' and age=1 , 没有按顺序连续查条件, 后面那个age就用不到索引

4.这时就会出现下面的情况

create table `index_test` (
  `id` int(10) unsigned not null auto_increment,
  `name` varchar(100) not null default '',
  `gid` int(11) not null default '0',
  `age` int(11) not null default '0',
  `score` int(10) unsigned not null default '0',
  primary key (`id`),
  key `name_gid_age_index` (`name`,`gid`,`age`),
  key `score_index` (`score`)
) engine=innodb auto_increment=4 default charset=utf8

[MySQL] 联合索引与using index condition

5. type值为range、 ref、 eq_ref或者ref_or_null的时候 , 会使用到索引条件下推技术