Re: Index to support LIKE '%suffix' queries - Mailing list pgsql-sql

From Alvaro Herrera
Subject Re: Index to support LIKE '%suffix' queries
Date
Msg-id 20060225181346.GA6092@surnet.cl
Whole thread Raw
In response to Re: Index to support LIKE '%suffix' queries  (Florian Weimer <fw@deneb.enyo.de>)
Responses Re: Index to support LIKE '%suffix' queries  (Florian Weimer <fw@deneb.enyo.de>)
List pgsql-sql
> > Florian Weimer <fw@deneb.enyo.de> writes:
> >> Is it possible to create an index to support queries of the form
> >> "column LIKE '%suffix'" (similar to an ordinary index for LIKE
> >> 'prefix%', which I also need)?

It is possible to create a functional index on the reverse of the
string.  You need to also reverse the patter at query-time as well.
This will make the % be at the end of the pattern, making it an
indexable condition.

Whether or not this beats tsearch2 is something you should investigate ...

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


pgsql-sql by date:

Previous
From: Florian Weimer
Date:
Subject: Re: Index to support LIKE '%suffix' queries
Next
From: "Yasuhiro Furuse"
Date:
Subject: Re: Relation 0 does not exist