暂无图片
关于8.0中,Using filesort 提示,但是使用了索引,
我来答
分享
暂无图片 匿名用户
关于8.0中,Using filesort 提示,但是使用了索引,

create table `test_order` (
`id` int not null auto_increment comment 'id',
`a` int unsigned not null default '0',
`b` int unsigned not null default '0',
`c` varchar(64) not null default '',
`d` int default null,
primary key (`id`),
key `idx_a_b_c` (`a`,`b`,`c`),
key `idx_d` (`d`)
)


mysql> explain select * from test_order where a = 100 order by c\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: test_order
partitions: NULL
type: ref
possible_keys: idx_a_b_c
key: idx_a_b_c
key_len: 4
ref: const
rows: 1
filtered: 100.00
Extra: Using filesort

不理解,明明走了索引,怎么还是filesort??

我来答
添加附件
收藏
分享
问题补充
1条回答
默认
最新
伟鹏

在这个查询中,虽然使用了索引idx_a_b_c,但是由于在查询结果中需要对c列进行排序,所以MySQL无法避免使用filesort。
导致出现filesort的原因是没有遵循最左前缀原则,你可以把sql改写成如下,就不会走filesort。

explain select * from test_order where a = 100 order by b,c\G
暂无图片 评论
暂无图片 有用 1
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏