Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A490B4753A1 for ; Mon, 18 Nov 2002 22:43:55 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 9C0B847601E for ; Mon, 18 Nov 2002 22:43:53 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.5/8.12.5) with ESMTP id gAJ3hqhR017249; Mon, 18 Nov 2002 22:43:52 -0500 (EST) To: "Marc Mitchell" Cc: pgsql-admin@postgresql.org Subject: Re: IN subselects and index / seq_scan question.... In-reply-to: <013901c28f62$a7379580$7c01050a@marcmdelltop> References: <20021112221500.D17277@mail.libertyrms.com> <200211130317.gAD3HPq21380@candle.pha.pa.us> <20021113075638.E5763@mail.libertyrms.com> <20021118143411.W30738@mail.libertyrms.com> <013901c28f62$a7379580$7c01050a@marcmdelltop> Comments: In-reply-to "Marc Mitchell" message dated "Mon, 18 Nov 2002 18:28:58 -0600" Date: Mon, 18 Nov 2002 22:43:52 -0500 Message-ID: <17248.1037677432@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/175 X-Sequence-Number: 6363 "Marc Mitchell" writes: > I am having an optimization problem with queries that include IN clauses > and subselects. The optimizer currently has no clue at all about dealing with "IN (subselect)", and always converts it into the worst sort of nested-loop plan. I'm hoping to do something about that for 7.4, but it's only pie-in-the-sky today. In the meantime, the conventional wisdom is to convert your query into an EXISTS() test instead of an IN() test. This is still nested-loop, but not as bad --- the clause you push down into the EXISTS() has a shot at using an index. I believe the details are in the FAQ. regards, tom lane