Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id D68D9B5D944 for ; Wed, 18 May 2011 05:46:07 -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 82176-06 for ; Wed, 18 May 2011 08:46:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-iw0-f174.google.com (mail-iw0-f174.google.com [209.85.214.174]) by mail.postgresql.org (Postfix) with ESMTP id EEE37B5D802 for ; Wed, 18 May 2011 05:46:00 -0300 (ADT) Received: by iwn34 with SMTP id 34so1119113iwn.19 for ; Wed, 18 May 2011 01:46:00 -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=vZ1hqc1Qe+cxbrGVJa9/BnnhUfN6noqrh31vj60cfl4=; b=UhnMrWZ+j1h2SOIRQNOP6r7YxKhzZ7KtP2sL2utkbMmCmtWjgRCHa46/skJz4A3yU/ w4LHVs9t3FYZfDLziAusnum5JY8lYcxFJXexQK751Ie4OWNLNGoIyuu7QkzX5HJsKHqe I5M2YDh8r77RKNkveRRdbAIofgyip0BFGdkIs= 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=Mm2C2sF6S1tZih5h2SLbBn6wj2uwTFbB9oM9IPuaw/zQR5L2CS5ja/pepSH4TErX2d qsGDzZSrL2VAaAiEdFajr/+2skt/2ya9q7MzoG1c2z7I6yPvNiqDRGvwgcgeGPCGUSfx fAWqHxDpCKIfSK2Yv3eYXQ09DQBgaXQ7cRNKo= MIME-Version: 1.0 Received: by 10.231.144.200 with SMTP id a8mr1274797ibv.85.1305708360322; Wed, 18 May 2011 01:46:00 -0700 (PDT) Received: by 10.231.30.72 with HTTP; Wed, 18 May 2011 01:46:00 -0700 (PDT) In-Reply-To: References: <23922.1305588168@sss.pgh.pa.us> Date: Wed, 18 May 2011 10:46:00 +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/266 X-Sequence-Number: 43775 Hi, Does anybody know why the planner treats "=3D ANY(ARRAY(select ...))" differently than "IN(select ...)"? Which one is preferable, when I already have a lot of joins? Thanks, Clemens 2011/5/17 Clemens Eisserer : > 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 >