Re: Planner should use index on a LIKE 'foo%' query - Mailing list pgsql-performance

From Dimitri Fontaine
Subject Re: Planner should use index on a LIKE 'foo%' query
Date
Msg-id 200806301220.43392.dfontaine@hi-media.com
Whole thread Raw
In response to Planner should use index on a LIKE 'foo%' query  (Moritz Onken <onken@houseofdesign.de>)
List pgsql-performance
Hi,

Le samedi 28 juin 2008, Moritz Onken a écrit :
> select count(*)
>   from result
>   where exists
>     (select * from item where item.url LIKE result.url || '%' limit 1);
>
> which basically returns the number of items which exist in table
> result and match a URL in table item by its prefix.

It seems you could benefit from the prefix project, which support indexing
your case of prefix searches. Your query would then be:
  SELECT count(*) FROM result r JOIN item i ON r.url @> i.url;

The result.url column would have to made of type prefix_range, which casts
automatically to text when needed.

Find out more about the prefix projects at those urls:
  http://pgfoundry.org/projects/prefix
  http://prefix.projects.postgresql.org/README.html

Regards,
--
dim

Attachment

pgsql-performance by date:

Previous
From: Matthew Wakeling
Date:
Subject: Re: Planner should use index on a LIKE 'foo%' query
Next
From: John Beaver
Date:
Subject: Re: sequence scan problem