Here we add overflow checks to guard against overflowing the int8 sum of all inputs for sum(int2), sum(int4), avg(int2) and avg(int4). Such an overflow is very unlikely for the int2 versions, but somewhat possible to hit for the int4 versions when given billions of large enough inputs. Since our code and machines are getting faster, and with the advent of things like columnar table AMs, it's getting more likely that such an overflow could occur in a real use case. No guards have been added to the average count. That would require 2^63 input rows, which is not possible to achieve in a single instance of PostgreSQL, given other limitations such as 64-bit LSNs. Fixing this only in master as we can probably get away with that today due to this still being unlikely for users to ever hit. Author: Andrei Lepikhov <lepihov@gmail.com> Reviewed-by: David Rowley <dgrowleyml@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Discussion: https://postgr.es/m/1ddc2a6f-4b26-43d9-9f3b-5b5db98a486d@gmail.com
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/devel/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/devel/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.