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: Resolve mismatch between JIT and non-JIT hashing
Date: Tue, 17 Nov 2026 23:53:19 +0000
Message-ID: <E1xTSzG-000000009tP-1R2x@gemulon.postgresql.org> (raw)

Resolve mismatch between JIT and non-JIT hashing

adf97c156 taught expression evaluation to produce hash values.  That
required both JIT and non-JIT versions.  The JIT version wasn't quite
correct as it didn't truncate the produced hash value down to 32 bits
before rotating and combining with the previously stored intermediate hash
value when hashing multiple keys.

When a hash function returned a negative int32, the value was
sign-extended to 64 bits, and the JIT code's 1-bit left rotation then
shifted those set upper bits into the lower 32, setting every bit of the
intermediate hash to 1 no matter what the earlier keys hashed to.  This
meant all rows for which an earlier key had a negative hash value
effectively hashed only on the remaining keys, causing many hash
collisions resulting in slow hash aggregates and hash joins.

Here we fix by adjusting the JIT code to match what the non-JIT version
does.

Backpatch to 18, where adf97c156 was introduced.

Reported-by: Tor Erik Linnerud <tel@jklm.no>
Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/CAEGP1v12rRmZo1h3KZ+ZCS66A9xLoSOuLAyBXu92nd97E3jJPw@mail.gmail.com
Backpatch-through: 18

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9107a0feafb6b1782f096c3231a79087a6a4bfac

Modified Files
--------------
src/backend/jit/llvm/llvmjit_expr.c | 41 ++++++++++++++++++++++---------------
1 file changed, 25 insertions(+), 16 deletions(-)



view thread (3+ messages)  latest in thread

Message-ID: <E1xTSzG-000000009tP-1R2x@gemulon.postgresql.org>
Permalink:  ../E1xTSzG-000000009tP-1R2x@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xTSzG-000000009tP-1R2x@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: drowley@postgresql.org
  Subject: Re: pgsql: Resolve mismatch between JIT and non-JIT hashing
  In-Reply-To: <E1xTSzG-000000009tP-1R2x@gemulon.postgresql.org>
  References: <E1xTSzG-000000009tP-1R2x@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