Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 99BDE9FB9BF for ; Tue, 17 Jul 2007 16:55:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 64396-02 for ; Tue, 17 Jul 2007 16:55:03 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mtao03.charter.net (mtao03.charter.net [209.225.8.188]) by postgresql.org (Postfix) with ESMTP id 9609A9FB823 for ; Tue, 17 Jul 2007 16:55:05 -0300 (ADT) Received: from aa03.charter.net ([10.20.200.155]) by mtao03.charter.net (InterMail vM.7.08.02.00 201-2186-121-20061213) with ESMTP id <20070717195504.DNMO1450.mtao03.charter.net@aa03.charter.net>; Tue, 17 Jul 2007 15:55:04 -0400 Received: from [10.0.1.2] (really [66.188.164.45]) by aa03.charter.net with ESMTP id <20070717195504.CPDF7864.aa03.charter.net@[10.0.1.2]>; Tue, 17 Jul 2007 15:55:04 -0400 In-Reply-To: <469D1AD3.9030004@ifi.uio.no> References: <469D1AD3.9030004@ifi.uio.no> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <0D6011B2-D09F-45E8-A5D7-5F84ADD1DC2B@seespotcode.net> Cc: pgsql-performance@postgresql.org Content-Transfer-Encoding: 7bit From: Michael Glaesemann Subject: Re: insert vs select into performance Date: Tue, 17 Jul 2007 14:54:55 -0500 To: Thomas Finneid X-Mailer: Apple Mail (2.752.2) X-Chzlrs: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/191 X-Sequence-Number: 25875 On Jul 17, 2007, at 14:38 , Thomas Finneid wrote: > I was doing some testing on "insert" compared to "select into". I > inserted 100 000 rows (with 8 column values) into a table, which > took 14 seconds, compared to a select into, which took 0.8 seconds. > (fyi, the inserts where batched, autocommit was turned off and it > all happend on the local machine) > > Now I am wondering why the select into is that much faster? It would be helpful if you included the actual queries you're using, as there are a number of variables: 1) If there are any constraints on the original table, the INSERT will be checking those constraints. AIUI, SELECT INTO does not generate any table constraints. 2a) Are you using INSERT INTO foo (foo1, foo2, foo2) SELECT foo1, foo2, foo3 FROM pre_foo or individual inserts for each row? The former would be faster than the latter. 2b) If you are doing individual inserts, are you wrapping them in a transaction? The latter would be faster. Michael Glaesemann grzm seespotcode net