Re: BUG #2050: Bad plan by using of LIKE - Mailing list pgsql-bugs

From Bernhard Weisshuhn
Subject Re: BUG #2050: Bad plan by using of LIKE
Date
Msg-id 20051118145251.GA10668@weisshuhn.de
Whole thread Raw
In response to BUG #2050: Bad plan by using of LIKE  ("Johannes" <postgres@arltus.de>)
List pgsql-bugs
On Thu, Nov 17, 2005 at 06:00:35PM +0000, Johannes <postgres@arltus.de> wrote:

> SELECT title FROM content WHERE title LIKE 'teane%';
>
> It uses to long time, I compare this with sybase
> and I was disappointed, but explain shows the reason.
>
>
> EXPLAIN SELECT title FROM content WHERE title LIKE 'teane%';
> Seq Scan on content  (cost=0.00..75647.59 rows=1 width=68)
>    Filter: (title ~~ 'teane%'::text)
>
> Now I change this SQL to:
> SELECT title FROM content WHERE title >= 'teane' AND title < 'teanez';
>
> I think it means the same but it works very fast by using my index.
> (1600 ms up to 2 ms !! sybase uses 4 ms)


You might want to take a look at

  http://www.postgresql.org/docs/8.1/interactive/indexes-opclass.html

and build your indexes on text fields with *_pattern_ops from now on.
Does the trick.

cheers,
bkw

pgsql-bugs by date:

Previous
From: "Magnus Hagander"
Date:
Subject: Re: BUG #2052: Federal Agency Tech Hub Refuses to Accept Postgresql on Network because of Security Vulnerabilities
Next
From: Alvaro Herrera
Date:
Subject: Re: BUG #2047: Can't get to mirrors