Re: [PATCH] GROUP BY ALL
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Christensen <david@pgguru.net>
Cc: jian he <jian.universality@gmail.com>,
Andrey Borodin <x4mmm@yandex-team.ru>,
Peter Eisentraut <peter@eisentraut.org>,
pgsql-hackers <pgsql-hackers@postgresql.org>,
"David G. Johnston" <david.g.johnston@gmail.com>,
Jelte Fennema-Nio <postgres@jeltef.nl>
Date: 2025-09-26T17:46:19Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add GROUP BY ALL.
- ef38a4d9756d 19 (unreleased) landed
-
Refactor to avoid code duplication in transformPLAssignStmt.
- b0fb2c6aa5a4 19 (unreleased) landed
-
Fix missed copying of groupDistinct in transformPLAssignStmt.
- b7f6798c056a 16.11 landed
- 9ca79896aba3 15.15 landed
- 78a284b0b8d4 18.1 landed
- 7504d2be9eb4 19 (unreleased) landed
- 3fc9aa5b0233 17.7 landed
- 0be39b4b1a01 14.20 landed
David Christensen <david@pgguru.net> writes: > Version 3 of this patch, incorporating some of the feedback thus far: Some random comments: I don't love where you put the parsing code. Instead of exposing addTargetToGroupList, I think you should have given transformGroupClause the responsibility of expanding GROUP BY ALL. One reason for that is that GROUP BY processing depends on the results of transformSortClause. This means that in v3, the behavior of SELECT x FROM ... GROUP BY x ORDER BY x; will be subtly different from SELECT x FROM ... GROUP BY ALL ORDER BY x; which seems like a bug, or at least not desirable. (You might need a DESC or USING decoration in the ORDER BY to expose this clearly.) The parsing code itself is not great: + TargetEntry *n = (TargetEntry*)lfirst(l1); + if (!contain_aggs_of_level((Node *)n->expr, 0)) + qry->groupClause = addTargetToGroupList(pstate, n, qry->groupClause, qry->targetList, 0); You should be skipping resjunk entries, and please use "tle" or some such name less generic than "n", and "0" is not the correct location to pass to addTargetToGroupList. Probably the location of the ALL keyword would be the ideal thing, but if we don't have that, the notation for "no location known" is -1 not 0. We could also consider using exprLocation(tle->expr), despite the comment on addTargetToGroupList that that's not the right thing. This might actually be better than pointing at the ALL anyway, since that would give no hint which targetentry caused the error. The test cases seem poorly designed, because it's very hard to be sure whether the code expanded the ALL as-expected. I think you could improve them by not executing the queries but just EXPLAINing them, so that the expanded group-by list is directly visible. regards, tom lane