Speed up SUM calculation in numeric aggregates

Enterprise / PostgreSQL - Heikki Linnakangas [iki.fi] - 2 September 2016 03:51 UTC

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.

9cca11c Speed up SUM calculation in numeric aggregates.
src/backend/utils/adt/numeric.c | 601 +++++++++++++++++++++++++++------
src/test/regress/expected/numeric.out | 16 +
src/test/regress/sql/numeric.sql | 8 +
3 files changed, 522 insertions(+), 103 deletions(-)

Upstream: git.postgresql.org


  • Share