mysql explain的bug

通过对Zabbix监控数据的分析,采用SQL查询优化的方法来评估Hadoop集群中Impala的内存使用情况。通过将子查询转换为多表连接的方式显著提高了查询效率。

最近在做hadoop集群的容量数据,主要依据zabbix的监控数据,因为要计算impala的内存使用情况,就使用了下面的sql

1
2
3
4
5
6
7
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:

1
2
3
4
5
6
7
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啊。。。



本文转自菜菜光 51CTO博客,原文链接:http://blog.51cto.com/caiguangguang/1369797,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值