pgsql: Use ExprStates for hashing in GROUP BY and SubPlans

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Use ExprStates for hashing in GROUP BY and SubPlans
Date: 2024-12-11 00:47:34
Message-ID: E1tLAt4-0027ER-1B@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)gmail(dot)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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message David Rowley 2024-12-11 09:35:50 pgsql: Enable BUFFERS with EXPLAIN ANALYZE by default
Previous Message Jeff Davis 2024-12-11 00:42:26 pgsql: Use in-place updates for pg_restore_relation_stats().