From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix old bug with coercing the result of a COLLATE expression.
Date: Mon, 12 Apr 2021 18:38:04 +0000
Message-ID: <E1lW1Rk-0008RZ-6S@gemulon.postgresql.org> (raw)
Fix old bug with coercing the result of a COLLATE expression.
There are hacks in parse_coerce.c to push down a requested coercion
to below any CollateExpr that may appear. However, we did that even
if the requested data type is non-collatable, leading to an invalid
expression tree in which CollateExpr is applied to a non-collatable
type. The fix is just to drop the CollateExpr altogether, reasoning
that it's useless.
This bug is ten years old, dating to the original addition of
COLLATE support. The lack of field complaints suggests that there
aren't a lot of user-visible consequences. We noticed the problem
because it would trigger an assertion in DefineVirtualRelation if
the invalid structure appears as an output column of a view; however,
in a non-assert build, you don't see a crash just a (subtly incorrect)
complaint about applying collation to a non-collatable type. I found
that by putting the incorrect structure further down in a view, I could
make a view definition that would fail dump/reload, per the added
regression test case. But CollateExpr doesn't do anything at run-time,
so this likely doesn't lead to any really exciting consequences.
Per report from Yulin Pei. Back-patch to all supported branches.
Discussion: https://postgr.es/m/HK0PR01MB22744393C474D503E16C8509F4709@HK0PR01MB2274.apcprd01.prod.exchangelabs....
Branch
------
REL_13_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/8a7bd1e6cba37170afadcb252da3cf9c5386ef06
Modified Files
--------------
src/backend/parser/parse_coerce.c | 29 ++++++++++++++++++-----------
src/test/regress/expected/collate.out | 16 +++++++++++++++-
src/test/regress/sql/collate.sql | 6 ++++++
3 files changed, 39 insertions(+), 12 deletions(-)
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: Fix old bug with coercing the result of a COLLATE expression.
In-Reply-To: <E1lW1Rk-0008RZ-6S@gemulon.postgresql.org>
References: <E1lW1Rk-0008RZ-6S@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