sum() on int2 and int4 columns now uses an int8, not numeric, accumulator
Tom Lane <tgl@sss.pgh.pa.us>
sum() on int2 and int4 columns now uses an int8, not numeric, accumulator for speed reasons; its result type also changes to int8. avg() on these datatypes now accumulates the running sum in int8 for speed; but we still deliver the final result as numeric, so that fractional accuracy is preserved. count() now counts and returns in int8, not int4. I am a little nervous about this possibly breaking users' code, but there didn't seem to be a strong sentiment for avoiding the problem. If we get complaints during beta, we can change count back to int4 and add a "count8" aggregate. For that matter, users can do it for themselves with a simple CREATE AGGREGATE command; the int4inc function is still present, so no C hacking is needed. Also added max() and min() aggregates for OID that do proper unsigned comparison, instead of piggybacking on int4 aggregates. initdb forced.
Files
| Path | Change | +/− |
|---|---|---|
| doc/src/sgml/func.sgml | modified | +10 −6 |
| src/backend/utils/adt/int8.c | modified | +9 −1 |
| src/backend/utils/adt/numeric.c | modified | +118 −27 |
| src/backend/utils/adt/oid.c | modified | +19 −1 |
| src/backend/utils/fmgr/fmgr.c | modified | +15 −1 |
| src/include/catalog/catversion.h | modified | +2 −2 |
| src/include/catalog/pg_aggregate.h | modified | +9 −7 |
| src/include/catalog/pg_proc.h | modified | +16 −3 |
| src/include/utils/builtins.h | modified | +6 −1 |
| src/include/utils/int8.h | modified | +2 −1 |
| src/test/regress/expected/opr_sanity.out | modified | +2 −2 |
| src/test/regress/expected/rules.out | modified | +1 −1 |
| src/test/regress/sql/rules.sql | modified | +1 −1 |