Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id CBD91B5DC47 for ; Wed, 31 Aug 2011 11:19:44 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 90696-02 for ; Wed, 31 Aug 2011 14:19:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from elizabeth.gransy.com (elizabeth.gransy.com [89.187.132.199]) by mail.postgresql.org (Postfix) with ESMTP id F1419B5DC40 for ; Wed, 31 Aug 2011 11:19:37 -0300 (ADT) Received: from sq.gransy.com (localhost [127.0.0.1]) by elizabeth.gransy.com (Postfix) with ESMTP id CBD4B15E411C; Wed, 31 Aug 2011 16:19:36 +0200 (CEST) Received: from 85.162.50.94 (SquirrelMail authenticated user tv@fuzzy.cz) by sq.gransy.com with HTTP; Wed, 31 Aug 2011 16:19:36 +0200 Message-ID: In-Reply-To: <4E5E3E5F.4000807@squeakycode.net> References: <4E5D485F.8060300@squeakycode.net> <4E5D8F68.4010102@ringerc.id.au> <4E5E3E5F.4000807@squeakycode.net> Date: Wed, 31 Aug 2011 16:19:36 +0200 Subject: Re: IN or EXISTS From: "Tomas Vondra" To: "Andy Colson" Cc: "Craig Ringer" , "pgsql-performance@postgresql.org" User-Agent: SquirrelMail/1.4.21 MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.5 tagged_above=-10 required=5 tests=BAYES_05=-0.5 X-Spam-Level: X-Archive-Number: 201108/321 X-Sequence-Number: 44768 On 31 Srpen 2011, 15:59, Andy Colson wrote: > I assume: > Buckets: 16384 Batches: 1 Memory Usage: 4531kB > > That means a total of 4.5 meg of ram was used for the hash, so if my > work_mem was lower than that it would swap? (or choose a different plan?) Why don't you try that? Just set the work_mem to 1MB or so and run the query. I think it'll use the same plan but multiple batches - read just part of the inner table so that the hash table fits into work_mem, scan the outer table etc. The downside is it'd rescan the outer table several times. Tomas