pgsql: postgres_fdw: Check PlaceHolderVars before pushing down a join. - Mailing list pgsql-committers

From Robert Haas
Subject pgsql: postgres_fdw: Check PlaceHolderVars before pushing down a join.
Date
Msg-id E1bCqbX-0001Xh-C1@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
postgres_fdw: Check PlaceHolderVars before pushing down a join.

As discovered by Andreas Seltenreich via sqlsmith, it's possible for a
remote join to need to generate a target list which contains a
PlaceHolderVar which would need to be evaluated on the remote server.
This happens when we try to push down a join tree which contains outer
joins and the nullable side of the join contains a subquery which
evauates some expression which can go to NULL above the level of the
join.  Since the deparsing logic can't build a remote query that
involves subqueries, it fails while trying to produce an SQL query
that can be sent to the remote side.  Detect such cases and don't try
to push down the join at all.

It's actually fine to push down the join if the PlaceHolderVar needs
to be evaluated at the current join level.  This patch makes a small
change to build_tlist_to_deparse so that this case will work.

Amit Langote, Ashutosh Bapat, and me.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/131c7e70b4596027992a2f72bfd3765f0fff1b7c

Modified Files
--------------
contrib/postgres_fdw/deparse.c                 |  4 +-
contrib/postgres_fdw/expected/postgres_fdw.out | 58 ++++++++++++++++++++++++++
contrib/postgres_fdw/postgres_fdw.c            | 34 ++++++++++-----
contrib/postgres_fdw/sql/postgres_fdw.sql      | 12 ++++++
4 files changed, 96 insertions(+), 12 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Minor fixes in contrib installation scripts.
Next
From: Robert Haas
Date:
Subject: pgsql: Update extensions with GIN/GIST support for parallel query.