Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1urHCQ-003Rv4-6P for pgsql-bugs@arkaria.postgresql.org; Wed, 27 Aug 2025 14:32:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1urHCP-00Fnl7-Hn for pgsql-bugs@arkaria.postgresql.org; Wed, 27 Aug 2025 14:32:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1urHCP-00Fnkz-9V for pgsql-bugs@lists.postgresql.org; Wed, 27 Aug 2025 14:32:29 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1urHCN-0021rS-1P for pgsql-bugs@lists.postgresql.org; Wed, 27 Aug 2025 14:32:29 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 57REWQlM1391112; Wed, 27 Aug 2025 10:32:26 -0400 From: Tom Lane To: Arseniy Mukhin cc: washwithcare@gmail.com, pgsql-bugs@lists.postgresql.org, Nikita Glukhov , Alexander Korotkov Subject: Re: BUG #19031: pg_trgm infinite loop on certain cases In-reply-to: References: <19031-0638148643d25548@postgresql.org> <969700.1756169663@sss.pgh.pa.us> <1081531.1756221406@sss.pgh.pa.us> Comments: In-reply-to Arseniy Mukhin message dated "Wed, 27 Aug 2025 11:33:03 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1391110.1756305146.1@sss.pgh.pa.us> Date: Wed, 27 Aug 2025 10:32:26 -0400 Message-ID: <1391111.1756305146@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Arseniy Mukhin 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