LIKE conditions in PGSQL very, very slow!

From: "(dot)ep" <erick(dot)papa(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: LIKE conditions in PGSQL very, very slow!
Date: 2007-08-11 02:36:09
Message-ID: 1186799769.611683.163150@x40g2000prg.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I'm moving from the mysql camp and quite liking things like functions
and such, but a lot of my functionality depends on queries such as

SELECT id, name, start_date
FROM customer
WHERE name LIKE 'eri%';

These kinds of queries are super fast in MySQL because "eri%" type
conditions also use the index. Is this not the case with PG?

Here's the EXPLAIN output:

CUSTDB=# explain select id,name,start_date from customer where name
like 'eri%';
QUERY PLAN
----------------------------------------------------------------
Seq Scan on customer (cost=0.00..86032.18 rows=1 width=111)
Filter: ((name)::text ~~ 'eri%'::text)
(2 rows)

Would appreciate any thoughts on how to make these kinds of queries
faster. I found a message (http://archives.postgresql.org/pgsql-sql/
1999-12/msg00218.php) but that's from 1999.

While we're at it, are compound indexes ok in PGSQL as well? In MySQL,
the order of columns is important if it reflects my WHERE conditions
in SQL. Should I follow the same structure in PGSQL? I tried looking
at the manual but did not find a section that talks about indexing in
detail. Would appreciate pointers.

Thanks!

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2007-08-11 03:06:42 Re: LIKE conditions in PGSQL very, very slow!
Previous Message Peter Marius 2007-08-11 00:40:03 Re: CREATE RULE on VIEW with INSERT after UPDATE does not work