model-writtenrun 92 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Andrei Lepikhov opened the thread with overflow checks for sum(int2), sum(int4), and their average transition functions, explaining that unchecked accumulation could silently wrap while the sum combine function raised an error, making results depend on the execution plan #1.
- Chao Li asked whether inverse transitions also needed subtraction overflow checks and demonstrated overflow with a caller-supplied state; Andrei considered such direct-call cases insufficient justification for additional production checks, and inverse transitions remained outside the patch #2 #4 #5.
- Michael Paquier questioned tests based on direct transition-function calls, while Andres Freund proposed making transition states internal to eliminate unsupported calling patterns and defensive overhead; Michael, Chao Li, and Tom Lane supported exploring that broader direction #6 #8 #9 #10 #11 #12.
- Andrei demonstrated negative sums and averages from roughly 4.3 billion positive integer inputs using ordinary aggregates, convincing Michael that the overflow was reachable through supported behavior; Michael suggested inexpensive tests using custom aggregates initialized near the accumulator limit #13 #14.
- David Rowley supplied a PG_RETURN_INPUT optimization to remove a branch and offset the overflow-checking cost, and Andrei incorporated it alongside custom-aggregate tests and additional count overflow checks #15 #16.
- David requested simpler comments, and Tom Lane requested corrected comment placement, conventional macro formatting, removal of impractical average-count overflow checks, and deletion of the artificial regression tests; David subsequently agreed that count checks were unnecessary #18 #19 #21 #22.
- Andrei accidentally attached the unchanged previous patch while claiming those corrections, then supplied the actual revision removing count checks and tests and applying the presentation fixes #23 #24.
- After a gap, David proposed limiting the fix to master because overflows were still unlikely and introducing the macro into only some stable minor releases could complicate extension compatibility #25.
- David split the revision into his macro optimization and Andrei's overflow checks, renamed the macro PG_RETURN_ARG, clarified its copying and detoasting requirements, and removed an obsolete comment; he also argued that restricting SQL callability should preserve efficient by-value aggregate states #26.
- The two patches from the final submission landed with identical diffs: the macro optimization as d2adf339b0 and the overflow checks as 903ce587e6, with the latter explicitly limited to master #26.
- David confirmed both commits and reported reproducing an overflow in about 4.4 seconds on a parallel machine, reinforcing his concern that work distribution could determine whether the existing combine check caught an overflow #27.
- The overflow work was complete at the end of the thread, while Andrei continued the separate design discussion about a procallable attribute or allowed-call-context mask for restricting direct SQL access to support functions; that broader mechanism remained a proposal #28.