Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 6FD431337BA4 for ; Tue, 26 Oct 2010 18:55:05 -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 68780-03-7 for ; Tue, 26 Oct 2010 21:54:58 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from lpo-relay-05.vmsinfo.com (lpo-relay-05.vmsinfo.com [216.169.137.116]) by mail.postgresql.org (Postfix) with ESMTP id DF6321337B97 for ; Tue, 26 Oct 2010 18:54:57 -0300 (ADT) X-IronPort-AV: E=Sophos;i="4.58,242,1286164800"; d="scan'208";a="29630364" Received: from unknown (HELO lpo-mailbox-01.vmsinfo.com) ([216.169.137.252]) by lpo-relay-05.vmsinfo.com with ESMTP; 26 Oct 2010 17:54:57 -0400 Received: from [10.101.43.35] (unknown [216.169.135.235]) by lpo-mailbox-01.vmsinfo.com (Postfix) with ESMTP id C8B417D00B for ; Tue, 26 Oct 2010 17:54:57 -0400 (EDT) Message-ID: <4CC74E31.6060307@vmsinfo.com> Date: Tue, 26 Oct 2010 17:54:57 -0400 From: Mladen Gogala User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.11) Gecko/20101013 Lightning/1.0b2 Thunderbird/3.1.5 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Postgres insert performance and storage requirement compared to Oracle References: <402913.53404.qm@web65405.mail.ac4.yahoo.com> <208728.42197.qm@web65409.mail.ac4.yahoo.com> <770715.39613.qm@web29003.mail.ird.yahoo.com> <4CC741FF.8050709@vmsinfo.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201010/445 X-Sequence-Number: 40863 On 10/26/2010 5:27 PM, Jon Nelson wrote: > start loop: > populate rows in temporary table > insert from temporary table into permanent table > truncate temporary table > loop > > I do something similar, where I COPY data to a temporary table, do > lots of manipulations, and then perform a series of INSERTS from the > temporary table into a permanent table. > 1) It's definitely not faster because you have to insert into the temporary table, in addition to inserting into the permanent table. 2) This is what I had in mind: mgogala=# create table a(c1 int); CREATE TABLE mgogala=# create temporary table t1(c1 int) on commit delete rows; CREATE TABLE mgogala=# begin; BEGIN mgogala=# insert into t1 select generate_series(1,1000); INSERT 0 1000 mgogala=# insert into a select * from t1; INSERT 0 1000 mgogala=# commit; COMMIT mgogala=# select count(*) from a; count ------- 1000 (1 row) mgogala=# select count(*) from t1; count ------- 0 (1 row) The table is created with "on commit obliterate rows" option which means that there is no need to do "truncate". The "truncate" command is a heavy artillery. Truncating a temporary table is like shooting ducks in a duck pond, with a howitzer. -- Mladen Gogala Sr. Oracle DBA 1500 Broadway New York, NY 10036 (212) 329-5251 http://www.vmsinfo.com The Leader in Integrated Media Intelligence Solutions