| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Fixing grouping expressions inside subqueries |
| Date: | 2026-02-25 22:32:11 |
| Message-ID: | 531183.1772058731@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
A recent complaint [1] reminded me of an unimplemented case that's
remained unimplemented for something close to 30 years. It's
explained by this comment in parse_agg.c:
* NOTE: we recognize grouping expressions in the main query, but only
* grouping Vars in subqueries. For example, this will be rejected,
* although it could be allowed:
* SELECT
* (SELECT x FROM bar where y = (foo.a + foo.b))
* FROM foo
* GROUP BY a + b;
* The difficulty is the need to account for different sublevels_up.
* This appears to require a whole custom version of equal(), which is
* way more pain than the feature seems worth.
Perhaps I was undercaffeinated when I wrote that, but anyway, there
is a way to do it that doesn't require either a custom version of
equal() or exponential amounts of time to do the matching.
See attached.
regards, tom lane
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Support-grouping-expression-references-and-GROUPI.patch | text/x-diff | 16.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ilia Evdokimov | 2026-02-25 22:45:44 | Re: Hash-based MCV matching for large IN-lists |
| Previous Message | Sami Imseih | 2026-02-25 21:53:09 | Re: Fix bug in multixact Oldest*MXactId initialization and access |