From: Tom Lane <tgl@sss.pgh.pa.us>
To: Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
Cc: washwithcare@gmail.com, pgsql-bugs@lists.postgresql.org, Nikita Glukhov <glukhov.n.a@gmail.com>
Cc: Alexander Korotkov <aekorotkov@gmail.com>
Subject: Re: BUG #19031: pg_trgm infinite loop on certain cases
Date: Wed, 27 Aug 2025 10:32:26 -0400
Message-ID: <1391111.1756305146@sss.pgh.pa.us> (raw)
In-Reply-To: <CAE7r3MK19VyQU_K2EYasMaUBNBd9n82qAmTfvq+vGFr320ZM=A@mail.gmail.com>
References: <19031-0638148643d25548@postgresql.org>
<969700.1756169663@sss.pgh.pa.us>
<CAE7r3MJp=0BHQLU_GpHdXJH=Dub+gvtuOziyin3oZyZO9tG-cw@mail.gmail.com>
<1081531.1756221406@sss.pgh.pa.us>
<CAE7r3MK19VyQU_K2EYasMaUBNBd9n82qAmTfvq+vGFr320ZM=A@mail.gmail.com>
Arseniy Mukhin <arseniy.mukhin.dev@gmail.com> writes:
> Good point, thanks for the explanation. I forgot that there can be
> many attributes. And I agree, the more determinism in the system, the
> easier it is to work with it and the less room for bugs. OTOH it seems
> from the performance POV we want to have the stricter keys to be the
> first so we do less work and fail fast on the first keys. It looks
> like these two rules (excludeOnly keys LAST and more restrictive keys
> FIRST) are kind of in conflict with each other. I tried to do some
> experiments and it's seems GIN quite sensitive to it, at least in this
> artificial example:
Yeah, it is. I recall seeing some comments to the effect that
optimizing the order of scan keys would be a good thing, but if there
is any code in there that tries to do so, I'm not seeing where.
Seems like a fertile area for future research.
> With applying patch both queries show the same time (second one). So
> currently the user can tune the query by defining more restrictive
> keys first. With the proposed fix it looks like users will have less
> freedom here.
I think most people would consider it a bug if they have to tune the
order of the WHERE clauses manually. The original statement of the
current bug was basically that: it worked in one order and not the
other.
regards, tom lane
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, arseniy.mukhin.dev@gmail.com, glukhov.n.a@gmail.com, aekorotkov@gmail.com
Subject: Re: BUG #19031: pg_trgm infinite loop on certain cases
In-Reply-To: <1391111.1756305146@sss.pgh.pa.us>
* 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