pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrei Lepikhov <lepihov@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: David Rowley <dgrowleyml@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Corey Huinker <corey.huinker@gmail.com>
Subject: Re: Allow a prosupport function to be attached to an aggregate
Date: Sat, 22 Aug 2026 22:33:15 +0200
Message-ID: <a943e222-70b5-4086-8f97-c18808fcb5aa@gmail.com> (raw)
In-Reply-To: <4078101.1787325628@sss.pgh.pa.us>
References: <8f58c96d-d3c7-4c0f-9898-116f00eeaff6@gmail.com>
	<CAApHDvpE-_CnMOQ=Y8wveUk-MrUzsyR66fXGq+R7j_g4tmra8g@mail.gmail.com>
	<1379592.1787063701@sss.pgh.pa.us>
	<3f63c035-e0a6-4dc6-a34e-743df8c19d50@gmail.com>
	<3954875.1787255265@sss.pgh.pa.us>
	<4008013.1787256399@sss.pgh.pa.us>
	<1f2140fe-e4ae-4a52-9365-d5cbadcf5ae4@gmail.com>
	<4078101.1787325628@sss.pgh.pa.us>

On 21/08/2026 17:20, Tom Lane wrote:
> Andrei Lepikhov <lepihov@gmail.com> writes:>
>> What I want to optimise is the built-in functions like
>> sum(), avg(), and similar ones, because those are what users
>> actually use.
> 
> For those, wouldn't we just modify the initial contents of pg_proc?

For the trivial ones, yes, and that is a fair point. sum(x) FILTER (WHERE true)
-> sum(x) holds unconditionally; sum(x ORDER BY x) -> sum(x) holds for the exact
types, though not for float, where the order is part of the result. They would
also make a decent worked example of an aggregate support function - AFAICS
int8inc_support is still the only in-core user of SupportRequestSimplifyAggref.

Other optimisations of built-in aggregates in my pocket are an OLAP
specialisation and would be pure overhead for other workloads. I doubt it makes
sense to put a sum(numeric(N,M)) variant into core when it only pays off in a
database whose numeric columns carry a typmod.
>> With
>> only CREATE OR REPLACE AGGREGATE available, an extension would have to restate
>> the whole definition of pg_catalog.sum(numeric), including sfunc, combinefunc,
>> and so on, and keep that copy updated with every major release.
> 
> I'm not particularly on board with this goal: I think letting
> extensions modify built-in aggregates is fraught with all sorts
> of issues.  (To name only one, there's no way for multiple
> extensions to each attach new behaviors to the same aggregate.)

Agreed as far as it goes, though the limitation is neither new nor specific to
aggregates: prosupport is a single regproc column, so ALTER FUNCTION ... SUPPORT
on a plain function is already last-one-wins. Whether a shared object should
accept support functions from third parties at all is a fair question, and a
larger one than this patch. So, with more evidence of practical need, we can
return to it later.

In my experience that is what applications ask for. An extension also back-ports
the optimisation to already-released majors, which is a large part of why we
write one. In the meantime we will do it by rewriting prosupport directly and
adding the pg_depend entry - the only way I know to attach such an optimisation
without touching the application.

> I'm certainly not going to risk putting in half-considered
> support for such a thing at this stage of the release cycle.
> There's enough risk in adding what I proposed yesterday.
No objection. It closes the case the thread started from and the pg_dump part is
what v0 was missing.

-- 
regards, Andrei Lepikhov,
pgEdge






view thread (12+ messages)  latest in thread

Message-ID: <a943e222-70b5-4086-8f97-c18808fcb5aa@gmail.com>
Permalink:  ../a943e222-70b5-4086-8f97-c18808fcb5aa@gmail.com/
Also on:    postgresql.org/message-id/a943e222-70b5-4086-8f97-c18808fcb5aa@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: lepihov@gmail.com, tgl@sss.pgh.pa.us, dgrowleyml@gmail.com, corey.huinker@gmail.com
  Subject: Re: Allow a prosupport function to be attached to an aggregate
  In-Reply-To: <a943e222-70b5-4086-8f97-c18808fcb5aa@gmail.com>
  References: <8f58c96d-d3c7-4c0f-9898-116f00eeaff6@gmail.com> <CAApHDvpE-_CnMOQ=Y8wveUk-MrUzsyR66fXGq+R7j_g4tmra8g@mail.gmail.com> <1379592.1787063701@sss.pgh.pa.us> <3f63c035-e0a6-4dc6-a34e-743df8c19d50@gmail.com> <3954875.1787255265@sss.pgh.pa.us> <4008013.1787256399@sss.pgh.pa.us> <1f2140fe-e4ae-4a52-9365-d5cbadcf5ae4@gmail.com> <4078101.1787325628@sss.pgh.pa.us> <a943e222-70b5-4086-8f97-c18808fcb5aa@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox