Re: How to force Postgres to use index on ILIKE

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Cc: "Andrus" <eetasoft(at)online(dot)ee>
Subject: Re: How to force Postgres to use index on ILIKE
Date: 2006-06-05 21:26:56
Message-ID: 200606051426.56789.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Andrus,

> SELECT toode, nimetus
> FROM toode
> WHERE toode ILIKE 'x10%' ESCAPE '!'
> ORDER BY UPPER(toode ),nimetus LIMIT 100
>
> runs 1 minute in first time for small table size.
>
> Toode field type is CHAR(20)

1) why are you using CHAR and not VARCHAR or TEXT? CHAR will give you
problems using an index, period.

2) You can't use an index on ILIKE. You can, however, use an index on
lower(field) if your query is properly phrased and if you've created an
expression index on lower(field).

--
--Josh

Josh Berkus
PostgreSQL @ Sun
San Francisco

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Chris Beecroft 2006-06-05 22:22:00 Re: Some queries starting to hang
Previous Message Tom Lane 2006-06-05 21:06:31 Re: Some queries starting to hang