pgsql: Don't apply sortgroupref labels to a tlist that might not match.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Don't apply sortgroupref labels to a tlist that might not match.
Date: 2016-06-28 14:43:33
Message-ID: E1bHuEf-0000D3-2U@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Don't apply sortgroupref labels to a tlist that might not match.

If we need to use a gating Result node for pseudoconstant quals,
create_scan_plan() intentionally suppresses use_physical_tlist's checks
on whether there are matches for sortgroupref labels, on the grounds that
we don't need matches because we can label the Result's projection output
properly. However, it then called apply_pathtarget_labeling_to_tlist
anyway. This oversight was harmless when written, but in commit aeb9ae645
I made that function throw an error if there was no match. Thus, the
combination of a table scan, pseudoconstant quals, and a non-simple-Var
sortgroupref column threw the dreaded "ORDER/GROUP BY expression not found
in targetlist" error. To fix, just skip applying the labeling in this
case. Per report from Rushabh Lathia.

Report: <CAGPqQf2iLB8t6t-XrL-zR233DFTXxEsfVZ4WSqaYfLupEoDxXA(at)mail(dot)gmail(dot)com>

Branch
------
master

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

Modified Files
--------------
src/backend/optimizer/plan/createplan.c | 14 ++++++++++----
src/test/regress/expected/aggregates.out | 19 +++++++++++++++++++
src/test/regress/sql/aggregates.sql | 5 +++++
3 files changed, 34 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Bruce Momjian 2016-06-28 17:54:31 pgsql: doc: remove mention of UT1 in representing time
Previous Message Robert Haas 2016-06-27 21:57:26 pgsql: Fix mistakes in pg_visibility documentation.