You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
postgres_fdw: Avoid 'variable not found in subplan target list' error.
The tlist of the EvalPlanQual outer plan for a ForeignScan node is
adjusted to produce a tuple whose descriptor matches the scan tuple slot
for the ForeignScan node. But in the case where the outer plan contains
an extra Sort node, if the new tlist contained columns required only for
evaluating PlaceHolderVars or columns required only for evaluating local
conditions, this would cause setrefs.c to fail with the error.
The cause of this is that when creating the outer plan by injecting the
Sort node into an alternative local join plan that could emit such extra
columns as well, we fail to arrange for the outer plan to propagate them
up through the Sort node, causing setrefs.c to fail to match up them in
the new tlist to what is available from the outer plan. Repair.
Per report from Alexander Pyhalov.
Richard Guo and Etsuro Fujita, reviewed by Alexander Pyhalov and Tom Lane.
Backpatch to all supported versions.
Discussion: http://postgr.es/m/cfb17bf6dfdf876467bd5ef533852d18%40postgrespro.ru
Copy file name to clipboardExpand all lines: contrib/postgres_fdw/expected/postgres_fdw.out
+83Lines changed: 83 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2419,6 +2419,89 @@ SELECT * FROM ft1, ft2, ft4, ft5 WHERE ft1.c1 = ft2.c1 AND ft1.c2 = ft4.c1
2419
2419
2420
2420
RESET enable_nestloop;
2421
2421
RESET enable_hashjoin;
2422
+
-- test that add_paths_with_pathkeys_for_rel() arranges for the epq_path to
2423
+
-- return columns needed by the parent ForeignScan node
2424
+
CREATE TABLE local_tbl (c1 int NOT NULL, c2 int NOT NULL, c3 text, CONSTRAINT local_tbl_pkey PRIMARY KEY (c1));
2425
+
INSERT INTO local_tbl SELECT id, id % 10, to_char(id, 'FM0000') FROM generate_series(1, 1000) id;
2426
+
ANALYZE local_tbl;
2427
+
EXPLAIN (VERBOSE, COSTS OFF)
2428
+
SELECT * FROM local_tbl LEFT JOIN (SELECT ft1.*, COALESCE(ft1.c3 || ft2.c3, 'foobar') FROM ft1 INNER JOIN ft2 ON (ft1.c1 = ft2.c1 AND ft1.c1 < 100)) ss ON (local_tbl.c1 = ss.c1) ORDER BY local_tbl.c1 FOR UPDATE OF local_tbl;
Remote SQL: SELECT r4."C 1", r4.c2, r4.c3, r4.c4, r4.c5, r4.c6, r4.c7, r4.c8, CASE WHEN (r4.*)::text IS NOT NULL THEN ROW(r4."C 1", r4.c2, r4.c3, r4.c4, r4.c5, r4.c6, r4.c7, r4.c8) END, CASE WHEN (r5.*)::text IS NOT NULL THEN ROW(r5."C 1", r5.c2, r5.c3, r5.c4, r5.c5, r5.c6, r5.c7, r5.c8) END, r5.c3 FROM ("S 1"."T 1" r4 INNER JOIN "S 1"."T 1" r5 ON (((r4."C 1" = r5."C 1")) AND ((r4."C 1" < 100)))) ORDER BY r4."C 1" ASC NULLS LAST
ALTER SERVER loopback OPTIONS (ADD fdw_startup_cost '10000.0');
2464
+
EXPLAIN (VERBOSE, COSTS OFF)
2465
+
SELECT * FROM local_tbl LEFT JOIN (SELECT ft1.* FROM ft1 INNER JOIN ft2 ON (ft1.c1 = ft2.c1 AND ft1.c1 < 100 AND ft1.c1 = postgres_fdw_abs(ft2.c2))) ss ON (local_tbl.c3 = ss.c3) ORDER BY local_tbl.c1 FOR UPDATE OF local_tbl;
Remote SQL: SELECT r4."C 1", r4.c2, r4.c3, r4.c4, r4.c5, r4.c6, r4.c7, r4.c8, CASE WHEN (r4.*)::text IS NOT NULL THEN ROW(r4."C 1", r4.c2, r4.c3, r4.c4, r4.c5, r4.c6, r4.c7, r4.c8) END, CASE WHEN (r5.*)::text IS NOT NULL THEN ROW(r5."C 1", r5.c2, r5.c3, r5.c4, r5.c5, r5.c6, r5.c7, r5.c8) END, r5.c2 FROM ("S 1"."T 1" r4 INNER JOIN "S 1"."T 1" r5 ON (((r4."C 1" = r5."C 1")) AND ((r4."C 1" < 100)))) ORDER BY r4.c3 ASC NULLS LAST
INSERT INTO local_tbl SELECT id, id % 10, to_char(id, 'FM0000') FROM generate_series(1, 1000) id;
587
+
ANALYZE local_tbl;
588
+
589
+
EXPLAIN (VERBOSE, COSTS OFF)
590
+
SELECT*FROM local_tbl LEFT JOIN (SELECT ft1.*, COALESCE(ft1.c3||ft2.c3, 'foobar') FROM ft1 INNER JOIN ft2 ON (ft1.c1=ft2.c1ANDft1.c1<100)) ss ON (local_tbl.c1=ss.c1) ORDER BYlocal_tbl.c1 FOR UPDATE OF local_tbl;
591
+
592
+
ALTER SERVER loopback OPTIONS (DROP extensions);
593
+
ALTER SERVER loopback OPTIONS (ADD fdw_startup_cost '10000.0');
594
+
EXPLAIN (VERBOSE, COSTS OFF)
595
+
SELECT*FROM local_tbl LEFT JOIN (SELECT ft1.*FROM ft1 INNER JOIN ft2 ON (ft1.c1=ft2.c1ANDft1.c1<100ANDft1.c1= postgres_fdw_abs(ft2.c2))) ss ON (local_tbl.c3=ss.c3) ORDER BYlocal_tbl.c1 FOR UPDATE OF local_tbl;
596
+
ALTER SERVER loopback OPTIONS (DROP fdw_startup_cost);
597
+
ALTER SERVER loopback OPTIONS (ADD extensions 'postgres_fdw');
598
+
599
+
DROPTABLE local_tbl;
600
+
583
601
-- check join pushdown in situations where multiple userids are involved
584
602
CREATE ROLE regress_view_owner;
585
603
CREATEUSERMAPPING FOR regress_view_owner SERVER loopback;
0 commit comments