Re: LIKE indexing - Mailing list pgsql-patches

From Peter Eisentraut
Subject Re: LIKE indexing
Date
Msg-id Pine.LNX.4.30.0108201732120.822-100000@peter.localdomain
Whole thread Raw
In response to Re: LIKE indexing  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: LIKE indexing  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
Tom Lane writes:

> The "but not" part is wrong: col LIKE 'bar' works perfectly fine as
> an indexable LIKE query.  Perhaps you meant "but not col LIKE '%foo'".

Thanks.  That was a mixup with the POSIX regexp style.

> While it's okay to treat text and varchar alike, I object to treating
> bpchar as equivalent to the other two.  Shouldn't the bpchar versions of
> these functions strip trailing spaces before comparing?

I had thought a long time about this and I couldn't see a reason why.
The reason is that the LIKE operator for bpchar does take the blanks into
account, so it effectively doesn't care whether the blanks are the result
of padding or explicit input.  E.g.,

peter=# set enable_indexscan to off;
SET VARIABLE
peter=# create table test1 (a char(5));
CREATE
peter=# insert into test1 values ('four');
INSERT 16560 1
peter=# select * from test1 where a like 'four'::bpchar;
 a
---
(0 rows)

/*
 * If we had stripped spaces here we would have gotten a false positive.
 */

peter=# select * from test1 where a like 'fou_'::bpchar;
 a
---
(0 rows)

/*
 * Since the padding here is after the wildcard character and is thus
 * stripped in the analysis, the augmented expression still holds.
 */

peter=# select * from test1 where a like 'fou%'::bpchar;
   a
-------
 four
(1 row)

/* same here */

I would also argue that the notion of a direct binary comparision would
not benefit from space stripping.

> Seems to me you should provide "$<>$" operators for completeness, even
> though they're not essential for btree opclasses.

Will do.

> I don't like the fact that you added expected-output rows to opr_sanity;
> seems like tweaking the queries to allow $<$ etc as expected names would
> be more appropriate.

Ok.

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: New version of XML support routines (0.2)
Next
From: Bruce Momjian
Date:
Subject: Re: Patch: use SCM_CREDS authentication over PF_LOCAL sockets