pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@postgresql.org
Subject: pgsql: Add an explicit representation of the output targetlist to Paths
Date: Fri, 19 Feb 2016 01:02:22 +0000
Message-ID: <E1aWZSg-0003H7-8A@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

Add an explicit representation of the output targetlist to Paths.

Up to now, there's been an assumption that all Paths for a given relation
compute the same output column set (targetlist).  However, there are good
reasons to remove that assumption.  For example, an indexscan on an
expression index might be able to return the value of an expensive function
"for free".  While we have the ability to generate such a plan today in
simple cases, we don't have a way to model that it's cheaper than a plan
that computes the function from scratch, nor a way to create such a plan
in join cases (where the function computation would normally happen at
the topmost join node).  Also, we need this so that we can have Paths
representing post-scan/join steps, where the targetlist may well change
from one step to the next.  Therefore, invent a "struct PathTarget"
representing the columns we expect a plan step to emit.  It's convenient
to include the output tuple width and tlist evaluation cost in this struct,
and there will likely be additional fields in future.

While Path nodes that actually do have custom outputs will need their own
PathTargets, it will still be true that most Paths for a given relation
will compute the same tlist.  To reduce the overhead added by this patch,
keep a "default PathTarget" in RelOptInfo, and allow Paths that compute
that column set to just point to their parent RelOptInfo's reltarget.
(In the patch as committed, actually every Path is like that, since we
do not yet have any cases of custom PathTargets.)

I took this opportunity to provide some more-honest costing of
PlaceHolderVar evaluation.  Up to now, the assumption that "scan/join
reltargetlists have cost zero" was applied not only to Vars, where it's
reasonable, but also PlaceHolderVars where it isn't.  Now, we add the eval
cost of a PlaceHolderVar's expression to the first plan level where it can
be computed, by including it in the PathTarget cost field and adding that
to the cost estimates for Paths.  This isn't perfect yet but it's much
better than before, and there is a way forward to improve it more.  This
costing change affects the join order chosen for a couple of the regression
tests, changing expected row ordering.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/19a541143a09c067ec8cac77ec6a64eb5b1b662b

Modified Files
--------------
contrib/file_fdw/file_fdw.c              |   4 +-
contrib/postgres_fdw/deparse.c           |   4 +-
contrib/postgres_fdw/postgres_fdw.c      |  11 ++--
doc/src/sgml/fdwhandler.sgml             |   2 +-
src/backend/nodes/outfuncs.c             |  19 ++++--
src/backend/optimizer/path/allpaths.c    |  37 +++++------
src/backend/optimizer/path/costsize.c    | 106 +++++++++++++++++++++++++++----
src/backend/optimizer/path/indxpath.c    |   7 +-
src/backend/optimizer/plan/createplan.c  |  15 ++---
src/backend/optimizer/plan/initsplan.c   |   7 +-
src/backend/optimizer/plan/planner.c     |  67 +++++++++++--------
src/backend/optimizer/util/clauses.c     |   2 +-
src/backend/optimizer/util/pathnode.c    |  37 +++++++++--
src/backend/optimizer/util/placeholder.c |  40 +++++++++---
src/backend/optimizer/util/relnode.c     |  24 ++++---
src/include/nodes/relation.h             |  47 +++++++++++---
src/include/optimizer/placeholder.h      |   4 +-
src/test/regress/expected/join.out       |  36 +++++------
18 files changed, 326 insertions(+), 143 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: <E1aWZSg-0003H7-8A@gemulon.postgresql.org>
Permalink:  ../E1aWZSg-0003H7-8A@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1aWZSg-0003H7-8A@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: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Add an explicit representation of the output targetlist to Paths
  In-Reply-To: <E1aWZSg-0003H7-8A@gemulon.postgresql.org>
  References: <E1aWZSg-0003H7-8A@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