Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wxsP5-0032Sk-0f for pgsql-hackers@arkaria.postgresql.org; Sat, 22 Aug 2026 20:33:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wxsP4-00Gd7X-01 for pgsql-hackers@arkaria.postgresql.org; Sat, 22 Aug 2026 20:33:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wxsP3-00Gd7P-2F for pgsql-hackers@lists.postgresql.org; Sat, 22 Aug 2026 20:33:21 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wxsP1-00000001wBs-2s4K for pgsql-hackers@lists.postgresql.org; Sat, 22 Aug 2026 20:33:20 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4956242332dso18528865e9.2 for ; Sat, 22 Aug 2026 13:33:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787430798; x=1788035598; darn=lists.postgresql.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1bclo7SRaKlOA2+go693Tk9k5LR2ok9qQWMLHl6Xgso=; b=G0OH4o60h9TnqEr++KgwF8WXH+yFL/rV79qJy2RTzg3RuqMDTUXfB8oZX8pvibpgGX viEzVIE72Tqzw6D53oeWmVuD858LyduqtP+6Un0FVFLrbyveLFq7wkKSSjji3JWakDvA Y6+7YreNWBz1GZ0Ud331HaqbNr3vsx7tyTl+ERJnFuCEEQXi61qbSaeNhE9I8nFGhckn T26zWj39eaPllKRpI/zC0JetAOLqPZ2SgywN8r/y7SjePFAd+xFYYmEIJzJMAqxns0wB Yv+57/rkSnzaOxyzMc4b94AOhwmU5G2S7eFgXJ09L2XJOEsor9VFscveC1Gc/TxzhLeB cyRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787430798; x=1788035598; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1bclo7SRaKlOA2+go693Tk9k5LR2ok9qQWMLHl6Xgso=; b=cFG8inoRu3SByEPhnmqXwvWOG9N8a8DAXFajcRM8wz7PIaIDx+2tQ4iiITo2/qgk/+ NYKRzeOlOTg1a0PceU5ffWnJvC+G0S7pL5r6Mwvvh2YuMM3nROjr/Kaxw6su+KjhetdM jCpnIhocT7CQ6eAxvH5KivcfT36BQzWxcgm7YZXBOpZeT5VFlGgRJ44mWMUkZBvnq5II B8YGe70u2Uup9WdeQy4KWLaOmM7BzNWqj2XRfLMyGuWGMM9sLjYv9aPJ8Ddce73tgGkv sF878dNuKKye9eZRfGMqQizZUmc6AcScvzPF5iYd7bTBR8hGX820Zd0lwVTG4x+eMdhU F4Dg== X-Forwarded-Encrypted: i=1; AHgh+RrVS6VwnIg/jx/EIjDmv4I1O0WYJgbW8ShvZrzC2NgEsIjzy05G9K7PJJ6dRTWcfgAyb2+/W5ZzwAe8Lr8M@lists.postgresql.org X-Gm-Message-State: AFuF++m93D/cWkodplUwq1FypKF3kaOFZTgC/4dOuG7B6lSJSYx9aZGW 4VB4W+BY9/M1/MsrMrqj0795/dX10U+nZoWXCICnGfByF59X0kG9fNRZ X-Gm-Gg: AR+sD11Gtw+wzRORGStTtd1CXcJlk0YMt5B8yNDhunor3r/EvwE4E/fQtj3gbSS9EpM sHhBVZVUXTReXeAMEyYzbkeA+gLRXfoS+mUsLbRg23adDN7zyHK0zcqZNTcM4Sem++XlzVoWbcn N2Dz/o+A9hHYUm9PCEz7uf8n6fpzFtovU6Lk7rdTR42xOwFPLNPLnqS/3Q8oXiyTDoV4MqS0mVL o8xMsKwcMlyFlfWieoeyNqwS1DUpPqLDzIrBUz5BYO1lGiqWkGJ17SpmnbGSEJYcf6dk1bBpW8v mgsSOu+M7DxYMXTw2hd26MV7ggH75M6T5GIOd+fFyIwmtBexZJ1w91nV6NuZlqzMMz5rkmdLJsK 1ccQwSFlWiv20nbkOjSkkzhDMmS71N5cWDiu8xOIsNK4kXCQTPo7eSCwHJWv8GGckUU9h5FpgF3 5oiZQcBO2acWaSvRudIIN0vtE6xlucoFZ3ZhMjAlRJdzqeuldzHJxObkjWd0oU0gOuf7L6Mbk/h Gh+vFLGnyUPnPg6u0xQHdtUf6DLdKtlIwWw X-Received: by 2002:a05:600c:6211:b0:495:4d88:e630 with SMTP id 5b1f17b1804b1-499b8465f7dmr211163945e9.10.1787430798025; Sat, 22 Aug 2026 13:33:18 -0700 (PDT) Received: from [192.168.0.86] (84.123.227.20.dyn.user.ono.com. [84.123.227.20]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499b9bcd41csm37016545e9.4.2026.08.22.13.33.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 22 Aug 2026 13:33:17 -0700 (PDT) Message-ID: Date: Sat, 22 Aug 2026 22:33:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Allow a prosupport function to be attached to an aggregate To: Tom Lane Cc: David Rowley , PostgreSQL Hackers , Corey Huinker References: <8f58c96d-d3c7-4c0f-9898-116f00eeaff6@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> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: <4078101.1787325628@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 21/08/2026 17:20, Tom Lane wrote: > Andrei Lepikhov 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