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: Disable physical tlist if any Var would need multiple sortgroupr
Date: Thu, 26 May 2016 18:52:43 +0000
Message-ID: <E1b60Oh-0005hi-3D@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

Disable physical tlist if any Var would need multiple sortgroupref labels.

As part of upper planner pathification (commit 3fc6e2d7f5b652b4) I redid
createplan.c's approach to the physical-tlist optimization, in which scan
nodes are allowed to return exactly the underlying table's columns so as
to save doing a projection step at runtime.  The logic was intentionally
more aggressive than before about applying the optimization, which is
generally a good thing, but Andres Freund found a case in which it got
too aggressive.  Namely, if any column is referenced more than once in
the parent plan node's sorting or grouping column list, we can't optimize
because then that column would need to have more than one ressortgroupref
label, and we only have space for one.

Add logic to detect this situation in use_physical_tlist(), and also add
some error checking in apply_pathtarget_labeling_to_tlist(), which this
example proves was being overly cavalier about whether what it was doing
made any sense.

The added test case exposes the problem only because we do not eliminate
duplicate grouping keys.  That might be something to fix someday, but it
doesn't seem like appropriate post-beta work.

Report: <20160526021235.w4nq7k3gnheg7vit@alap3.anarazel.de>

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/aeb9ae6457865c8949641d71a9523374d843a418

Modified Files
--------------
src/backend/optimizer/plan/createplan.c       | 15 +++++++++++++--
src/backend/optimizer/util/tlist.c            | 23 +++++++++++++++++------
src/test/regress/expected/select_distinct.out | 24 ++++++++++++++++++++++++
src/test/regress/sql/select_distinct.sql      | 11 +++++++++++
4 files changed, 65 insertions(+), 8 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: <E1b60Oh-0005hi-3D@gemulon.postgresql.org>
Permalink:  ../E1b60Oh-0005hi-3D@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1b60Oh-0005hi-3D@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: Disable physical tlist if any Var would need multiple sortgroupr
  In-Reply-To: <E1b60Oh-0005hi-3D@gemulon.postgresql.org>
  References: <E1b60Oh-0005hi-3D@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