Re: Wrong results with grouping sets - Mailing list pgsql-hackers

From Richard Guo
Subject Re: Wrong results with grouping sets
Date
Msg-id CAMbWs4_=voKa2URLnRcQkbKs5D_+AW2PkOHMTqjuQX3Ms363LQ@mail.gmail.com
Whole thread Raw
In response to Wrong results with grouping sets  (Richard Guo <guofenglinux@gmail.com>)
List pgsql-hackers

On Mon, Sep 25, 2023 at 3:11 PM Richard Guo <guofenglinux@gmail.com> wrote:
I think the root cause is that when we generate distinct_pathkeys, we
failed to realize that Var 'b' might be nullable by the grouping sets,
so it's no longer always equal to Var 'a'.  It's not correct to deem
that the PathKey for 'b' is redundant and thus remove it from the
pathkeys list.

We have the same issue when generating sort_pathkeys.  As a result, we
may have the final output in the wrong order.  There were several
reports about this issue before, such as [1][2].

To fix this issue, I'm thinking that we mark the grouping expressions
nullable by grouping sets with a dummy RTE for grouping sets, something
like attached. 

Hi Tom, I'm wondering if you've got a chance to look into this issue.
What do you think about the fix?

Thanks
Richard

pgsql-hackers by date:

Previous
From: Michał Kłeczek
Date:
Subject: Draft LIMIT pushdown to Append and MergeAppend patch
Next
From: Richard Guo
Date:
Subject: Fix a typo in _bt_readpage