Re: PG 18 JIT regression: int4range hash breaks multi-key GROUP BY

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Tor Erik Linnerud <tel(at)jklm(dot)no>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: PG 18 JIT regression: int4range hash breaks multi-key GROUP BY
Date: 2026-11-16 22:34:21
Message-ID: CAApHDvq1ExPa97Cx7XKpJaSo7==c9zfmksOy2jHMXVhVRweTZQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, 17 Nov 2026 at 00:27, Tor Erik Linnerud <tel(at)jklm(dot)no> wrote:
> create table t as
> select (random() * 1000)::int as p, random() < 0.5 as b,
> int4range(d, d + 10) as r
> from (select (random() * 20)::int * 10 as d from generate_series(1, 1000000)) s;
> analyze t;
> set max_parallel_workers_per_gather = 0;
> set enable_sort = off;
> set jit = on;
> set jit_above_cost = 0;
>
> -- slow on 18: range key followed by another key
> select count(*) from (select p, r, b from t group by 1, 2, 3) s;

Many thanks for the clear and concise report and reproducer. That's
becoming rare.

The attached patch resolves the issue. I had to use a bit of LLM as I
previously didn't find the proper way to trim the result to 32-bit. I
had been using LLVMBuildAnd with l_datum_const(0xffffffff). The
documentation for all this stuff seems nonexistent. The LLM tells I
should have used LLVMBuildTrunc(), which the patch does, and now I'm
truncating before the shift and xor then doing the zero-extend back to
64-bit before storing the result.

I did some analysis when patched with:

--- a/src/backend/executor/execGrouping.c
+++ b/src/backend/executor/execGrouping.c
@@ -413,6 +413,7 @@ LookupTupleHashEntry(TupleHashTable hashtable,
TupleTableSlot *slot,
hashtable->cur_eq_func = hashtable->tab_eq_func;

local_hash = TupleHashTableHash_internal(hashtable->hashtab, NULL);
+ elog(NOTICE, "%u", local_hash);
entry = LookupTupleHashEntry_internal(hashtable, slot, isnew,
local_hash);

if (hash != NULL)

and diffed the output with jit=1 vs jit=0. Running your query now
produces the same hash values with and without jit.

David

Attachment Content-Type Size
v1-0001-Resolve-mismatch-between-JIT-and-non-JIT-hashing.patch application/octet-stream 4.6 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Andres Freund 2026-11-16 22:39:28 Re: 16.16: join order regression for pg_indexes self-join (schema filter applied last), ~50x slower than 16.15
Previous Message Tom Lane 2026-11-16 21:51:58 Re: BUG #19908: pg_upgrade --check crashes instance if running in a different PID Namespace then the old cluster