Re: Like 'name%' is not using index

From: Greg Stark <gsstark(at)mit(dot)edu>
To: "Jozsef Szalay" <jszalay(at)storediq(dot)com>
Cc: <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Like 'name%' is not using index
Date: 2006-03-03 04:01:39
Message-ID: 877j7cuqfw.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


"Jozsef Szalay" <jszalay(at)storediq(dot)com> writes:

> One would
> think that Postgres will use the index to look up the matches, but
> apparently that is not the case. It performs a full table scan. My
> query looks something like this:
>
> SELECT * FROM table WHERE name LIKE 'smith%';

There are two possible answers here:

First, what does this output on your database?

db=> show lc_collate;

If it's not "C" then the index can't be used. You would have to make a second
special-purpose index specifically for use with LIKE.

Secondly, please send "explain analyze" output for your query. It will show if
the optimizer is simply estimating that the index won't help enough to be
faster than the full table scan.

--
greg

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Paul Mackay 2006-03-03 10:03:24 Physical column size
Previous Message Jozsef Szalay 2006-03-03 02:48:51 Re: Like 'name%' is not using index