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

From: Tor Erik Linnerud <tel(at)jklm(dot)no>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: PG 18 JIT regression: int4range hash breaks multi-key GROUP BY
Date: 2026-11-16 11:26:36
Message-ID: CAEGP1v12rRmZo1h3KZ+ZCS66A9xLoSOuLAyBXu92nd97E3jJPw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 18.6, a hash aggregate grouping by an int4range column followed by
another column is several hundred times slower than on 17 when JIT is used.
Same data, official Docker images, jit_above_cost = 0:

GROUP BY p, r, b (range not last):
17.12: 0.48 s
18.6: 188 s

GROUP BY p, b, r (range last):
17.12: 0.45 s
18.6: 0.39 s

With jit = off, 18.6 is fast.

Likely cause: in llvmjit_expr.c, EEOP_HASHDATUM_NEXT32 combines the hash
function's full 64-bit Datum. hash_range returns its hash via
PG_RETURN_INT32, which sign-extends, and the next column's rotate then
shifts those upper bits into the combined hash, wiping it. The interpreter
truncates to 32 bits and is not affected.

Reproduction:

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;

-- fast: same groups, range key last
select count(*) from (select p, b, r from t group by 1, 2, 3) s;

Best,
Tor Erik

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Andrey Borodin 2026-11-16 12:08:50 Re: Timing issue in pg_basebackup
Previous Message Aleksander Alekseev 2026-11-16 10:45:34 Re: BUG #19772: ERROR: corrupt MVNDistinct entry for GROUP BY c0, ROLLUP (abs(c0)) with ndistinct statistics