2021-03-31
msyql前导列索引问题
我建立一个组合索引,在查询的时候不使用这个这个组合索引的前导列进行查询但还是走索引,请教各位!
-----------------------------------------------------------+
| Table | Create Table |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t | CREATE TABLE `t` (
`name` varchar(20) DEFAULT NULL,
`age` int(29) DEFAULT NULL,
`local` varchar(30) DEFAULT NULL,
KEY `xxoo` (`name`,`age`,`local`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
select count(*) from t;
+----------+
| count(*) |
+----------+
| 10000 |
+----------+
1 row in set (0.02 sec)
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 | xxoo | 61 | NULL | 10161 | 10.00 | Using where; Using index |
+----+-------------+-------+------------+-------+---------------+------+---------+------+-------+----------+--------------------------+
1 row in set, 1 warning (0.00 sec)
我来答
添加附件
收藏
分享
问题补充
3条回答
默认
最新
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
墨值悬赏

评论

