Re: Optimizing a like-cause

From: "Adam Rich" <adam(dot)r(at)sbcglobal(dot)net>
To: "'Stefan Sturm'" <stefan(dot)s(dot)sturm(at)googlemail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Optimizing a like-cause
Date: 2008-07-22 20:36:13
Message-ID: 032401c8ec3a$9556c850$c00458f0$@r@sbcglobal.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>
> Hello,
>
> 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 can I do to speed up the Statement? What Index can I set?
>

The open-ended search is what's killing you. Can you change your
query to be like this?

select * from _table_ where _field_ like 'STRING%';

That allows the database to use an index. You'll still have to
either store the data already in upper-case format, or use a
functional index on upper(field).

http://www.postgresql.org/docs/8.3/interactive/indexes-expressional.html

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rich Shepard 2008-07-22 20:51:48 Re: Problems Restarting PostgreSQL Daemon
Previous Message Alan Hodgson 2008-07-22 20:30:11 Re: Optimizing a like-cause