pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jeff Janes <jeff.janes@gmail.com>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14505: explain verbose for postgresql_fdw
Date: Fri, 20 Jan 2017 11:55:47 -0500
Message-ID: <14719.1484931347@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMkU=1z1H0v_9JTMVVqS3Z8mNnY-VSW2WOrOgQ+w42YQ1LC8Vw@mail.gmail.com>
References: <20170118234359.1430.69705@wrigleys.postgresql.org>
	<20910.1484789276@sss.pgh.pa.us>
	<CAMkU=1z1H0v_9JTMVVqS3Z8mNnY-VSW2WOrOgQ+w42YQ1LC8Vw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Jeff Janes <jeff.janes@gmail.com> writes:
> On Wed, Jan 18, 2017 at 5:27 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> jeff.janes@gmail.com writes:
>>> The "Output:" line of explain verbose lists columns of foreign table that
>>> are not actually output, or at least ought not be output.

>> That's an optimization to avoid an unnecessary projection step.  It has
>> nothing to do with what's retrieved from the remote, and for that matter
>> it's not specific to foreign tables.

> Is all of that data actually being transferred from the foreign to the
> local?

Well, that would depend on the particular FDW, but postgres_fdw doesn't
transfer unneeded columns, as you can tell by looking at the "Remote SQL"
command.

The key point here is that the output of the ForeignScan plan node has to
match the declared rowtype of the foreign table.  So what postgres_fdw is
going to do, after retrieving the subset of columns that it detected were
used in the query, is construct a dummy tuple that has all the columns but
fills in nulls for the unused ones.  The point of what the planner is
doing with the node output is that we don't need to run ExecProject just
to throw away those nulls again; we can pass the dummy tuple up to the
join node as-is.  (In some cases, like if we had to pass the tuples
through a sort, it'd be worth projecting to remove unused columns ... but
the planner knows that, and generates a minimal output tlist in those
cases.  This isn't one of those cases.)

> If so, I don't think the optimization is a good choice in this case.

I think you're mistaken.

The alternative that we could have used is to require FDWs to emit tuples
containing only used columns --- but that would *require* all FDWs to
contain the logic about identifying used columns, and for at least some
kinds of FDW it would add processing not subtract it.  It'd also
complicate matters elsewhere, because ForeignScan would act quite a bit
different from scans on regular tables.  In those scans, the raw tuples
are necessarily going to contain all columns.

> Do you know where can I find the relevant source code which decides
> on this?

See use_physical_tlist in createplan.c.

			regards, tom lane


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



view thread (4+ messages)

Message-ID: <14719.1484931347@sss.pgh.pa.us>
Permalink:  ../14719.1484931347@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14719.1484931347@sss.pgh.pa.us

 · 

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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jeff.janes@gmail.com
  Subject: Re: BUG #14505: explain verbose for postgresql_fdw
  In-Reply-To: <14719.1484931347@sss.pgh.pa.us>
  References: <20170118234359.1430.69705@wrigleys.postgresql.org> <20910.1484789276@sss.pgh.pa.us> <CAMkU=1z1H0v_9JTMVVqS3Z8mNnY-VSW2WOrOgQ+w42YQ1LC8Vw@mail.gmail.com> <14719.1484931347@sss.pgh.pa.us>

* 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