Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 9CC221337BA1 for ; Tue, 18 Jan 2011 17:43:17 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 43654-01-9 for ; Tue, 18 Jan 2011 21:43:10 +0000 (UTC) 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 CF6871337CC9 for ; Tue, 18 Jan 2011 17:32:12 -0400 (AST) Received: from 121-98-80-66.bitstream.orcon.net.nz ([121.98.80.66] helo=[192.168.1.2]) by tremor.opencloud.co.nz with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PfJ9l-0006b4-Hg; Wed, 19 Jan 2011 10:32:01 +1300 Message-ID: <4D3606CD.7080707@opencloud.com> Date: Wed, 19 Jan 2011 10:31:57 +1300 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Quartz CC: pgsql-jdbc@postgresql.org Subject: Re: jdbc spec violation for autocommit=true & addbatch/executeBatch References: <654041.58993.qm@web33207.mail.mud.yahoo.com> In-Reply-To: <654041.58993.qm@web33207.mail.mud.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.3 tagged_above=-10 required=5 tests=BAYES_00=-1.9, SARE_BAYES_5x7=0.6 X-Spam-Level: X-Archive-Number: 201101/53 X-Sequence-Number: 21385 Quartz wrote: > Postgres with transaction (autocommit=false & commit()) does deadlock as expected. > Postgres without transaction (autocommit=true) deadlocks UNEXPECTEDLY. > > The jdbc javadoc says clearly: > http://download.oracle.com/javase/6/docs/api/java/sql/Connection.html#setAutoCommit%28boolean%29 > > "If a connection is in auto-commit mode, then all its SQL statements will be executed and committed as individual transactions." It's worth noting that the javadoc changes without warning between releases - there have been many "clarifications" over the years that are actually unannounced behavioral changes - have you checked historical javadoc to see what it says? Maybe we implemented against a spec that said something different. That said - yes, all statements within addBatch() are run in a single transaction. (Autocommit is triggered by the final Sync message, which is only sent at the end of the batch) A related gotcha is that if you execute a multiple statement query (i.e. execute("select 1; select 2; select 3") then, again, there is only one enclosing autocommit transaction. (This was deliberate, as it mirrored the behavior of protocol-version-2 drivers back in the 7.x days) I'm not sure if we can implement this according to the current spec without losing any performance benefit of addBatch()/executeBatch() - we'd have to send a Sync after every individual query. As a workaround I suggest you just run the queries individually, not in a batch - there won't be much performance difference. (And if you really don't care about ordering or atomicity as you imply, you could parallelize it across multiple connections if latency is a problem) Oliver