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 1uJvh4-009YlH-4r for pgsql-bugs@arkaria.postgresql.org; Tue, 27 May 2025 14:54:18 +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 1uJvh2-008fVs-Rn for pgsql-bugs@arkaria.postgresql.org; Tue, 27 May 2025 14:54:16 +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 1uJvh2-008fTK-JB for pgsql-bugs@lists.postgresql.org; Tue, 27 May 2025 14:54:16 +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 1uJvh0-000DXp-2r for pgsql-bugs@lists.postgresql.org; Tue, 27 May 2025 14:54:15 +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 54REsCYu1101509; Tue, 27 May 2025 10:54:12 -0400 From: Tom Lane To: Laurenz Albe cc: Michael Paquier , pgsql-bugs@lists.postgresql.org Subject: Re: SIMILAR TO expressions translate wildcards where they shouldn't In-reply-to: <37584c1321b984a0c5c05d213ef70b869d95a12a.camel@cybertec.at> References: <16ab039d1af455652bdf4173402ddda145f2c73b.camel@cybertec.at> <5498224d1d5a6a3be7f29ae7725f76162d48372f.camel@cybertec.at> <37584c1321b984a0c5c05d213ef70b869d95a12a.camel@cybertec.at> Comments: In-reply-to Laurenz Albe message dated "Tue, 27 May 2025 12:24:33 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1101507.1748357652.1@sss.pgh.pa.us> Date: Tue, 27 May 2025 10:54:12 -0400 Message-ID: <1101508.1748357652@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe writes: > On Tue, 2025-05-27 at 14:57 +0900, Michael Paquier wrote: >> With some tweaks and the tests reworked, I am finishing with the >> reviewed version attached. What do you think? > Thank you; I think that is good to go. Code changes look good, but I think the test cases are too cute: +EXPLAIN (VERBOSE, COSTS OFF) SELECT (SELECT '') SIMILAR TO '_[_[:alpha:]_]_'; + QUERY PLAN +--------------------------------------------------------------- + Result + Output: ((InitPlan 1).col1 ~ '^(?:.[_[:alpha:]_].)$'::text) + InitPlan 1 + -> Result + Output: ''::text +(5 rows) This will break whenever somebody decides it's worth optimizing a sub-select that looks like that. I'd suggest following the pattern explain (costs off) select * from text_tbl where f1 similar to 'z'; QUERY PLAN ---------------------------------- Seq Scan on text_tbl Filter: (f1 ~ '^(?:z)$'::text) (2 rows) which is both less noisy and less likely to change in future. regards, tom lane