mysql explain的bug 推荐
2014-03-07 13:40
309 查看
最近在做hadoop集群的容量数据,主要依据zabbix的监控数据,因为要计算impala的内存使用情况,就使用了下面的sql
考虑到sql的性能优化,就把上面的查询写成了3个表的join:
这样性能就好多了。。
其实这是explain的一个bug,在使用subquery时,explain会在后台执行这个sql,这样explain的时间就差不多是sql运行的时间了。。。
看来自己的sql写得太烂了,以后还是要多多的explain啊。。。
select a.host,avg(b.value) from (select a.host,b.itemid,b.key_ from hosts a,items b where a.hostid=b.hostid and a.host like '%hadoop-datanode%' and b.key_='impala.get[mem]')a join (select itemid,clock,value from history) b on a.itemid=b.itemid and b.clock between unix_timestamp('2014-02-28 00:00:00') and unix_timestamp('2014-03-06 00:00:00') group by a.host;在使用explain时发现巨慢,一个生成执行计划的操作都这么慢?
考虑到sql的性能优化,就把上面的查询写成了3个表的join:
select a.host,avg(c.value) from hosts a,items b,history c where a.hostid=b.hostid and a.host like '%hadoop-datanode%' and b.key_='impala.get[mem]' and b.itemid=c.itemid and c.clock between unix_timestamp('2014-02-28 00:00:00') and unix_timestamp('2014-03-06 00:00:00') group by a.host;
这样性能就好多了。。
其实这是explain的一个bug,在使用subquery时,explain会在后台执行这个sql,这样explain的时间就差不多是sql运行的时间了。。。
看来自己的sql写得太烂了,以后还是要多多的explain啊。。。
相关文章推荐
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜
- MySQL 备份与恢复
- MySQL 优化
- MySQL 数据类型
- Facebook's New Real-time Messaging System: HBase to Store 135+ Billion Messages a Month
- MySQL复制