Re: BUG #18662: ORDER BY after GROUPING SETS does not order correctly for certain WHERE condition

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: sander(dot)evers(at)topicus(dot)nl
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18662: ORDER BY after GROUPING SETS does not order correctly for certain WHERE condition
Date: 2024-10-17 15:03:13
Message-ID: 657102.1729177393@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> I'm seeing inconsistent results for an ORDER BY in combination with GROUPING
> SETS.

Yup. Your example actually works correctly as of HEAD (v18-to-be):

regression=# select * from (values (1, 1), (1, 2), (2,1), (2,2)) as t (a,b)
where a=1
group by grouping sets ((b),(a,b))
order by a, b;
a | b
---+---
1 | 1
1 | 2
| 1
| 2
(4 rows)

but I'm afraid there's zero chance of back-patching the fix,
as it's far too invasive (and under-tested, for now) for that.

> This might be the same bug as
> https://www.postgresql.org/message-id/CAL48EtKDHCKnOkLdSgOmgBZBcahU2zpBqyzeET_ZM74uNZBFHg@mail.gmail.com

Indeed. Richard Guo recently completed the fix I alluded to in that
thread:

https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=247dea89f
https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=f5050f795

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2024-10-17 17:29:03 Re: BUG #18614: [ECPG] out of bound in DecodeDateTime
Previous Message Erik Wienhold 2024-10-17 15:02:35 Re: BUG #18660: information_schema.columns.ordinal_position has gaps when primary key columns are dropped