Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 05B819FBCA0 for ; Tue, 17 Jul 2007 16:39:08 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 68726-04 for ; Tue, 17 Jul 2007 16:38:53 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from pat.uio.no (pat.uio.no [129.240.10.15]) by postgresql.org (Postfix) with ESMTP id 283B49FBD06 for ; Tue, 17 Jul 2007 16:39:01 -0300 (ADT) Received: from mail-mx9.uio.no ([129.240.10.39]) by pat.uio.no with esmtp (Exim 4.67) (envelope-from ) id 1IAssu-0008Av-NB for pgsql-performance@postgresql.org; Tue, 17 Jul 2007 21:39:00 +0200 Received: from smtp.uio.no ([129.240.10.9] helo=mail-mx9.uio.no) by mail-mx9.uio.no with esmtp (Exim 4.67) (envelope-from ) id 1IAssu-0001wh-AY for pgsql-performance@postgresql.org; Tue, 17 Jul 2007 21:39:00 +0200 Received: from 113.80-203-240.nextgentel.com ([80.203.240.113] helo=[10.0.0.128]) by mail-mx9.uio.no with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.67) (envelope-from ) id 1IAssu-0001wW-4d for pgsql-performance@postgresql.org; Tue, 17 Jul 2007 21:39:00 +0200 Message-ID: <469D1AD3.9030004@ifi.uio.no> Date: Tue, 17 Jul 2007 21:38:59 +0200 From: Thomas Finneid User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: insert vs select into performance Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-UiO-SPF-Received: X-UiO-Resend: resent X-UiO-SPF-Received: X-UiO-Spam-info: not spam, SpamAssassin (score=0.0, required=12.0, autolearn=disabled, none) X-UiO-Scanned: 259FF3E4D981085B1327A1A6E9212AB64AF51371 X-UiO-SPAM-Test: remote_host: 129.240.10.9 spam_score: 0 maxlevel 200 minaction 2 bait 0 mail/h: 252 total 2876361 max/h 8345 blacklist 0 greylist 0 ratelimit 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/190 X-Sequence-Number: 25874 Hi 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? Does the select into translate into a specially optimised function in c that can cut corners which a insert can not do (e.g. lazy copying), or is it some other reason? The reason I am asking is that select into shows that a number of rows can be inserted into a table quite a lot faster than one would think was possible with ordinary sql. If that is the case, it means that if I write an pl-pgsql insert function in C instead of sql, then I can have my db perform order of magnitude faster. Any comments? regards thomas