Re: Wrong results from inner-unique joins caused by collation mismatch

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Wrong results from inner-unique joins caused by collation mismatch
Date: 2026-04-25 09:24:39
Message-ID: CAMbWs492Ps+0nvSRk02VU+55G=5C==J+N8eYdbR0DK4iZw-W4w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Apr 25, 2026 at 12:44 AM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
> On Fri, Apr 24, 2026 at 11:53 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > 1. I think there are other places in the planner that will need
> > substantially this same logic. I recommend breaking out a
> > subroutine defined more or less as "do these collations have
> > equivalent notions of equality".

> Right. I just found several other places that need this same logic,
> which are in query_is_distinct_for(). Without it, we produce wrong
> results:

0001 wrapped the logic in subroutine collations_are_compatible().

(I'm a little unsure about the InvalidOid cases. The current
implementation treats InvalidOid on either side as compatible, as
absence of a collation can't conflict with the other side. This
generalizes the asymmetric treatment in IndexCollMatchesExprColl().)

0002 fixed query_is_distinct_for(), using that subroutine.

- Richard

Attachment Content-Type Size
v2-0001-Consider-collation-when-proving-uniqueness-from-u.patch application/octet-stream 11.2 KB
v2-0002-Consider-collation-when-proving-subquery-uniquene.patch application/octet-stream 20.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2026-04-25 10:52:52 ri_LockPKTuple misleading message
Previous Message Daniil Davydov 2026-04-25 08:34:22 Re: Fix bug with accessing to temporary tables of other sessions