sql - 有没有办法在 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 亿行。
任何想法?任何提示都受到高度赞赏。
解决方案
我的第一个想法是order by
从用于创建最终表的最后一个查询中删除该子句。这个操作真的很昂贵,而且考虑到数据不会被顺序读取,因此它不会增加任何价值,因此您不会从中获得任何收益。
可能有其他方法可以实现相同的查询,如果您可以解释您尝试解决的问题而不是用于解决它的查询,这将很有用。
推荐阅读
- java - 使用 groovy-maven-plugin 时,Groovy 不会将闭包转换为 BiPredicate
- mongodb - MongoDb:查询数组字段
- c# - 实体框架数据库优先 - 没有主键的表
- python - QIODevice::read (QProcess): 设备未打开
- php - MySQLi:选择所有不在用户登录好友数组中的用户
- c# - 将新颜色对象添加到颜色类 c# wpf
- javascript - 单击其中的锚链接时,如何使导航栏停止消失?为什么这样做?
- django - 使用 React 前端和 Django REST 框架后端部署网站
- java - Camera2 媒体记录器 | 音频和视频正在异步录制
- c# - Task.Run() 代码是否异步执行?