Re: Slow Queries with OR's? - Mailing list pgsql-general

From Tom Lane
Subject Re: Slow Queries with OR's?
Date
Msg-id 10005.1051882423@sss.pgh.pa.us
Whole thread Raw
In response to Re: Slow Queries with OR's?  (Mr Mat psql-mail <psql-mail@freeuk.com>)
List pgsql-general
Mr Mat psql-mail <psql-mail@freeuk.com> writes:
> I have now gone back to my original query shown below:

> SELECT msg_id, from_line, col_date FROM news_messages WHERE msg_id IN(
> SELECT msg_id FROM news_msg_id_ng_id_link WHERE ng_id IN(
> SELECT ng_id FROM news_ng_genre_link WHERE genre_id in (3,6)
> )
> )

I think all you can do with this is transform the outer IN into EXISTS
and make sure there's an index on news_msg_id_ng_id_link.msg_id.  See
the FAQ item about slow IN's for details.

7.4 will do this a lot better, but for now you need a workaround...

            regards, tom lane


pgsql-general by date:

Previous
From: Manfred Koizar
Date:
Subject: Re: fixed size columns
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Slow Queries with OR's?