Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 28FA7133798E for ; Tue, 18 Jan 2011 18:20:45 -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 53269-08 for ; Tue, 18 Jan 2011 22:20:38 +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 74E10133655C for ; Tue, 18 Jan 2011 18:20:37 -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 1PfJui-0007El-Qx; Wed, 19 Jan 2011 11:20:33 +1300 Message-ID: <4D36122D.9030308@opencloud.com> Date: Wed, 19 Jan 2011 11:20:29 +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: <728504.34967.qm@web33202.mail.mud.yahoo.com> In-Reply-To: <728504.34967.qm@web33202.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.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201101/55 X-Sequence-Number: 21387 Quartz wrote: > Is is expected that your said 'sync' at every statement would be less performant than a transaction, but it is still more performant than separated statements/connections, especially with prepared statements. I don't know without implementing and benchmarking it (which, unfortunately, I have no time to do). > IMHO, you should avoid breaking the spec even if it means some performance loss, which "might"* be recovered another time. The main issue here is to impose a transaction that MAY fail when the calling code isn't designed to handle retries because it didn't need to in the first place. We certainly do avoid breaking the spec whereever possible, but please remember that much of the driver's implementation dates back to the days of JDBC2, and back then the JDBC spec was a terrible spec in terms of precisely describing the required behaviour. (It's somewhat better now, but still leaves a lot to be desired) Your particular case is a bit of an edge case too - I don't remember hearing of anyone else using batch updates with autocommit=on, from memory. Typically you are using batch updates because you have a lot of data to stream in, and if you have a lot of data to stream in you want it in one big transaction to avoid repeated transaction costs - so having autocommit=on somewhat defeats the purpose.. > *For attempting to preserve performance, I guess the sync is too aggressive, so there should be an agreement to make a lighter new protocol directive to denote the intent of performing the statement alone rather than in a transaction, although the server can buffer these statement. Some kind of 'enqueue' directive, sort of. I think it's quite unlikely that the FE/BE protocol is going to change merely because of a quirk in the JDBC spec that can be handled by the driver. That protocol has been stable for a number of years now - dating back to 7.4, IIRC. You might want to read up on the query protocol at http://www.postgresql.org/docs/9.0/static/protocol-flow.html as a starting point. (The JDBC driver uses the "extended query" flow) The simplest fix I can see is to just have a special case at the Statement level that falls back to executing each batch entry individually when autocommit=on. That would match the spec better and be no worse than having the caller execute statements individually. Wiring different logic into the query executor itself to handle this case would be more complicated, and would only be a win if the server roundtrip latency was a bigger factor than the cost of transaction setup/teardown (which pretty much means "server on the other end of a WAN") Oliver