| From: | Andrei Lepikhov <lepihov(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, David Rowley <dgrowleyml(at)gmail(dot)com> |
| Cc: | Corey Huinker <corey(dot)huinker(at)gmail(dot)com> |
| Subject: | Allow a prosupport function to be attached to an aggregate |
| Date: | 2026-08-17 06:13:29 |
| Message-ID: | 8f58c96d-d3c7-4c0f-9898-116f00eeaff6@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
Commit 42473b3b31 added SupportRequestSimplifyAggref, which the planner issues
for any Aggref whose function names a support function. Nice, but extensions
cannot reach it, because there is no way to attach a support function to an
aggregate:
ALTER FUNCTION pg_catalog.sum(numeric) SUPPORT numeric_support;
ERROR: "pg_catalog.sum" is an aggregate function
CREATE/ALTER aggregate doesn't support this feature at all. This does not look
like a decision about support functions. AlterFunction() rejects an aggregate
for every property it can change, not just for SUPPORT, and the other properties
it covers are ones AggregateCreate() fixes for aggregates anyway. prosupport is
different: nothing else in the catalog determines it, so refusing to set it
leaves the capability simply unreachable rather than merely inconvenient.
Updating pg_proc directly is not an answer. It records no pg_depend entry, so
the support function can then be dropped and leave a dangling OID behind.
My interest is extension-defined optimizations of numeric aggregates [1] or even
more extravagant dumb transformations, like the following (doable for specific
conditions):
SUM(x ORDER BY x) → SUM(x)
SUM(x) FILTER (WHERE true) → SUM(x)
SUM(N) -> N * COUNT(*)
Please find attached a patch adding SUPPORT to CREATE AGGREGATE's option
list and an ALTER AGGREGATE ... SUPPORT form. Both require superuser,
as the equivalent function clauses do, and record a normal dependency.
[1] https://github.com/danolivo/pg_numeric_agg_support
--
regards, Andrei Lepikhov,
pgEdge
| Attachment | Content-Type | Size |
|---|---|---|
| v0-0001-Enable-altering-prosupport-function-of-an-aggrega.patch | text/plain | 13.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | JiaoShuntian | 2026-08-17 06:18:04 | Re: PSQL schema "describe" \dn is not escaping quotes |
| Previous Message | solai v | 2026-08-17 06:12:37 | Re: Add XMLNamespaces to XMLElement |