X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 22251D1E747; Sat, 1 May 2004 19:09:32 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 14719-09; Sat, 1 May 2004 19:09:12 -0300 (ADT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 06878D1E7FA; Sat, 1 May 2004 19:09:09 -0300 (ADT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=opencloud.com) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1BK2fE-0000kl-00; Sun, 02 May 2004 10:08:52 +1200 Message-ID: <40941FF2.4080903@opencloud.com> Date: Sun, 02 May 2004 10:08:50 +1200 From: Oliver Jowett User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: alvherre@dcc.uchile.cl Cc: tgl@sss.pgh.pa.us, pgsql-hackers@postgresql.org, pgsql-jdbc@postgresql.org Subject: Re: Weird prepared stmt behavior Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200405/1 X-Sequence-Number: 10011 (I'm not on -hackers, but saw this in the archives) Alvaro Herrera wrote: > On Fri, Apr 30, 2004 at 09:44:52PM -0400, Tom Lane wrote: >> Alvaro Herrera writes: >> > Is this expected? If so, why? I'd expect the prepared stmt to be >> > deallocated. >> >> prepare.c probably should have provisions for rolling back its state to >> the start of a failed transaction ... but it doesn't. >> >> Before jumping into doing that, though, I'd want to have some >> discussions about the implications for the V3 protocol's notion of >> prepared statements. The protocol spec does not say anything that >> would suggest that prepared statements are lost on transaction rollback, >> and offhand it seems like they shouldn't be because the protocol is >> lower-level than transactions. > > Right now there is no distinction between a PREPARE prepared statement > and a protocol-level one. If we want to have the v3proto's statements > behave different from PREPARE's, it's just a matter of adding a new > field into the PreparedStatement. I can do that and make them behave > different if people think this is how it should be. > > I don't really have an opinion on whether protocol-level should behave > different. What do people think? At least from the JDBC driver's point of view, having prepared statements roll back is more work for the driver. Currently it uses PREPARE/EXECUTE statements, but eventually it'll use the protocol-level messages. When the JDBC driver is given a query to execute and decides to use server-side preparation, it sends a PREPARE (or eventually a Parse message). Thereafter, when that same query is executed it will send an EXECUTE (or Bind/Execute) instead of the full query. It does this by setting some state in the driver-side object representing the query to say "this query is prepared with name 'foo'". If PREPARE can roll back, the driver must maintain a set of all statements that were sucessfully PREPAREd in the current transaction, and fix up the corresponding query object state whenever a transaction rolls back. From that point of view, it's much simpler to keep PREPARE (or at least Parse) as it currently is. I suspect the same argument applies to any interface layer that uses PREPARE or Parse automatically. -O