mysql5.6.19下子查询为什么无法使用索引
作者:whsnow 时间:2024-01-15 01:04:29
表结构很简单
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行变化太大了,一个进行了完整的遍历,第一个使用了索引,造成差距过大,不过原因尚未找到,有哪位知道呢?
标签:子查询,索引
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解PHP结构型设计模式之桥接模式Bridge Pattern
2023-05-25 06:58:55
z-blog文章摘要图文混排
2009-02-28 13:49:00
![](https://img.aspxhome.com/file/UploadPic/20092/28/tagimg-64s.gif)
Python10行代码实现模拟百度搜索的示例
2022-07-19 17:10:57
![](https://img.aspxhome.com/file/2023/4/70844_0s.jpg)
Echarts实例教程之树形图表的实现方法
2024-04-18 09:44:01
![](https://img.aspxhome.com/file/2023/7/136287_0s.png)
NodeJs Express路由使用流程解析
2024-05-11 10:16:56
MySQL数据库锁机制的相关原理简介
2010-04-22 15:34:00
php线性表顺序存储实现代码(增删查改)
2023-11-19 06:51:53
python pandas遍历每行并累加进行条件过滤方式
2023-08-07 12:41:54
![](https://img.aspxhome.com/file/2023/8/117878_0s.jpg)
利用python读取YUV文件 转RGB 8bit/10bit通用
2023-09-05 08:33:19
4款Javascript放大镜特效脚本
2009-10-14 20:46:00
![](https://img.aspxhome.com/file/UploadPic/200910/14/javascript-9-7-6j-25s.jpg)
关于 MediaPlayer 播放器参数详解
2008-08-10 18:33:00
ASP常见数学函数 Abs Atn Cos 等详解
2008-05-28 12:33:00
MySQL 视图,第1349号错误
2008-05-18 13:04:00
python使用reportlab生成pdf实例
2022-09-13 09:36:42
![](https://img.aspxhome.com/file/2023/3/105033_0s.png)
解决vue组件中click事件失效的问题
2023-07-02 16:34:10
![](https://img.aspxhome.com/file/2023/4/139714_0s.jpg)
php获取当前页面完整URL地址
2024-05-13 09:20:56
数据库查询哪个对像里面包含什么字段方法语句
2024-01-24 10:32:56
Tensorflow自定义模型与训练超详细讲解
2023-09-19 10:18:00
![](https://img.aspxhome.com/file/2023/5/101425_0s.jpg)
sqlserver中去除字符串中连续的分隔符的sql语句
2024-01-24 02:45:51
Python iter()函数用法实例分析
2022-11-01 00:00:01