X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 28E793CCD9F for ; Fri, 17 Dec 2004 18:52:14 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 11556-10 for ; Fri, 17 Dec 2004 18:52:08 +0000 (GMT) Received: from rwcrmhc11.comcast.net (rwcrmhc13.comcast.net [204.127.198.39]) by svr1.postgresql.org (Postfix) with ESMTP id D72563CC495 for ; Fri, 17 Dec 2004 18:52:07 +0000 (GMT) Received: from localhost.localdomain (c-67-167-246-79.client.comcast.net[67.167.246.79]) by comcast.net (rwcrmhc13) with ESMTP id <200412171852030150091qn5e>; Fri, 17 Dec 2004 18:52:04 +0000 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.12.11/8.12.11) with ESMTP id iBHIq2pg013436 for ; Fri, 17 Dec 2004 12:52:03 -0600 Received: (from spike@localhost) by localhost.localdomain (8.12.11/8.12.11/Submit) id iBHIq25R013435 for pgsql-performance@postgresql.org; Fri, 17 Dec 2004 12:52:02 -0600 X-Authentication-Warning: localhost.localdomain: spike set sender to mike@thegodshalls.com using -f Date: Fri, 17 Dec 2004 12:52:01 -0600 From: "Mike G." To: pgsql-performance@postgresql.org Subject: Which is more efficient? Message-ID: <20041217185201.GA13389@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-Virus-Scanned: ClamAV 0.80/615/Sat Dec 4 18:05:12 2004 clamav-milter version 0.80j on localhost X-Virus-Status: Clean X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200412/222 X-Sequence-Number: 9597 Hi, I have data that I am taking from 2 tables, pulling out specific columns and inserting into one table. Is it more efficient to do: a) insert into x select z from y; insert into x select z from a; b) insert into x select z from y union all select z from a; I have run both through explain. a) 650ms b) 741.57ms According to the planner option a, select z from y takes 545.93 ms Under option b select z from y takes 553.34 ms Shouldn't the time predicted for the select z from y be the same? I would believe b would be more efficient as the inserts could be done in a batch rather than individual transactions but the planner doesn't recognize that. When I run option a through the planner I have to highlight each insert separately since the planner stops executing after the first ; it comes across. Mike