当前位置: 移动技术网 > IT编程>数据库>Mysql > mysql5.6.19下子查询为什么无法使用索引

mysql5.6.19下子查询为什么无法使用索引

2017年12月12日  | 移动技术网IT编程  | 我要评论

表结构很简单

create table `oplogs` (
`id` int(10) unsigned not null auto_increment,
`kind` varchar(45) not null default '',
`op` varchar(100) not null,
`user` varchar(25) not null default '',
`ip` varchar(16) not null default '',
`updatetime` timestamp not null default current_timestamp on update current_timestamp,
primary key (`id`)
) engine=myisam auto_increment=34896 default charset=utf8 row_format=fixed

结果有34895条

sql查询语句为:

select a.id,a.kind,a.op,a.user,a.ip,a.updatetime from oplogs as a inner join(select id from oplogs where 1 order by id desc limit 0,20) as b using(id)

在5.6.19情况下

用php读取内容并显示

首次显示结果需要3.5秒

但是同样的配置

在linux 下 5.5.38下

只需要0.7秒左右

很奇怪的情况

然后在5.6下执行了explain 结果如下:

而同样的数据 explain 结构如下:

比较结果很明显 主要在于对oplogs进行排序时,rows行变化太大了,一个进行了完整的遍历,第一个使用了索引,造成差距过大,不过原因尚未找到,有哪位知道呢?

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网