Re: Inconsistent Behavior of GROUP BY ROLLUP in v17 vs master

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, 邱宇航 <iamqyh(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Inconsistent Behavior of GROUP BY ROLLUP in v17 vs master
Date: 2025-10-17 16:18:40
Message-ID: 1707141.1760717920@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Richard Guo <guofenglinux(at)gmail(dot)com> writes:
> Having heard nothing but crickets and not wanting to leave this until
> the 11th hour before November, I'll plan to push the v1 patch next
> week, unless there are any objections.

I started to look at this again, and now I'm thinking that there is
indeed an issue related to "Query 1". Recall that the test setup is

CREATE TABLE t(id int);
INSERT INTO t SELECT generate_series(1, 3);

If we do

regression=# SELECT id, 'XXX' FROM t GROUP BY ROLLUP (id, 1);

we get this, which seems correct:

id | ?column?
----+----------
| XXX
3 | XXX
2 | XXX
1 | XXX
3 | XXX
2 | XXX
1 | XXX
(7 rows)

But leave out the "id" output, and look what happens:

regression=# SELECT 'XXX' FROM t GROUP BY ROLLUP (id, 1);
?column?
----------

XXX
XXX
XXX



(7 rows)

How can that be correct?? Simplifying further to

regression=# SELECT 'XXX' FROM t GROUP BY ROLLUP (id);
?column?
----------
XXX
XXX
XXX
XXX
(4 rows)

restores sanity. I've not dug into the code, but these two examples
make it look like we think that 'XXX' is dependent on '1', which
surely it is not, most especially since it shouldn't vary depending
on whether "id" is included as an output column.

This behavior is the same as in v17, but that doesn't make it not
broken.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniele Varrazzo 2025-10-17 16:26:57 Re: Getting the SQLSTATE after a failed connection
Previous Message Peter Eisentraut 2025-10-17 16:15:47 Re: make tsearch use the database default locale