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.96) (envelope-from ) id 1w5pQD-003fgd-1X for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Mar 2026 18:27:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5pQB-004gbf-1w for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Mar 2026 18:27:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w5pQB-004gbW-0p for pgsql-hackers@lists.postgresql.org; Thu, 26 Mar 2026 18:27:07 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w5pQ5-00000001Kia-3iqE for pgsql-hackers@postgresql.org; Thu, 26 Mar 2026 18:27:07 +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 62QIQhmO1017963; Thu, 26 Mar 2026 14:26:43 -0400 From: Tom Lane To: Jeff Davis cc: David Geier , pgsql-hackers , Heikki Linnakangas , Peter Eisentraut Subject: Re: Use correct collation in pg_trgm In-reply-to: <677b2db1582d9eb9e099ea83856e610a5072dcd3.camel@j-davis.com> References: <2c15502fd399128ee27fbe1a305e006780159f66.camel@j-davis.com> <7e11acde-9d5b-49a1-9c41-23096d51d2e2@gmail.com> <677b2db1582d9eb9e099ea83856e610a5072dcd3.camel@j-davis.com> Comments: In-reply-to Jeff Davis message dated "Thu, 26 Mar 2026 11:12:14 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1017961.1774549603.1@sss.pgh.pa.us> Date: Thu, 26 Mar 2026 14:26:43 -0400 Message-ID: <1017962.1774549603@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Jeff Davis writes: > On Thu, 2026-03-26 at 09:50 +0100, David Geier wrote: >> I agree. That is inconsistent. But if anything, shouldn't we change >> tsvector/tsquery to as well adhere to the inferred collation? > I am not sure either way. > It's easy to specify a COLLATE clause to affect the interpretation of > the input. But once you parse the inputs into a stored value, you can't > later reinterpret those values by specifying a COLLATE clause. The > parsing already happened and the original input string was lost. > You can end up with a table full of values, some of which were parsed > with one set of semantics, and others parsed with a different set of > semantics. That may make sense or it may just cause confusion. It's > tough for me to say. The rule that text search goes by is that it's okay to be a bit fuzzy about this because people are usually looking for approximate matches, so that even if you have sets of lexemes that were extracted under slightly different parsing rules you can probably still find what you want. While that argument still works for pg_trgm's original "similarity" functions, it falls flat for the LIKE/ILIKE/regex index support functionality: people will be justifiably unhappy if the index doesn't find the exact same matches that a seqscan-and-filter would. I've not experimented, but I rather imagine that things are already buggy as heck, in that optimizing a LIKE or regex expression that's got collation A applied to it into an indexscan on a pg_trgm index made with collation B will not work if different trigrams get extracted. I think we have to insist that the index collation match the query. Once we've done that, the concern about making a change like this seems less: you will not get wrong answers, rather the planner will refuse to use an incompatible index. regards, tom lane