首页 > 解决方案 > 有没有办法在 Impala 中优化这个查询的性能?

问题描述

此查询涉及 4 个表,需要 10.5 小时才能完成:

步骤1:

create table temp partitioned by (date_pull) stored as parquet as
select <fields>
from trans_ext -- this is the base table
inner join [shuffle] ac  -- fact_acc
inner join [shuffle] c  --related_acc
left join dt --trx_type 

表的行数统计信息:

trans_ext: 8,289,244,895 (72 partitions)
ac: 985,164,794 (1 partitions)
c: 17,496,531 (1 partition)
dt 4: 369 (1 partition)

步骤 2:从 temp 创建一个计数表 h

select related_cust, count(*) as ct from temp group by related_cust;

第 3 步:通过内连接计数表创建最终表并应用 where 子句

select t.* 
from temp t
inner join [shuffle] h on h.related_cust=t.related_cust
where  t.related_cust is not null
and h.ct <=1000000
order by t.related_cust;

我在想如何消除计数表并直接创建最终结果?最终表大小:196 亿行。

任何想法?任何提示都受到高度赞赏。

标签: sqlperformanceimpala

解决方案


我的第一个想法是order by从用于创建最终表的最后一个查询中删除该子句。这个操作真的很昂贵,而且考虑到数据不会被顺序读取,因此它不会增加任何价值,因此您不会从中获得任何收益。

可能有其他方法可以实现相同的查询,如果您可以解释您尝试解决的问题而不是用于解决它的查询,这将很有用。


推荐阅读