Re: Slow Queries with OR's?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: psql-mail(at)freeuk(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Slow Queries with OR's?
Date: 2003-05-02 13:33:43
Message-ID: 10005.1051882423@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mr Mat psql-mail <psql-mail(at)freeuk(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2003-05-02 14:13:29 Re: Slow Queries with OR's?
Previous Message Manfred Koizar 2003-05-02 10:34:54 Re: fixed size columns