pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Resolve mismatch between JIT and non-JIT hashing
3+ messages / 1 participants
[nested] [flat]

* pgsql: Resolve mismatch between JIT and non-JIT hashing
@ 2026-11-17 23:53  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 3+ messages in thread

From: David Rowley @ 2026-11-17 23:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Resolve mismatch between JIT and non-JIT hashing
@ 2026-11-17 23:53  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 3+ messages in thread

From: David Rowley @ 2026-11-17 23:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
REL_19_STABLE

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

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Resolve mismatch between JIT and non-JIT hashing
@ 2026-11-17 23:53  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 3+ messages in thread

From: David Rowley @ 2026-11-17 23:53 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7646ab9384b9437991e91359f058dd284ab69ca0

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2026-11-17 23:53 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 23:53 pgsql: Resolve mismatch between JIT and non-JIT hashing David Rowley <drowley@postgresql.org>
2026-11-17 23:53 pgsql: Resolve mismatch between JIT and non-JIT hashing David Rowley <drowley@postgresql.org>
2026-11-17 23:53 pgsql: Resolve mismatch between JIT and non-JIT hashing David Rowley <drowley@postgresql.org>

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