pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dimitri Fontaine <dfontaine@hi-media.com>
To: pgsql-performance@postgresql.org
Cc: Moritz Onken <onken@houseofdesign.de>
Subject: Re: Planner should use index on a LIKE 'foo%' query
Date: Mon, 30 Jun 2008 12:20:40 +0200
Message-ID: <200806301220.43392.dfontaine@hi-media.com> (raw)
In-Reply-To: <287E4428-BECC-46D6-BC47-EA94EA0121F0@houseofdesign.de>
References: <287E4428-BECC-46D6-BC47-EA94EA0121F0@houseofdesign.de>

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

Attachments:

  signature.asc (application/pgp-signature, 196B) download

view thread (12+ messages)  latest in thread

Message-ID: <200806301220.43392.dfontaine@hi-media.com>
Permalink:  ../200806301220.43392.dfontaine@hi-media.com/
Also on:    postgresql.org/message-id/200806301220.43392.dfontaine@hi-media.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: dfontaine@hi-media.com, onken@houseofdesign.de
  Subject: Re: Planner should use index on a LIKE 'foo%' query
  In-Reply-To: <200806301220.43392.dfontaine@hi-media.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox