Re: Issue with query_is_distinct_for() and grouping sets

Richard Guo <guofenglinux@gmail.com>

From: Richard Guo <guofenglinux@gmail.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-10-23T03:43:36Z
Lists: pgsql-hackers
On Thu, Oct 23, 2025 at 12:07 PM David Rowley <dgrowleyml@gmail.com> wrote:
> Or if it's a case of it returning false when it could have returned
> true, then maybe the commit message should make that clear. I'm unable
> to tell from reading it. Something like; "The previous logic in
> query_is_distinct_for() was incomplete [as it failed to detect that a
> query was distinct when ...]".

It's the case of failing to recognize distinctness when it actually
holds (i.e., a false negative).  Therefore, this issue does not cause
incorrect results, but rather leads to missed optimization
opportunities.

How about using the following wording in the commit message?

"
The previous logic in query_is_distinct_for() was incomplete because
the check was insufficiently thorough and could return false when it
should have returned true.
"

- Richard



Commits

  1. Fix distinctness check for queries with grouping sets