Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 0BE05B5DBD4 for ; Tue, 17 May 2011 04:39:03 -0300 (ADT) 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 74680-06 for ; Tue, 17 May 2011 07:38:56 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-iy0-f174.google.com (mail-iy0-f174.google.com [209.85.210.174]) by mail.postgresql.org (Postfix) with ESMTP id F23FEB5DBDA for ; Tue, 17 May 2011 04:38:55 -0300 (ADT) Received: by iyb14 with SMTP id 14so196370iyb.19 for ; Tue, 17 May 2011 00:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=v3XSvml/ejfvu7BcUmeOnPcKjsG4CwIvfjtPn03hvHE=; b=QVI76sMb/VKPSm0qcvE09zk+QTVlvutNjab0xsPA6RNhTkvIHh8jvu7RuDzsX65qc2 FwSPnliHeC6QnOFSizXwtYU+esiCVVCFL18kVeXvjrH8MN2PtXml8rJdSyQ1cGp+J/nt +6MBTYnfDEztVV4hDDj9IL+/EKDcAvAQUMqHs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=h+zb4Lm2drCWnQu6rYUpKOJbUNmADHnV7y5eEijSij0Pq0c3vOFjsTrs50R0NZrGiL LLRTCYg+QtmjeD0I4WeiyMHSn7X6BXmIq7ge/2x6yp5BOtKASZpXi6J7hFPLZkZB6/pf w2V6lg1/SkwC39f358ldoiIlMKrXmBkij8Z5M= MIME-Version: 1.0 Received: by 10.231.144.200 with SMTP id a8mr208073ibv.85.1305617935457; Tue, 17 May 2011 00:38:55 -0700 (PDT) Received: by 10.231.30.72 with HTTP; Tue, 17 May 2011 00:38:55 -0700 (PDT) In-Reply-To: <23922.1305588168@sss.pgh.pa.us> References: <23922.1305588168@sss.pgh.pa.us> Date: Tue, 17 May 2011 09:38:55 +0200 Message-ID: Subject: Re: hash semi join caused by "IN (select ...)" From: Clemens Eisserer To: pgsql-performance@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.888 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201105/255 X-Sequence-Number: 43764 Hi, >> select .... from t1 left join t2 .... WHERE id IN (select ....) > > Does it work as expected with one less join? =C2=A0If 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? Thanks, Clemens