pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Haas <rhaas@postgresql.org>
To: pgsql-committers@postgresql.org
Subject: pgsql: postgres_fdw: Check PlaceHolderVars before pushing down a join.
Date: Tue, 14 Jun 2016 15:50:15 +0000
Message-ID: <E1bCqbX-0001Xh-C1@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


Message-ID: <E1bCqbX-0001Xh-C1@gemulon.postgresql.org>
Permalink:  ../E1bCqbX-0001Xh-C1@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1bCqbX-0001Xh-C1@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: rhaas@postgresql.org
  Subject: Re: pgsql: postgres_fdw: Check PlaceHolderVars before pushing down a join.
  In-Reply-To: <E1bCqbX-0001Xh-C1@gemulon.postgresql.org>
  References: <E1bCqbX-0001Xh-C1@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox