Thread: pgsql: Use ExprStates for hashing in GROUP BY and SubPlans

pgsql: Use ExprStates for hashing in GROUP BY and SubPlans

From
David Rowley
Date:
Use ExprStates for hashing in GROUP BY and SubPlans

This speeds up obtaining hash values for GROUP BY and hashed SubPlans by
using the ExprState support for hashing, thus allowing JIT compilation for
obtaining hash values for these operations.

This, even without JIT compilation, has been shown to improve Hash
Aggregate performance in some cases by around 15% and hashed NOT IN
queries in one case by over 30%, however, real-world cases are likely to
see smaller gains as the test cases used were purposefully designed to
have high hashing overheads by keeping the hash table small to prevent
additional memory overheads that would be a factor when working with large
hash tables.

In passing, fix a hypothetical bug in ExecBuildHash32Expr() so that the
initial value is stored directly in the ExprState's result field if
there are no expressions to hash.  None of the current users of this
function use an initial value, so the bug is only hypothetical.

Reviewed-by: Andrei Lepikhov <lepihov@gmail.com>
Discussion: https://postgr.es/m/CAApHDvpYSO3kc9UryMevWqthTBrxgfd9djiAjKHMPUSQeX9vdQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0f5738202b812a976e8612c85399b52d16a0abb6

Modified Files
--------------
src/backend/executor/execExpr.c     | 155 ++++++++++++++++++++++++++++++++++++
src/backend/executor/execGrouping.c |  82 ++++++++-----------
src/backend/executor/nodeSubplan.c  |  18 ++++-
src/include/executor/executor.h     |  10 ++-
src/include/nodes/execnodes.h       |  25 +++---
5 files changed, 224 insertions(+), 66 deletions(-)