1
當我有一個在整個select語句中重複多次的複雜子查詢時,在Hive中構建/寫入查詢的最佳方式是什麼?配置單元 - 如何在配置單元中以最優性能重用子查詢
我最初爲每次運行前刷新的子查詢創建了一個臨時表。然後,我開始使用CTE作爲原始查詢的一部分(丟棄臨時表)以提高可讀性並注意到性能下降。這讓我很好奇哪些實現方法在需要重新使用子查詢時的性能方面是最好的。
我正在使用的數據包含超過1000萬條記錄。以下是我使用CTE編寫的查詢的一個示例。
with temp as (
select
a.id,
x.type,
y.response
from sandbox.tbl_form a
left outer join sandbox.tbl_formStatus b
on a.id = b.id
left outer join sandbox.tbl_formResponse y
on b.id = y.id
left outer join sandbox.tbl_formType x
on y.id = x.typeId
where b.status = 'Completed'
)
select
a.id,
q.response as user,
r.response as system,
s.response as agent,
t.response as owner
from sandbox.tbl_form a
left outer join (
select * from temp x
where x.type= 'User'
) q
on a.id = q.id
left outer join (
select * from temp x
where x.type= 'System'
) r
on a.id = r.id
left outer join (
select * from temp x
where x.type= 'Agent'
) s
on a.id = s.id
left outer join (
select * from temp x
where x.type= 'Owner'
) t
on a.id = t.id;