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 <[email protected]> Reviewed-by: Tom Lane <[email protected]> Discussion: https://postgr.es/m/CAApHDvp-3v1OWbo7RavBf37=mjnscqhj4vyayhoudy51ngu...@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(-)
