Skip to content

Commit 84cb51b

Browse files
committed
postgres_fdw: Fix interaction of PHVs with child joins.
Commit f49842d introduced the concept of a child join, but did not update this code accordingly. Ashutosh Bapat, with cosmetic changes by me Discussion: http://postgr.es/m/CAFjFpRf=J_KPOtw+bhZeURYkbizr8ufSaXg6gPEF6DKpgH-t6g@mail.gmail.com
1 parent de6428a commit 84cb51b

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7800,4 +7800,44 @@ SELECT t1.a,t1.b FROM fprt1 t1, LATERAL (SELECT t2.a, t2.b FROM fprt2 t2 WHERE t
78007800
400 | 400
78017801
(4 rows)
78027802

7803+
-- with PHVs, partition-wise join selected but no join pushdown
7804+
EXPLAIN (COSTS OFF)
7805+
SELECT t1.a, t1.phv, t2.b, t2.phv FROM (SELECT 't1_phv' phv, * FROM fprt1 WHERE a % 25 = 0) t1 FULL JOIN (SELECT 't2_phv' phv, * FROM fprt2 WHERE b % 25 = 0) t2 ON (t1.a = t2.b) ORDER BY t1.a, t2.b;
7806+
QUERY PLAN
7807+
------------------------------------------------------------
7808+
Sort
7809+
Sort Key: ftprt1_p1.a, ftprt2_p1.b
7810+
-> Result
7811+
-> Append
7812+
-> Hash Full Join
7813+
Hash Cond: (ftprt1_p1.a = ftprt2_p1.b)
7814+
-> Foreign Scan on ftprt1_p1
7815+
-> Hash
7816+
-> Foreign Scan on ftprt2_p1
7817+
-> Hash Full Join
7818+
Hash Cond: (ftprt1_p2.a = ftprt2_p2.b)
7819+
-> Foreign Scan on ftprt1_p2
7820+
-> Hash
7821+
-> Foreign Scan on ftprt2_p2
7822+
(14 rows)
7823+
7824+
SELECT t1.a, t1.phv, t2.b, t2.phv FROM (SELECT 't1_phv' phv, * FROM fprt1 WHERE a % 25 = 0) t1 FULL JOIN (SELECT 't2_phv' phv, * FROM fprt2 WHERE b % 25 = 0) t2 ON (t1.a = t2.b) ORDER BY t1.a, t2.b;
7825+
a | phv | b | phv
7826+
-----+--------+-----+--------
7827+
0 | t1_phv | 0 | t2_phv
7828+
50 | t1_phv | |
7829+
100 | t1_phv | |
7830+
150 | t1_phv | 150 | t2_phv
7831+
200 | t1_phv | |
7832+
250 | t1_phv | 250 | t2_phv
7833+
300 | t1_phv | |
7834+
350 | t1_phv | |
7835+
400 | t1_phv | 400 | t2_phv
7836+
450 | t1_phv | |
7837+
| | 75 | t2_phv
7838+
| | 225 | t2_phv
7839+
| | 325 | t2_phv
7840+
| | 475 | t2_phv
7841+
(14 rows)
7842+
78037843
RESET enable_partitionwise_join;

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4565,7 +4565,11 @@ foreign_join_ok(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype,
45654565
foreach(lc, root->placeholder_list)
45664566
{
45674567
PlaceHolderInfo *phinfo = lfirst(lc);
4568-
Relids relids = joinrel->relids;
4568+
Relids relids;
4569+
4570+
/* PlaceHolderInfo refers to parent relids, not child relids. */
4571+
relids = IS_OTHER_REL(joinrel) ?
4572+
joinrel->top_parent_relids : joinrel->relids;
45694573

45704574
if (bms_is_subset(phinfo->ph_eval_at, relids) &&
45714575
bms_nonempty_difference(relids, phinfo->ph_eval_at))

contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,4 +1913,9 @@ EXPLAIN (COSTS OFF)
19131913
SELECT t1.a,t1.b FROM fprt1 t1, LATERAL (SELECT t2.a, t2.b FROM fprt2 t2 WHERE t1.a = t2.b AND t1.b = t2.a) q WHERE t1.a%25 = 0 ORDER BY 1,2;
19141914
SELECT t1.a,t1.b FROM fprt1 t1, LATERAL (SELECT t2.a, t2.b FROM fprt2 t2 WHERE t1.a = t2.b AND t1.b = t2.a) q WHERE t1.a%25 = 0 ORDER BY 1,2;
19151915

1916+
-- with PHVs, partition-wise join selected but no join pushdown
1917+
EXPLAIN (COSTS OFF)
1918+
SELECT t1.a, t1.phv, t2.b, t2.phv FROM (SELECT 't1_phv' phv, * FROM fprt1 WHERE a % 25 = 0) t1 FULL JOIN (SELECT 't2_phv' phv, * FROM fprt2 WHERE b % 25 = 0) t2 ON (t1.a = t2.b) ORDER BY t1.a, t2.b;
1919+
SELECT t1.a, t1.phv, t2.b, t2.phv FROM (SELECT 't1_phv' phv, * FROM fprt1 WHERE a % 25 = 0) t1 FULL JOIN (SELECT 't2_phv' phv, * FROM fprt2 WHERE b % 25 = 0) t2 ON (t1.a = t2.b) ORDER BY t1.a, t2.b;
1920+
19161921
RESET enable_partitionwise_join;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy