Use more efficient hashtable for execGrouping.c to speed up hash aggregation.

The more efficient hashtable speeds up hash-aggregations with more than
a few hundred groups significantly. Improvements of over 120% have been

Due to the the different hash table queries that not fully
determined (e.g. GROUP BY without ORDER BY) may change their result

The conversion is largely straight-forward, except that, due to the
static element types of simplehash.h type hashes, the additional data
some users store in elements (e.g. the per-group working data for hash
aggregaters) is now stored in TupleHashEntryData->additional.  The
meaning of BuildTupleHashTable's entrysize (renamed to additionalsize)
has been changed to only be about the additionally stored size.  That
size is only used for the initial sizing of the hash-table.

Reviewed-By: Tomas Vondra
Discussion: <>



Modified Files
src/backend/executor/execGrouping.c       | 155 ++++++++++++------------------
src/backend/executor/nodeAgg.c            |  64 ++++++------
src/backend/executor/nodeRecursiveunion.c |  17 +---
src/backend/executor/nodeSetOp.c          |  46 ++++-----
src/backend/executor/nodeSubplan.c        |   6 +-
src/backend/optimizer/plan/planner.c      |   6 ++
src/include/executor/executor.h           |   2 +-
src/include/nodes/execnodes.h             |  32 +++---
src/tools/pgindent/typedefs.list          |   2 +
9 files changed, 144 insertions(+), 186 deletions(-)

Sent via pgsql-committers mailing list (
To make changes to your subscription:

Reply via email to