pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: SIMILAR TO expressions translate wildcards where they shouldn't
Date: Tue, 27 May 2025 10:54:12 -0400
Message-ID: <1101508.1748357652@sss.pgh.pa.us> (raw)
In-Reply-To: <37584c1321b984a0c5c05d213ef70b869d95a12a.camel@cybertec.at>
References: <16ab039d1af455652bdf4173402ddda145f2c73b.camel@cybertec.at>
	<aC_K7JPXF0AdPZqB@paquier.xyz>
	<aC_p7b5H6pLICU_e@paquier.xyz>
	<5498224d1d5a6a3be7f29ae7725f76162d48372f.camel@cybertec.at>
	<aDVUWaoZg8cW3B9x@paquier.xyz>
	<37584c1321b984a0c5c05d213ef70b869d95a12a.camel@cybertec.at>

Laurenz Albe <laurenz.albe@cybertec.at> 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





view thread (11+ messages)  latest in thread

Message-ID: <1101508.1748357652@sss.pgh.pa.us>
Permalink:  ../1101508.1748357652@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1101508.1748357652@sss.pgh.pa.us

 · 

reply

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, laurenz.albe@cybertec.at, michael@paquier.xyz, pgsql-bugs@lists.postgresql.org
  Subject: Re: SIMILAR TO expressions translate wildcards where they shouldn't
  In-Reply-To: <1101508.1748357652@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