On 02/09/2026 09:37, Michael Paquier wrote: > On Wed, Sep 02, 2026 at 08:01:56AM +0200, Andrei Lepikhov wrote: >> In my mind, we should pay for CPU cycles only in practical cases. So, if this >> case deserves an overflow check, it should be an assertion that consumes no >> resources in production. > > All the patterns you are showing imply direct function calls, which > don't really seem worth bothering about. Are any of these overflow > cases reachable using operators with dedicated casts? I would count > as OK even cases where the sum functions are used in a custom > aggregate, say with a SFUNC set to one of the paths you are pointing > at. 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 -- regards, Andrei Lepikhov, pgEdge
