Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id B8E641337BDF for ; Tue, 29 Mar 2011 22:11:31 -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 05816-01 for ; Wed, 30 Mar 2011 01:11:23 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail-gx0-f174.google.com (mail-gx0-f174.google.com [209.85.161.174]) by mail.postgresql.org (Postfix) with ESMTP id F30021337B93 for ; Tue, 29 Mar 2011 22:11:20 -0300 (ADT) Received: by gxk21 with SMTP id 21so326583gxk.19 for ; Tue, 29 Mar 2011 18:11:20 -0700 (PDT) Received: by 10.91.195.29 with SMTP id x29mr812225agp.97.1301441489294; Tue, 29 Mar 2011 16:31:29 -0700 (PDT) Received: from Craig-Jamess-MacBook-Pro.local (cpe-24-30-147-136.san.res.rr.com [24.30.147.136]) by mx.google.com with ESMTPS id r8sm2869581ane.19.2011.03.29.16.31.27 (version=SSLv3 cipher=OTHER); Tue, 29 Mar 2011 16:31:28 -0700 (PDT) Message-ID: <4D926BCE.8000001@emolecules.com> Date: Tue, 29 Mar 2011 16:31:26 -0700 From: Craig James User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: multiple table scan performance References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 201103/367 X-Sequence-Number: 43046 On 3/29/11 3:16 PM, Samuel Gendler wrote: > I've got some functionality that necessarily must scan a relatively large table. Even worse, the total workload is actually 3 similar, but different queries, each of which requires a table scan. They all have a resultset that has the same structure, and all get inserted into a temp table. Is there any performance benefit to revamping the workload such that it issues a single: > > insert into (...) select ... UNION select ... UNION select > > as opposed to 3 separate "insert into () select ..." statements. > > I could figure it out empirically, but the queries are really slow on my dev laptop and I don't have access to the staging system at the moment. Also, it requires revamping a fair bit of code, so I figured it never hurts to ask. I don't have a sense of whether postgres is able to parallelize multiple subqueries via a single scan You don't indicate how complex your queries are. If it's just a single table and the conditions are relatively simple, could you do something like this? insert into (...) select ... where (...) OR (...) OR (...) Craig