CREATE TABLE msg (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
msg_id bigint(20) NOT NULL,
status tinyint(4),
content text NOT NULL,
create_time datetime NOT NULL,
PRIMARY KEY (id),
KEY idx_msg_id (msg_id)
) ENGINE=InnoDB AUTO_INCREMENT=3048 DEFAULT CHARSET=utf8mb4
select id from msg where msg_id = #{param1} order by id desc limit 10;
显示走了 idx_msg_id 索引,extra 是 Using where; Using index 。 去掉 order by id 后 ,extra 是 Using index 。
PS:默认索引扩展 use_index_extensions=on
Q:既然 idx_msg_id 索引上有 id,且 select 只查询 id,order by id 为何会导致出现 Using where;
附上 mysql 官方文档:https://dev.mysql.com/doc/refman/5.7/en/index-extensions.html 看完也没弄明白。