pgsql: Postpone aggregate checks until after collation is assigned. - Mailing list pgsql-committers

From Andrew Gierth
Subject pgsql: Postpone aggregate checks until after collation is assigned.
Date
Msg-id E1gk1Sx-0005Kj-F2@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Postpone aggregate checks until after collation is assigned.

Previously, parseCheckAggregates was run before
assign_query_collations, but this causes problems if any expression
has already had a collation assigned by some transform function (e.g.
transformCaseExpr) before parseCheckAggregates runs. The differing
collations would cause expressions not to be recognized as equal to
the ones in the GROUP BY clause, leading to spurious errors about
unaggregated column references.

The result was that CASE expr WHEN val ... would fail when "expr"
contained a GROUPING() expression or matched one of the group by
expressions, and where collatable types were involved; whereas the
supposedly identical CASE WHEN expr = val ... would succeed.

Backpatch all the way; this appears to have been wrong ever since
collations were introduced.

Per report from Guillaume Lelarge, analysis and patch by me.

Discussion: https://postgr.es/m/CAECtzeVSO_US8C2Khgfv54ZMUOBR4sWq+6_bLrETnWExHT=rFg@mail.gmail.com
Discussion: https://postgr.es/m/87muo0k0c7.fsf@news-spur.riddles.org.uk

Branch
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/624046abe23f3da003b8db07d7028c70f1c672bd

Modified Files
--------------
src/backend/parser/analyze.c               | 18 ++++++++++++------
src/test/regress/expected/aggregates.out   | 19 +++++++++++++++++++
src/test/regress/expected/groupingsets.out | 25 +++++++++++++++++++++++++
src/test/regress/sql/aggregates.sql        |  8 ++++++++
src/test/regress/sql/groupingsets.sql      | 11 +++++++++++
5 files changed, 75 insertions(+), 6 deletions(-)


pgsql-committers by date:

Previous
From: Tatsuo Ishii
Date:
Subject: pgsql: Doc: enhance pgbench manual.
Next
From: Magnus Hagander
Date:
Subject: pgsql: Remove references to Majordomo