Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 5E0FF1336B42 for ; Wed, 8 Dec 2010 16:12:36 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 89472-07 for ; Wed, 8 Dec 2010 20:12:29 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 15A08133655C for ; Wed, 8 Dec 2010 16:12:28 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id oB8KCQIw020171; Wed, 8 Dec 2010 15:12:26 -0500 (EST) To: Shrirang Chitnis cc: Bryce Nesbitt , "pgsql-performance@postgresql.org" Subject: Re: hashed subplan 5000x slower than two sequential operations In-reply-to: References: <4CFFD446.6040609@obviously.com> Comments: In-reply-to Shrirang Chitnis message dated "Wed, 08 Dec 2010 14:05:48 -0500" Date: Wed, 08 Dec 2010 15:12:26 -0500 Message-ID: <20170.1291839146@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201012/111 X-Sequence-Number: 41563 Shrirang Chitnis writes: > Bryce, > The two queries are different: I suspect the second one is a typo and not what he really wanted. > WHERE (contexts.parent_key = 392210 > OR contexts.context_key IN > (SELECT collection_data.context_key > FROM collection_data > WHERE collection_data.collection_context_key = 392210) The only really effective way the planner knows to optimize an "IN (sub-SELECT)" is to turn it into a semi-join, which is not possible here because of the unrelated OR clause. You might consider replacing this with a UNION of two scans of "contexts". (And yes, I know it'd be nicer if the planner did that for you.) regards, tom lane