Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id F32B41BA1318 for ; Thu, 5 Apr 2012 05:55:01 -0300 (ADT) Received: from dd2030.kasserver.com ([85.13.128.37]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SFiT0-0000pV-IU for pgsql-jdbc@postgresql.org; Thu, 05 Apr 2012 08:55:00 +0000 Received: from [172.26.14.87] (fw-front.credativ.com [87.193.134.200]) by dd2030.kasserver.com (Postfix) with ESMTPSA id 94810E0037 for ; Thu, 5 Apr 2012 10:54:39 +0200 (CEST) Date: Thu, 05 Apr 2012 10:54:38 +0200 From: Bernd Helmle To: pgsql-jdbc@postgresql.org Subject: prepareTreshold=0 vs. transaction control commands Message-ID: X-Mailer: Mulberry/4.1.0a1 (Mac OS X) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="==========43475F4AD432D8F349C2==========" X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201204/8 X-Sequence-Number: 22808 --==========43475F4AD432D8F349C2========== Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; size=2129 During debugging database problems at a customer site with JDBC i discovered the following behavior when passing prepareThreshold=0 to the connection DSN: The SQL workflow is supposed as follows: BEGIN; SELECT 1; COMMIT; Stripped sample program attached. What i expected was the complete absence of named prepared statements, however, examining the debug output i've seen the following: 16:02:23.777 (1) FE=> Parse(stmt=S_1,query="BEGIN",oids={}) 16:02:23.777 (1) FE=> Bind(stmt=S_1,portal=null) 16:02:23.777 (1) FE=> Execute(portal=null,limit=0) 16:02:23.777 (1) FE=> Parse(stmt=null,query="SELECT $1::int",oids={23}) 16:02:23.778 (1) FE=> Bind(stmt=null,portal=null,$1=<'[B@7a982589'>) 16:02:23.778 (1) FE=> Describe(portal=null) 16:02:23.778 (1) FE=> Execute(portal=null,limit=0) 16:02:23.778 (1) FE=> Sync 16:02:23.779 (1) <=BE ParseComplete [S_1] 16:02:23.779 (1) <=BE BindComplete [null] 16:02:23.780 (1) <=BE CommandStatus(BEGIN) 16:02:23.780 (1) <=BE ParseComplete [null] 16:02:23.780 (1) <=BE BindComplete [null] 16:02:23.780 (1) <=BE RowDescription(1) 16:02:23.780 (1) Field(,INT4,4,T) 16:02:23.780 (1) <=BE DataRow(len=3) 16:02:23.781 (1) <=BE CommandStatus(SELECT 1) 16:02:23.789 (1) <=BE ReadyForQuery(T) 16:02:23.789 (1) simple execute, handler=org.postgresql.jdbc2.AbstractJdbc2Connection$TransactionCommandHandler@7c4c51, maxRows=0, fetchSize=0, flags=22 16:02:23.789 (1) FE=> Parse(stmt=S_2,query="COMMIT",oids={}) 16:02:23.790 (1) FE=> Bind(stmt=S_2,portal=null) 16:02:23.790 (1) FE=> Execute(portal=null,limit=1) 16:02:23.790 (1) FE=> Sync 16:02:23.790 (1) <=BE ParseComplete [S_2] 16:02:23.790 (1) <=BE BindComplete [null] 16:02:23.790 (1) <=BE CommandStatus(COMMIT) Please note the named statement for BEGIN and COMMIT. The reason for this seems to be that those transaction control commands aren't flagged with QUERY_ONESHOT in case someone uses prepareThreshold=0 and always gets named. I couldn't get an explanation for this from the code (AFAIU), so i wonder what the technical reason behind this behavior is...anyone able to shed a light on this? -- Thanks Bernd --==========43475F4AD432D8F349C2========== Content-Type: text/plain; charset=utf-8; name="jdbc_test.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="jdbc_test.java"; size=1033 import java.util.*; import java.sql.*; public class jdbc_test { protected static final String host =3D "localhost"; protected static final String db =3D "bernd"; protected static final String user =3D "bernd"; protected static final String port =3D "5447"; protected static Connection con =3D null; public static void main(String args[]) { =20 try { // setting up JDBC connection PreparedStatement pstmt; Class.forName("org.postgresql.Driver"); con =3D DriverManager.getConnection("jdbc:postgresql://"=20 + host + ":" + port=20 + "/"=20 + db=20 + "?" + "user=3D"=20 + user + = "&loglevel=3D2&prepareThreshold=3D0"); con.setAutoCommit(false); pstmt =3D con.prepareStatement("SELECT ?::int"); pstmt.setInt(1, 100); pstmt.execute(); con.commit(); } catch(Exception e) { e.printStackTrace(); } =20 } } --==========43475F4AD432D8F349C2==========--