Re: SUM(int2)/SUM(int4) do not detect overflow of the int8 accumulator

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Andrei Lepikhov <lepihov(at)gmail(dot)com>
Cc: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Nathan Bossart <nathandbossart(at)gmail(dot)com>
Subject: Re: SUM(int2)/SUM(int4) do not detect overflow of the int8 accumulator
Date: 2026-09-02 23:44:12
Message-ID: api0zO-MqjNPZnXn@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Sep 02, 2026 at 10:19:29AM +0200, Andrei Lepikhov wrote:
> I use direct calls mainly to make regression tests run faster.
>
> The first case arose during benchmarking built-in SUM(int4) with various
> parallelising methods [1] (bare research topic) at scale. This may not be a big
> issue right now, but as databases get larger, it could become one. I think it's
> more likely to happen first in the microcurrency space, where the base unit is a
> cent instead of a dollar, especially with very large partitioned tables.
>
> [1] https://www.pgedge.com/blog/do-global-hash-tables-strike-back-in-postgresql

Honestly, I don't know how to feel about this patch.

I see the reason why you are doing it for efficiency, but you are
abusing direct function calls (not in the docs) to emulate patterns
that we support behind operators (in user-visible documentation), or
even casts (in user-visible documentation).

Overall I don't see a need to do anything here, but perhaps I'm just
the only one feeling that. Others are free to disagree with this
statement. If there are overflow holes when going through operators
and/or casts, these would be more appealing to fix, IMO, because
these refer to the behavior we expose to the end-users in the docs.
--
Michael

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2026-09-02 23:56:32 Re: SUM(int2)/SUM(int4) do not detect overflow of the int8 accumulator
Previous Message Bharath Rupireddy 2026-09-02 23:22:00 Re: Make pg_prewarm, autoprewarm yield for waiting DDL