Re: Reduce build times of pg_trgm GIN indexes

From: Kirill Reshke <reshkekirill(at)gmail(dot)com>
To: David Geier <geidav(dot)pg(at)gmail(dot)com>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, Japin Li <japinli(at)hotmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Reduce build times of pg_trgm GIN indexes
Date: 2026-11-09 21:10:41
Message-ID: CALdSSPj0amESJpj0FYoruotCOHAQf6UeJyb_JsyKAe2n98gdrQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 9 Nov 2026 at 20:34, David Geier <geidav(dot)pg(at)gmail(dot)com> wrote:
>
> > Committed
> > v11-0001-Use-branchless-comparisons-in-btint4cmp-and-btin.patch, since
> > that one seems uncontroversial. Thanks!
>
> Thanks!
>
> >> In the case of btint4cmp(), it's only ever invoked from the function
> >> manager, where it cannot be inlined.
> >>
> >> Or are there ways to invoke btint4cmp() that can be inlined, which I'm
> >> unaware of?
> >
> > JIT compilation, maybe? Unless someone shows that there's a measurable
> > problem though, I wouldn't worry about it.
>
> Yes, but I reasoned that when inlined via JIT it's not used by a
> sort_template.h
>
> --
> David Geier
>
>

Hi! I think there is a regression with numeric[]. Equal numeric values
can have different scales, so e.g. 1, 1.0 have different byte images.
The RB-tree accumulator combines them by comparator equality while the
hash keeps a separate entry for each image.

example (no pg_trgm extension required):

SET max_parallel_maintenance_workers = 0;
SET maintenance_work_mem = '256MB';
CREATE TABLE numeric_many AS
SELECT i, ARRAY[round((i%100)::numeric, ((i/100)%256)::int)] AS a
FROM generate_series(1,1000000) AS i;
VACUUM (FREEZE, ANALYZE) numeric_many;
SELECT count(*), count(DISTINCT a[1]),
count(DISTINCT encode(numeric_send(a[1]),'hex')) FROM numeric_many;

in my run size of patch index is 7.3532338308457711x bigger and build
time is 4.0799353308331456x longer

--
Best regards,
Kirill Reshke

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Rafael Chacón 2026-11-09 21:11:19 Re: Table synchronization cannot resume after a subscriber crash
Previous Message Nathan Bossart 2026-11-09 20:50:21 Re: Logical Implication