Re: Optimizing a like-cause - Mailing list pgsql-general

From Tom Lane
Subject Re: Optimizing a like-cause
Date
Msg-id 5141.1216763174@sss.pgh.pa.us
Whole thread Raw
In response to Re: Optimizing a like-cause  ("Dann Corbit" <DCorbit@connx.com>)
List pgsql-general
"Dann Corbit" <DCorbit@connx.com> writes:
>>> I'm developing a autocomplete Feature using php and PostgreSQL 8.3.
>>> To fill the autocomplete box I use the following SQL Statement:
>>> select * from _table_ where upper( _field_ ) like '%STRING%';
>>> This SQL Statement takes 900 ms on a Table with 300.000 entries.

> What you are asking for is very difficult, because an ordinary index
> won't help (you have a wildcard on the front) and an index on the
> reversed word won't help either (you have a wildcard on the back).

Actually ... if the usage is autocompletion, why in the world is the
OP searching for '%STRING%' and not 'STRING%'?  If I type "bar<TAB>",
I certainly don't expect to be offered "foobar" as one of the possible
completions.

This makes a difference since an anchored-left pattern *can* be searched
for using a standard index ...

            regards, tom lane

pgsql-general by date:

Previous
From: "Dann Corbit"
Date:
Subject: Re: Optimizing a like-cause
Next
From: "Francisco Reyes"
Date:
Subject: Re: Substitute a variable in PL/PGSQL.