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

From Richard Guo
Subject Re: Wrong results with grouping sets
Date
Msg-id CAMbWs4_9_A77tFgUAKtMHV0X2rCFQAiY1oj+=E38NtTWkXUxxQ@mail.gmail.com
Whole thread Raw
In response to Re: Wrong results with grouping sets  (Alena Rybakina <lena.ribackina@yandex.ru>)
List pgsql-hackers

On Thu, Nov 16, 2023 at 11:25 PM Alena Rybakina <lena.ribackina@yandex.ru> wrote:

I noticed that this query worked correctly in the main branch with the inequality operator:

postgres=# select distinct on (a, b) a, b from (values (3, 1), (2, 2)) as t (a, b) where a > b group by grouping sets((a, b), (a)); a | b ---+--- 3 | 1 3 | (2 rows)

So, I think you are right)


Thanks for taking an interest in this patch and verifying it.
 

I looked at your patch and noticed a few things:

1. I think you should add a test with the cube operator, because I noticed that the order of the query in the result has also changed:

 
Hmm, I'm not sure if that's necessary.  The wrong result order you saw
here is caused by the same reason explained above: the planner fails to
realize that Var 'a' and 'b' are nullable by the grouping sets, making
them no longer always equal to each other.  This issue should have been
covered in the tests added by v1 patch.

Thanks
Richard

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: [HACKERS] Should logtape.c blocks be of type long?
Next
From: Tom Lane
Date:
Subject: Re: Wrong rows estimations with joins of CTEs slows queries by more than factor 500