Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9cbc4b8

Browse files
committed
Redo postgres_fdw's planner code so it can handle parameterized paths.
I wasn't going to ship this without having at least some example of how to do that. This version isn't terribly bright; in particular it won't consider any combinations of multiple join clauses. Given the cost of executing a remote EXPLAIN, I'm not sure we want to be very aggressive about doing that, anyway. In support of this, refactor generate_implied_equalities_for_indexcol so that it can be used to extract equivalence clauses that aren't necessarily tied to an index.
1 parent 08af1a0 commit 9cbc4b8

File tree

8 files changed

+919
-553
lines changed

8 files changed

+919
-553
lines changed

contrib/postgres_fdw/deparse.c

Lines changed: 235 additions & 164 deletions
Large diffs are not rendered by default.

contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,27 @@ EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE c8 = 'foo'; -- can't
446446
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1"
447447
(4 rows)
448448

449+
-- parameterized remote path
450+
EXPLAIN (VERBOSE, COSTS false)
451+
SELECT * FROM ft2 a, ft2 b WHERE a.c1 = 47 AND b.c1 = a.c2;
452+
QUERY PLAN
453+
-------------------------------------------------------------------------------------------------------------
454+
Nested Loop
455+
Output: a.c1, a.c2, a.c3, a.c4, a.c5, a.c6, a.c7, a.c8, b.c1, b.c2, b.c3, b.c4, b.c5, b.c6, b.c7, b.c8
456+
-> Foreign Scan on public.ft2 a
457+
Output: a.c1, a.c2, a.c3, a.c4, a.c5, a.c6, a.c7, a.c8
458+
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE (("C 1" = 47))
459+
-> Foreign Scan on public.ft2 b
460+
Output: b.c1, b.c2, b.c3, b.c4, b.c5, b.c6, b.c7, b.c8
461+
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE (($1::integer = "C 1"))
462+
(8 rows)
463+
464+
SELECT * FROM ft2 a, ft2 b WHERE a.c1 = 47 AND b.c1 = a.c2;
465+
c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8
466+
----+----+-------+------------------------------+--------------------------+----+------------+-----+----+----+-------+------------------------------+--------------------------+----+------------+-----
467+
47 | 7 | 00047 | Tue Feb 17 00:00:00 1970 PST | Tue Feb 17 00:00:00 1970 | 7 | 7 | foo | 7 | 7 | 00007 | Thu Jan 08 00:00:00 1970 PST | Thu Jan 08 00:00:00 1970 | 7 | 7 | foo
468+
(1 row)
469+
449470
-- ===================================================================
450471
-- parameterized queries
451472
-- ===================================================================
@@ -646,7 +667,7 @@ EXPLAIN (VERBOSE, COSTS false) EXECUTE st5('foo', 1);
646667
Foreign Scan on public.ft1 t1
647668
Output: c1, c2, c3, c4, c5, c6, c7, c8
648669
Filter: (t1.c8 = $1)
649-
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE (("C 1" = $2::integer))
670+
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE (("C 1" = $1::integer))
650671
(4 rows)
651672

652673
EXECUTE st5('foo', 1);

0 commit comments

Comments
 (0)