Re: [repost] partial index / funxtional idx or bad sql? - Mailing list pgsql-performance

From Josh Berkus
Subject Re: [repost] partial index / funxtional idx or bad sql?
Date
Msg-id 200305121713.38449.josh@agliodbs.com
Whole thread Raw
In response to [repost] partial index / funxtional idx or bad sql?  (csajl <csajl@yahoo.com>)
Responses Re: [repost] partial index / funxtional idx or bad sql?
List pgsql-performance
Seth,

> SELECT p.id, p.areacode, p.content
> FROM posts p
> WHERE p.type_id = ?
> AND p.areacode in (
>   select areacode from areacodes
>    where site_id = ?
>  )

Unless you're using 7.4 from CVS, you want to get rid of that IN:

 SELECT p.id, p.areacode, p.content
 FROM posts p
 WHERE p.type_id = ?
 AND EXISTS (
  select areacode from areacodes
    where site_id = ?
    and p.areacode = areacodes.areacode
  );

See how that works, and if it's still slow, post the EXPLAIN ANALYZE.


--
-Josh Berkus
 Aglio Database Solutions
 San Francisco


pgsql-performance by date:

Previous
From: csajl
Date:
Subject: [repost] partial index / funxtional idx or bad sql?
Next
From: csajl
Date:
Subject: Re: [repost] partial index / funxtional idx or bad sql?