Speed up SUM calculation in numeric aggregates.
Heikki Linnakangas <heikki.linnakangas@iki.fi>
Speed up SUM calculation in numeric aggregates. This introduces a numeric sum accumulator, which performs better than repeatedly calling add_var(). The performance comes from using wider digits and delaying carry propagation, tallying positive and negative values separately, and avoiding a round of palloc/pfree on every value. This speeds up SUM(), as well as other standard aggregates like AVG() and STDDEV() that also calculate a sum internally. Reviewed-by: Andrey Borodin Discussion: <c0545351-a467-5b76-6d46-4840d1ea8aa4@iki.fi>
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/utils/adt/numeric.c | modified | +498 −103 |
| src/test/regress/expected/numeric.out | modified | +16 −0 |
| src/test/regress/sql/numeric.sql | modified | +8 −0 |