check query plan during physical planning for outer joins

onur-leftjoin_push-improvements
eaydingol 2025-08-14 20:21:58 +03:00
parent c2c6f7b910
commit f1181db55c
3 changed files with 25 additions and 0 deletions

View File

@ -2302,6 +2302,18 @@ QueryPushdownSqlTaskList(Query *query, uint64 jobId,
}
}
/*
* We might fail to find outer joins from the relationRestrictionContext
* when the original query has CTEs. In order to ensure that we always mark
* the outer joins correctly and compute additional quals when necessary,
* check the task query as well.
*/
if (!updateQualsForOuterJoin && FindNodeMatchingCheckFunction((Node *) query,
IsOuterJoinExpr))
{
updateQualsForOuterJoin = true;
}
/*
* We keep track of minShardOffset to skip over a potentially big amount of pruned
* shards. However, we need to start at minShardOffset - 1 to make sure we don't

View File

@ -845,6 +845,14 @@ DEBUG: assigned task to node localhost:xxxxx
(1 row)
SET client_min_messages TO ERROR;
-- Ensure that even when CTEs are replaced, we insert push
-- down conditions for outer joins when necessary.
WITH cte_0 AS ( SELECT table_0.a FROM d1 AS table_0 WHERE table_0.a IN ( SELECT table_1.a FROM d1 AS table_1 ORDER BY a LIMIT 2 ) ORDER BY a ) SELECT count(*), avg(avgsub.a) FROM ( SELECT table_2.a FROM cte_0 AS table_2 RIGHT JOIN r1 AS table_3 USING (a)) AS avgsub;
count | avg
---------------------------------------------------------------------
15 | 1.00000000000000000000
(1 row)
-- The following queries trigger recursive computing, recurring outer-join push down
-- methods introduced in#7973 can be enhanced to cover these cases in the future.
CREATE TABLE r1_local AS SELECT * FROM r1;

View File

@ -117,6 +117,11 @@ SELECT count(*) FROM (SELECT * FROM d1) AS t1 RIGHT JOIN r1 USING (a);
SET client_min_messages TO ERROR;
-- Ensure that even when CTEs are replaced, we insert push
-- down conditions for outer joins when necessary.
WITH cte_0 AS ( SELECT table_0.a FROM d1 AS table_0 WHERE table_0.a IN ( SELECT table_1.a FROM d1 AS table_1 ORDER BY a LIMIT 2 ) ORDER BY a ) SELECT count(*), avg(avgsub.a) FROM ( SELECT table_2.a FROM cte_0 AS table_2 RIGHT JOIN r1 AS table_3 USING (a)) AS avgsub;
-- The following queries trigger recursive computing, recurring outer-join push down
-- methods introduced in#7973 can be enhanced to cover these cases in the future.
CREATE TABLE r1_local AS SELECT * FROM r1;