Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 671CC63403E for ; Sat, 18 Jul 2009 11:25:39 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 16500-02 for ; Sat, 18 Jul 2009 11:25:28 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by mail.postgresql.org (Postfix) with ESMTP id D4D5F633F07 for ; Sat, 18 Jul 2009 11:25:28 -0300 (ADT) Received: from 125-237-255-118.jetstream.xtra.co.nz ([125.237.255.118] helo=[192.168.1.3]) by tremor.opencloud.co.nz with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1MSAqo-0003MH-4u; Sun, 19 Jul 2009 02:25:22 +1200 Message-ID: <4A61DB50.2030201@opencloud.com> Date: Sun, 19 Jul 2009 02:25:20 +1200 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.22 (X11/20090608) MIME-Version: 1.0 To: "J. W. Ulbts" CC: pgsql-jdbc@postgresql.org Subject: Re: Speed improvement - Group batch Insert - Rewrite the INSERT at the driver level (using a parameter) References: <828427796@web.de> In-Reply-To: <828427796@web.de> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200907/45 X-Sequence-Number: 19813 J. W. Ulbts wrote: > The normal batch would execute this: > -------------------- > INSERT INTO sometable (col1, col2) VALUES (1, 'word1'); > INSERT INTO sometable (col1, col2) VALUES (2, 'word2'); > INSERT INTO sometable (col1, col2) VALUES (3, 'word3'); > INSERT INTO sometable (col1, col2) VALUES (4, 'word4'); > -------------------- > > If the batch insert is rewritten by the driver it would generate and execute this: > -------------------- > INSERT INTO sometable (col1, col2) VALUES (1, 'word1'), (2, 'word2'), (3, 'word3'), (4, 'word4'); > -------------------- That would require teaching the driver how to parse INSERT statements, and in general the driver tries to avoid parsing SQL where ever possible. Where exactly is the performance benefit that you see coming from? I would expect the driver to already be reusing a named statement when batching a PreparedStatement (you could check the loglevel=2 output to verify this), so you only pay the parsing cost a few times until use of a named statement kicks in. Is the overhead of Bind/Execute really that high? If your use case is just "I want to do bulk inserts as fast as possible" then perhaps the newly merged COPY suport is a better way to go. -O PS: my reading of the mysql blog entry that you linked was that it was the parsing/rewriting that the MySQL driver does that caused a 10x slowdown in the first place, and the "speedup" was actually just fixing that.