Google bigquery 没有意义。你的场景中有1个条件连接,更新后的版本实际上满足了我上面的理论。join说它肯定需要扫描t1和t2。case语句中包含t2的原始连接没有定义t2的扫描量。@rtenha但是包含两个连接的那一个呢?如果你的理论是正确的,那不是也行吗?这是同一个问题
Google bigquery 没有意义。你的场景中有1个条件连接,更新后的版本实际上满足了我上面的理论。join说它肯定需要扫描t1和t2。case语句中包含t2的原始连接没有定义t2的扫描量。@rtenha但是包含两个连接的那一个呢?如果你的理论是正确的,那不是也行吗?这是同一个问题,google-bigquery,Google Bigquery,没有意义。你的场景中有1个条件连接,更新后的版本实际上满足了我上面的理论。join说它肯定需要扫描t1和t2。case语句中包含t2的原始连接没有定义t2的扫描量。@rtenha但是包含两个连接的那一个呢?如果你的理论是正确的,那不是也行吗?这是同一个问题。t3在case语句中,使其具有条件。它无法估计需要扫描多少t3。 #standardSQL SELECT *, ARRAY( SELECT AS STRUCT * FROM t2 b WHERE b.id IN
没有意义。你的场景中有1个条件连接,更新后的版本实际上满足了我上面的理论。join说它肯定需要扫描t1和t2。case语句中包含t2的原始连接没有定义t2的扫描量。@rtenha但是包含两个连接的那一个呢?如果你的理论是正确的,那不是也行吗?这是同一个问题。t3在case语句中,使其具有条件。它无法估计需要扫描多少t3。
#standardSQL
SELECT *,
ARRAY(
SELECT AS STRUCT *
FROM t2 b
WHERE b.id IN (a.id, a.other_id)
ORDER BY (
CASE
WHEN dairy IN ('milk', 'yogurt') THEN 1
ELSE 2
END
)
LIMIT 1
)[SAFE_OFFSET(0)] AS t2
FROM t1 a
Row dairy id other_id t2.color t2.id
1 milk 1 2 blue 1
2 yogurt 3 4 red 4
3 cheese 5 6
WITH t1 AS (
SELECT "milk" AS dairy, 1 AS id, 2 AS other_id UNION ALL
SELECT "yogurt", 3, 4 UNION ALL
SELECT "cheese", 5, 6
),
t2 AS (
SELECT "blue" AS color, 1 AS id UNION ALL
SELECT "red", 4
),
t3 AS (
SELECT "sunny" AS weather, 1 as id, 10 as other_id UNION ALL
SELECT "cloudy", 11, 4
),
join_t1_t2 as (
select
t1.*,
case
when t1.dairy = 'milk' then milk.color
when t1.dairy = 'yogurt' then yogurt.color
else null
end as t2_color,
case
when t1.dairy = 'milk' then milk.id
when t1.dairy = 'yogurt' then yogurt.id
else null
end as t2_id
from t1
left join t2 milk on t1.id = milk.id
left join t2 yogurt on t1.other_id = yogurt.id
),
join_t1_t2_t3 as (
select
join_t1_t2.*,
case
when t2_color = 'blue' then blue.id
when t2_color = 'red' then red.id
else null
end as t3_id,
case
when t2_color = 'blue' then blue.other_id
when t2_color = 'red' then red.other_id
else null
end as t3_other_id,
case
when t2_color = 'blue' then blue.weather
when t2_color = 'red' then red.weather
else null
end as t3_weather,
from join_t1_t2
left join t3 blue on t2_id = blue.id
left join t3 red on t2_id = red.other_id
)
select * from join_t1_t2_t3