pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Speed up Hash Join by making ExprStates support hashing
Date: Tue, 20 Aug 2024 01:39:20 +0000
Message-ID: <E1sgDqB-000W0s-Us@gemulon.postgresql.org> (raw)

Speed up Hash Join by making ExprStates support hashing

Here we add ExprState support for obtaining a 32-bit hash value from a
list of expressions.  This allows both faster hashing and also JIT
compilation of these expressions.  This is especially useful when hash
joins have multiple join keys as the previous code called ExecEvalExpr on
each hash join key individually and that was inefficient as tuple
deformation would have only taken into account one key at a time, which
could lead to walking the tuple once for each join key.  With the new
code, we'll determine the maximum attribute required and deform the tuple
to that point only once.

Some performance tests done with this change have shown up to a 20%
performance increase of a query containing a Hash Join without JIT
compilation and up to a 26% performance increase when JIT is enabled and
optimization and inlining were performed by the JIT compiler.  The
performance increase with 1 join column was less with a 14% increase
with and without JIT.  This test was done using a fairly small hash
table and a large number of hash probes.  The increase will likely be
less with large tables, especially ones larger than L3 cache as memory
pressure is more likely to be the limiting factor there.

This commit only addresses Hash Joins, but lays expression evaluation
and JIT compilation infrastructure for other hashing needs such as Hash
Aggregate.

Author: David Rowley
Reviewed-by: Alexey Dvoichenkov <alexey@hyperplane.net>
Reviewed-by: Tels <nospam-pg-abuse@bloodgate.com>
Discussion: https://postgr.es/m/CAApHDvoexAxgQFNQD_GRkr2O_eJUD1-wUGm%3Dm0L%2BGc%3DT%3DkEa4g%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/adf97c1562380e02acd60dc859c289ed3a8352ee

Modified Files
--------------
src/backend/executor/execExpr.c       | 141 +++++++++++++++++++++++
src/backend/executor/execExprInterp.c | 110 ++++++++++++++++++
src/backend/executor/nodeHash.c       | 190 +++++++------------------------
src/backend/executor/nodeHashjoin.c   | 143 ++++++++++++++++++++----
src/backend/jit/llvm/llvmjit_expr.c   | 204 ++++++++++++++++++++++++++++++++++
src/include/executor/execExpr.h       |  24 ++++
src/include/executor/executor.h       |   7 ++
src/include/executor/hashjoin.h       |  12 --
src/include/executor/nodeHash.h       |   9 +-
src/include/nodes/execnodes.h         |  12 +-
10 files changed, 650 insertions(+), 202 deletions(-)



Message-ID: <E1sgDqB-000W0s-Us@gemulon.postgresql.org>
Permalink:  ../E1sgDqB-000W0s-Us@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1sgDqB-000W0s-Us@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: drowley@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Speed up Hash Join by making ExprStates support hashing
  In-Reply-To: <E1sgDqB-000W0s-Us@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox