pgsql: Improve performance of numeric sum(), avg(), stddev(), variance( - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Improve performance of numeric sum(), avg(), stddev(), variance(
Date
Msg-id E1VhpZd-0003le-6z@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Improve performance of numeric sum(), avg(), stddev(), variance(), etc.

This patch improves performance of most built-in aggregates that formerly
used a NUMERIC or NUMERIC array as their transition type; this includes
not only aggregates on numeric inputs, but some aggregates on integer
inputs where overflow of an int8 value is a possibility.  The code now
uses a special-purpose data structure to avoid array construction and
deconstruction overhead, as well as packing and unpacking overhead for
numeric values.

These aggregates' transition type is now declared as INTERNAL, since
it doesn't correspond to any SQL data type.  To keep the planner from
thinking that that means a lot of storage will be used, we make use
of the just-added pg_aggregate.aggtransspace feature.  The space estimate
is set to 128 bytes, which is at least in the right ballpark.

Hadi Moshayedi, reviewed by Pavel Stehule and Tomas Vondra

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/69c8fbac201652282e18b0e2e301d4ada991fbde

Modified Files
--------------
src/backend/utils/adt/numeric.c          |  392 +++++++++++++++++++-----------
src/include/catalog/catversion.h         |    2 +-
src/include/catalog/pg_aggregate.h       |   56 ++---
src/include/catalog/pg_proc.h            |   24 +-
src/include/utils/builtins.h             |    1 +
src/test/regress/expected/aggregates.out |   61 +++++
src/test/regress/sql/aggregates.sql      |   12 +
7 files changed, 362 insertions(+), 186 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Allow aggregates to provide estimates of their transition state
Next
From: Tom Lane
Date:
Subject: pgsql: Add make_date() and make_time() functions.