From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add PG_RETURN_ARG macro and use it for sum(int2) and sum(int4)
Date: Tue, 27 Oct 2026 21:37:07 +0000
Message-ID: <E1xLoqx-000000012OQ-0Wel@gemulon.postgresql.org> (raw)
Add PG_RETURN_ARG macro and use it for sum(int2) and sum(int4)
This is intended for SQL-level functions written in C for cases when
they want to return an input parameter unmodified; NULL if that parameter
is NULL, or the exact value of the parameter otherwise. The return type
and the given input parameter must have matching types. The caller must
verify whether it's safe to not copy non-byval types and not de-toast
variable-length typed inputs.
Here we introduce two usages of the new macro for the transition
functions for sum(int4) and sum(int2). These just need to return the
int8 aggregate state value unmodified when asked to transition a NULL
input; the aggregate state may or may not be NULL at that point.
PG_RETURN_ARG() is coded to work for either case.
This is primarily being added to partially circumvent an argument
against adding overflow checks on sum(int2) and sum(int4), which a pending
patch proposes to do. Effectively, here we're removing 1 jump per
transition function, and that commit plans to add a new jump, so this
commit allows a net zero increase in jumps for both of those functions.
Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAApHDvp-3v1OWbo7RavBf37=MjNScqhj4vyAyHOUDY51nGUnog@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/d2adf339b06b8046d69be7974f9f7e490d2c9e84
Modified Files
--------------
src/backend/utils/adt/numeric.c | 38 ++++++++++++++------------------------
src/include/fmgr.h | 13 +++++++++++++
2 files changed, 27 insertions(+), 24 deletions(-)
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-committers@postgresql.org
Cc: drowley@postgresql.org
Subject: Re: pgsql: Add PG_RETURN_ARG macro and use it for sum(int2) and sum(int4)
In-Reply-To: <E1xLoqx-000000012OQ-0Wel@gemulon.postgresql.org>
References: <E1xLoqx-000000012OQ-0Wel@gemulon.postgresql.org>
* 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