Re: Use of subquery causes seq scan??? - Mailing list pgsql-performance

From Bruno Wolff III
Subject Re: Use of subquery causes seq scan???
Date
Msg-id 20040420175632.GB11203@wolff.to
Whole thread Raw
In response to Use of subquery causes seq scan???  ("Chris Hoover" <revoohc@sermonaudio.com>)
List pgsql-performance
Please don't reply to messages to start new threads.

On Tue, Apr 20, 2004 at 10:20:05 -0400,
  Chris Hoover <revoohc@sermonaudio.com> wrote:
> I need some help.  I have a query that refuses to use the provided index and
> is always sequentially scanning causing me large performance headaches.  Here
> is the basic situation:
>
> Table A:
> inv_num int
> type        char
> .
> .
> .
> pkey (inv_num, type)
> indx(inv_num)
>
> Table B (has the same primary key)
>
> Select *
> from table a
> where inv_num in (select inv_num from table b where ....)
>
> Doing this causes sequential scans of both tables.  If I do a set
> enable_seqscan to false before the query, I get an index scan of table b but
> still seq scan table a.
>
> Is there anyway to force table a to use this index (or another) and not
> sequentially scan the table?
>
> I'm running 7.3.4 on RedHat EL 2.1.

IN was slow in 7.3.x and before. The query will probably run much better
as is in 7.4 and above. In 7.3 you want to rewrite it as a join or using
EXISTS.

pgsql-performance by date:

Previous
From: Josh Berkus
Date:
Subject: Re: Wierd context-switching issue on Xeon
Next
From: Pailloncy Jean-Gérard
Date:
Subject: Re: 225 times slower