mysql 5.7.21 linux 6.8
福布斯gb59,com的小李经理LRtc520999建立一个组合索引,在查询的时候不使用这个这个组合索引的前导列进行查询但还是走索引,请教各位!
show create table t;
±------±---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
±------±---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t | CREATE TABLE t
(
name
varchar(20) DEFAULT NULL,
age
int(29) DEFAULT NULL,
local
varchar(30) DEFAULT NULL,
KEY xxxx
(name
,age
,local
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
±------±---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
select count() from t;
±---------+
| count() |
±---------+
| 10000 |
±---------+
explain select name from t where local=‘xx33’;
±—±------------±------±-----------±------±--------------±-----±--------±-----±------±---------±-------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
±—±------------±------±-----------±------±--------------±-----±--------±-----±------±---------±-------------------------+
| 1 | SIMPLE | t | NULL | index | NULL | xxxx | 61 | NULL | **61 | 10.00 | Using where; Using index |
±—±------------±------±-----------±------±--------------±-----±--------±-----±------±---------±-------------------------+