Re: Wrong results with grouping sets

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Wrong results with grouping sets
Date: 2023-10-07 10:29:41
Message-ID: CAMbWs4_=voKa2URLnRcQkbKs5D_+AW2PkOHMTqjuQX3Ms363LQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Sep 25, 2023 at 3:11 PM Richard Guo <guofenglinux(at)gmail(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Richard Guo 2023-10-07 11:02:09 Fix a typo in _bt_readpage
Previous Message Michał Kłeczek 2023-10-07 10:01:17 Draft LIMIT pushdown to Append and MergeAppend patch