Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 18499638909 for ; Fri, 20 Feb 2009 13:42:04 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 14272-01 for ; Fri, 20 Feb 2009 13:41:54 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from leary.csoft.net (leary.csoft.net [205.205.214.5]) by mail.postgresql.org (Postfix) with ESMTP id A3DD5638901 for ; Fri, 20 Feb 2009 13:41:54 -0400 (AST) Received: by leary.csoft.net (Postfix, from userid 1112) id 7C4B7ACA6; Fri, 20 Feb 2009 12:41:52 -0500 (EST) Date: Fri, 20 Feb 2009 12:41:52 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: ralf.baumhof@bgs-ag.de cc: pgsql-jdbc@postgresql.org Subject: Re: Performance of jdbc insert statements and select nextval In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed 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: 200902/38 X-Sequence-Number: 19313 On Fri, 20 Feb 2009, ralf.baumhof@bgs-ag.de wrote: > [insert with pgadmin is faster than JDBC] As I explained previously I believe pgadmin is sending all of your inserts in one network roundtrip rather than a single insert at a time. So for example: StringBuffer sql = new StringBuffer(); for (int i=0; i<100; i++) { sql.append("INSERT INTO mytable (a) VALUES ("); sql.append(i).append(")"); } Statement.execute(sql.toString()) will be faster than for (int i=0; i<100; i++) { String sql = "INSERT INTO mytable (a) VALUES (" + i + ")"; Statement.execute(sql); } because the second sample has to make 100 network trips instead of just one. > I made a test with "logical" insert of objects which results in 50000 > inserts can be done within 2 minutes, what means 416 inserts per second, > or 1 insert in 2/1000 sec (2ms). The cost estimate with explain for an > insert is on the other hand is 0,4 ms. Explain cost estimates do not have units of milliseconds, so the comparison is invalid. Kris Jurka