Docs off on ILIKE indexing?

Started by Magnus Haganderabout 20 years ago5 messageshackersdocs
Jump to latest
#1Magnus Hagander
magnus@hagander.net
hackers

http://www.postgresql.org/docs/8.1/static/indexes-types.html

says:
The optimizer can also use a B-tree index for queries involving the
pattern matching operators LIKE, ILIKE, ~, and ~*, if the pattern is a
constant and is anchored to the beginning of the string - for example,
col LIKE 'foo%' or col ~ '^foo', but not col LIKE '%bar'.

But really, does it use indexes for ILIKE? (And I assume the same holds
for case insensitive regexp matching)

(If it does, can someone enlighten me on what I have to do - I have a
system with C locale that refuses to do it for ILIKE, but works just
fine for LIKE. My workaronud for now is to create an index on lower(foo)
and then use WHERE lower(foo) LIKE 'bar%' which works fine - but it does
require an extra index..)

So. Am I off, or are the docs? Or is it just me who can't read ;-)

//Magnus

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Magnus Hagander (#1)
hackers
Re: Docs off on ILIKE indexing?

"Magnus Hagander" <mha@sollentuna.net> writes:

http://www.postgresql.org/docs/8.1/static/indexes-types.html
says:
The optimizer can also use a B-tree index for queries involving the
pattern matching operators LIKE, ILIKE, ~, and ~*, if the pattern is a
constant and is anchored to the beginning of the string - for example,
col LIKE 'foo%' or col ~ '^foo', but not col LIKE '%bar'.

But really, does it use indexes for ILIKE?

That's pretty poorly phrased. For ILIKE it'll only work if there's a
prefix of the pattern that's not letters (and hence is unaffected by
the case-folding issue).

regards, tom lane

#3Magnus Hagander
magnus@hagander.net
In reply to: Tom Lane (#2)
hackersdocs
Re: Docs off on ILIKE indexing?

http://www.postgresql.org/docs/8.1/static/indexes-types.html
says:
The optimizer can also use a B-tree index for queries involving the
pattern matching operators LIKE, ILIKE, ~, and ~*, if the

pattern is a

constant and is anchored to the beginning of the string -

for example,

col LIKE 'foo%' or col ~ '^foo', but not col LIKE '%bar'.

But really, does it use indexes for ILIKE?

That's pretty poorly phrased. For ILIKE it'll only work if
there's a prefix of the pattern that's not letters (and hence
is unaffected by the case-folding issue).

Ahh. That explains it. Perfectly logical.
And yes, that's pretty poorly phrased - at least I didn't understand it
:-)

//Magnus

#4Jim Nasby
Jim.Nasby@BlueTreble.com
In reply to: Magnus Hagander (#3)
hackersdocs
Re: [HACKERS] Docs off on ILIKE indexing?

On Tue, Jan 17, 2006 at 03:44:30PM +0100, Magnus Hagander wrote:

http://www.postgresql.org/docs/8.1/static/indexes-types.html
says:
The optimizer can also use a B-tree index for queries involving the
pattern matching operators LIKE, ILIKE, ~, and ~*, if the

pattern is a

constant and is anchored to the beginning of the string -

for example,

col LIKE 'foo%' or col ~ '^foo', but not col LIKE '%bar'.

But really, does it use indexes for ILIKE?

That's pretty poorly phrased. For ILIKE it'll only work if
there's a prefix of the pattern that's not letters (and hence
is unaffected by the case-folding issue).

Ahh. That explains it. Perfectly logical.
And yes, that's pretty poorly phrased - at least I didn't understand it
:-)

I was going to submit a patch on this, and the best way seems to be
adding a note to 'ILIKE', specifying that it will only work if there's a
prefix to the pattern that isn't letters. Is there a standard way to tag
a word indicating that there's a note?
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

#5Bruce Momjian
bruce@momjian.us
In reply to: Jim Nasby (#4)
hackersdocs
Re: [HACKERS] Docs off on ILIKE indexing?

I have applied the following patch to clarify the current behavior.
Thanks.

---------------------------------------------------------------------------

Jim C. Nasby wrote:

On Tue, Jan 17, 2006 at 03:44:30PM +0100, Magnus Hagander wrote:

http://www.postgresql.org/docs/8.1/static/indexes-types.html
says:
The optimizer can also use a B-tree index for queries involving the
pattern matching operators LIKE, ILIKE, ~, and ~*, if the

pattern is a

constant and is anchored to the beginning of the string -

for example,

col LIKE 'foo%' or col ~ '^foo', but not col LIKE '%bar'.

But really, does it use indexes for ILIKE?

That's pretty poorly phrased. For ILIKE it'll only work if
there's a prefix of the pattern that's not letters (and hence
is unaffected by the case-folding issue).

Ahh. That explains it. Perfectly logical.
And yes, that's pretty poorly phrased - at least I didn't understand it
:-)

I was going to submit a patch on this, and the best way seems to be
adding a note to 'ILIKE', specifying that it will only work if there's a
prefix to the pattern that isn't letters. Is there a standard way to tag
a word indicating that there's a note?
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Attachments:

/bjm/difftext/plainDownload+22-21