Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id E00D89FBD3D for ; Tue, 17 Jul 2007 18:27:13 -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 79182-04 for ; Tue, 17 Jul 2007 18:26:59 -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 BA53B9FBB1C for ; Tue, 17 Jul 2007 18:27:08 -0300 (ADT) Received: from mail-mx4.uio.no ([129.240.10.45]) by pat.uio.no with esmtp (Exim 4.67) (envelope-from ) id 1IAuZX-0007QU-J6 for pgsql-performance@postgresql.org; Tue, 17 Jul 2007 23:27:07 +0200 Received: from smtp.uio.no ([129.240.10.9] helo=mail-mx4.uio.no) by mail-mx4.uio.no with esmtp (Exim 4.67) (envelope-from ) id 1IAuZX-0006ry-5q for pgsql-performance@postgresql.org; Tue, 17 Jul 2007 23:27:07 +0200 Received: from 113.80-203-240.nextgentel.com ([80.203.240.113] helo=[10.0.0.128]) by mail-mx4.uio.no with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.67) (envelope-from ) id 1IAuZX-0006rr-0t for pgsql-performance@postgresql.org; Tue, 17 Jul 2007 23:27:07 +0200 Message-ID: <469D342B.7080103@ifi.uio.no> Date: Tue, 17 Jul 2007 23:27:07 +0200 From: Thomas Finneid User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: insert vs select into performance References: <469D1AD3.9030004@ifi.uio.no> In-Reply-To: Content-Type: text/plain; charset=utf-8; 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: 1286CA76E0CCBED8984ED3822462F32BB5BC8616 X-UiO-SPAM-Test: remote_host: 129.240.10.9 spam_score: 0 maxlevel 200 minaction 2 bait 0 mail/h: 182 total 2877181 max/h 8345 blacklist 0 greylist 0 ratelimit 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/202 X-Sequence-Number: 25886 PFC 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) > > Did you use prepared statements ? > Did you use INSERT INTO ... VALUES () with a long list of values, or > just 100K insert statements ? It was prepared statements and I tried it both batched and non-batched (not much difference on a local machine) > It's the time to parse statements, plan, execute, roundtrips with > the client, context switches, time for your client library to escape the > data and encode it and for postgres to decode it, etc. In a word : > OVERHEAD. I know there is some overhead, but that much when running it batched...? > By the way which language and client library are you using ? > > FYI 14s / 100k = 140 microseconds per individual SQL query. That > ain't slow at all. Unfortunately its not fast enough, it needs to be done in no more than 1-2 seconds, ( and in production it will be maybe 20-50 columns of data, perhaps divided over 5-10 tables.) Additionally it needs to scale to perhaps three times as many columns and perhaps 2 - 3 times as many rows in some situation within 1 seconds. Further on it needs to allow for about 20 - 50 clients reading much of that data before the next batch of data arrives. I know the computer is going to be a much faster one than the one I am testing with, but I need to make sure the solution scales well. regars thomas