impala 的 view 或 with 子句是否只计算一次并在查询中多次使用?
Would view or with clause of impala just compute once and be used multiple times in a query?
with core as (
select
t1.a,
t1.b,
t2.c
from
test_1 t1
join
test_2 t2 on t1.a = t2.a
where
t1.b = 'test'
)
,tmp_1 as (
select a,count(1) from core group by a
)
,tmp_2 as (
select b,count(1) from core group by b
)
select
t1.a,
t1.count,
t2.count
from
tmp_1 t1
join
tmp_2 t2 on t1.a=t2.b
我的问题是,上述查询中的 core
CTE 是否只计算一次?或者在 tmp_1
和 tmp_2
两个 CTE 中,我在 documentation of impala,
中找不到线索
截至目前,使用 Impala 和 Hive 的当前版本,
查询中的核心 CTE 将计算 2 次,正如您在 tmp_1 和 tmp_2 中引用的那样。
可以在查询的EXPLAIN PLAN中观察到。
结论是,您可以使用 WITH 子句来更好地调试和维护复杂的查询。它无助于提高 Hive 或 Impala 查询的性能。根据 Hive JIRA 站点,没有路线图来包含此递归功能。
Oracle 和 PostgreSQL 支持此递归功能。
with core as (
select
t1.a,
t1.b,
t2.c
from
test_1 t1
join
test_2 t2 on t1.a = t2.a
where
t1.b = 'test'
)
,tmp_1 as (
select a,count(1) from core group by a
)
,tmp_2 as (
select b,count(1) from core group by b
)
select
t1.a,
t1.count,
t2.count
from
tmp_1 t1
join
tmp_2 t2 on t1.a=t2.b
我的问题是,上述查询中的 core
CTE 是否只计算一次?或者在 tmp_1
和 tmp_2
两个 CTE 中,我在 documentation of impala,
截至目前,使用 Impala 和 Hive 的当前版本, 查询中的核心 CTE 将计算 2 次,正如您在 tmp_1 和 tmp_2 中引用的那样。
可以在查询的EXPLAIN PLAN中观察到。
结论是,您可以使用 WITH 子句来更好地调试和维护复杂的查询。它无助于提高 Hive 或 Impala 查询的性能。根据 Hive JIRA 站点,没有路线图来包含此递归功能。
Oracle 和 PostgreSQL 支持此递归功能。