Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 71E99633E5A for ; Sat, 18 Jul 2009 10:51:46 -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 12391-04 for ; Sat, 18 Jul 2009 10:51:35 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from fmmailgate09.web.de (fmmailgate09.web.de [217.72.192.184]) by mail.postgresql.org (Postfix) with ESMTP id AFEFB633D1A for ; Sat, 18 Jul 2009 10:51:35 -0300 (ADT) Received: from web.de by fmmailgate09.web.de (Postfix) with SMTP id E41E32B1857C for ; Sat, 18 Jul 2009 15:51:32 +0200 (CEST) Received: from [84.132.48.118] by freemailng1604.web.de with HTTP; Sat, 18 Jul 2009 15:51:31 +0200 Date: Sat, 18 Jul 2009 15:51:31 +0200 Message-Id: <828427796@web.de> MIME-Version: 1.0 From: "J. W. Ulbts" To: pgsql-jdbc@postgresql.org Subject: =?iso-8859-15?Q?Speed_improvement_-_Group_batch_Insert_-_Rewrite_the_I?= =?iso-8859-15?Q?NSERT_at_the_driver_level_(using_a_parameter)?= Precedence: fm-user Organization: http://freemail.web.de/ X-Provags-Id: V01U2FsdGVkX186HXmCMEZUZhd5hgkIGLUTMmzRXeCcmbOUH+8fdBMfwmjI7 EyDZCvrwEFNKPmA6Srbo5LyvxHisKH4UqTUY4OorDulKtTcPJA= Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.819 tagged_above=0 required=5 tests=MIME_QP_LONG_LINE=1.819 X-Spam-Level: * X-Archive-Number: 200907/44 X-Sequence-Number: 19812 Hello! It would be great if someone would add a parameter and code to the driver = which would allow the JDBC driver to group a list of INSERT INTO added to = a batch (Prepared Statement and the addBatch(..) method). This way the INSERT INTO from the batch could be rewritten in a single INS= ERT INTO which is at least 3 times faster compared to the current behaviou= r. At least that was the result of my tests. To make clear what I mean a simple example. 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 execu= te this: -------------------- INSERT INTO sometable (col1, col2) VALUES (1, 'word1'), (2, 'word2'), (3, = 'word3'), (4, 'word4'); -------------------- If this is already possible with the PostgreSQL JDBC driver I must have mi= ssed it. I ran into this by one of my users pointing me to the multi value/grouped = insert statement, and then I finally saw that Mark Matthews has just impro= ved the MySQL JDBC driver in this area. He's talking about 10x performance= increase but that's basically because the MySQL server isn't optimizing a= s good as PostgreSQL. ;) I could "only" see an improvement by factor 5 with my test data and MySQL = InnoDB (IMDb - Keywords.list; reading data from file creating INSERT INTO = all in one transaction). It's possible that MyISAM are up to 10x faster. In my tests where I added the values for the INSERT INTO statement into tw= o Lists (ArrayList; one for the key column and one for the data column) an= d generated the "INSERT INTO sometable (col1, col2) VALUES (x,y)[, (x,y)];= " in my Java code it was 3 times faster compared to the normal PreparedSta= tement addBatch with it's batchExecute for PostgreSQL. I could get the same speed improvement with my manually generated INSERT I= NTO as with the new JDBC driver for MySQL where I turned on the "rewriteBa= tchedStatements" parameter. I tried column groups (the "(x,y)") with sizes between 250 and 5000 (in st= eps of 250: so 250, 500, 750,...,5000). The speed was pretty stable at 3x = for PostgreSQL but the larger the group the more memory is used to store t= he data you are trying to insert. Here is the blog entry of Mark Matthews (MySQL Connector/J developer) abou= t speeding up Batch Inserts: http://www.jroller.com/mmatthews/entry/speeding=5Fup=5Fbatch=5Finserts=5Ffor The upcoming MySQL driver supporting this feature (Connector/J 5.1 GA and = 6.0 Alpha) can be downloaded here: http://downloads.mysql.com/snapshots.php Currently the MySQL driver has an error if your prepared INSERT INTO state= ment ends with a ";" (which is not needed except in a SQL script but sever= al developers like myself normally also add this to the SQL Command in the= Java code). The driver would create an INSERT INTO statment that looks like this: INSERT INTO sometable1 (col1, col2) VALUES (1, 'word');, (2, 'word2'), ...= It would be great if someone could implement this into the JDBC driver and= the grouping could be turned on by a URL driver parameter like e.g MySQL = Connector/J (=3FrewriteBatchedStatements=3Dtrue). Maybe there are also comment about this. So what do you think=3F -- Juergen =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F GRATIS f=FCr alle WEB.DE-Nutzer: Die maxdome Movie-FLAT! Jetzt freischalten unter http://movieflat.web.de