Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 7082CB5DBF7 for ; Wed, 18 May 2011 14:51:30 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 86479-01 for ; Wed, 18 May 2011 17:51:23 +0000 (UTC) X-Greylist: delayed 00:10:05.700913 by SQLgrey-1.7.6 Received: from EXHUB018-2.exch018.msoutlookonline.net (exhub018-2.exch018.msoutlookonline.net [64.78.17.17]) by mail.postgresql.org (Postfix) with ESMTP id 54EBBB5DC0B for ; Wed, 18 May 2011 14:51:23 -0300 (ADT) Received: from EXVMBX018-1.exch018.msoutlookonline.net ([64.78.17.47]) by EXHUB018-2.exch018.msoutlookonline.net ([64.78.17.17]) with mapi; Wed, 18 May 2011 10:41:16 -0700 From: Scott Carey To: Clemens Eisserer , "pgsql-performance@postgresql.org" Date: Wed, 18 May 2011 10:41:40 -0700 Subject: Re: hash semi join caused by "IN (select ...)" Thread-Topic: [PERFORM] hash semi join caused by "IN (select ...)" Thread-Index: AcwVgsnTa/v93gNFTc2dSC+0ss2/pQ== Message-ID: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Microsoft-MacOutlook/14.10.0.110310 acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201105/271 X-Sequence-Number: 43780 On 5/17/11 12:38 AM, "Clemens Eisserer" wrote: >Hi, > >>> select .... from t1 left join t2 .... WHERE id IN (select ....) >> >> Does it work as expected with one less join? If so, try increasing >> join_collapse_limit ... > >That did the trick - thanks a lot. I only had to increase >join_collapse_limit a bit and now get an almost perfect plan. >Instead of hash-joining all the data, the planner generates >nested-loop-joins with index only on the few rows I fetch. > >Using =3D ANY(array(select... )) also seems to work, I wonder which one >works better. Does ANY(ARRAY(...)) force the optimizer to plan the >subquery seperated from the main query? I'm not sure exactly what happens with ANY(ARRAY()). I am fairly confident that the planner simply transforms an IN(select ...) to a join, since they are equivalent. Because "foo IN (select ...)" is just a join, it counts towards join_collapse_limit. > >Thanks, Clemens > >--=20 >Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) >To make changes to your subscription: >http://www.postgresql.org/mailpref/pgsql-performance