pgsql: Disable physical tlist if any Var would need multiple sortgroupr

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Disable physical tlist if any Var would need multiple sortgroupr
Date: 2016-05-26 18:52:43
Message-ID: E1b60Oh-0005hi-3D@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-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(dot)w4nq7k3gnheg7vit(at)alap3(dot)anarazel(dot)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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Magnus Hagander 2016-05-26 20:22:45 pgsql: Make pg_dump error cleanly with -j against hot standby
Previous Message Alvaro Herrera 2016-05-26 15:59:12 pgsql: Fix typo in 9.5 release nodes