From: Bernd Helmle <mailings@oopsware.de>
To: pgsql-jdbc@postgresql.org
Subject: prepareTreshold=0 vs. transaction control commands
Date: Thu, 05 Apr 2012 10:54:38 +0200
Message-ID: <A3F31011DB93D443CAA72041@apophis.local> (raw)
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
Attachments:jdbc_test.java (text/plain, 1.0K) download
import java.util.*;
import java.sql.*;
public class jdbc_test {
protected static final String host = "localhost";
protected static final String db = "bernd";
protected static final String user = "bernd";
protected static final String port = "5447";
protected static Connection con = null;
public static void main(String args[]) {
try {
// setting up JDBC connection
PreparedStatement pstmt;
Class.forName("org.postgresql.Driver");
con = DriverManager.getConnection("jdbc:postgresql://"
+ host + ":" + port
+ "/"
+ db
+ "?"
+ "user="
+ user
+ "&loglevel=2&prepareThreshold=0");
con.setAutoCommit(false);
pstmt = con.prepareStatement("SELECT ?::int");
pstmt.setInt(1, 100);
pstmt.execute();
con.commit();
} catch(Exception e) {
e.printStackTrace();
}
}
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: mailings@oopsware.de
Subject: Re: prepareTreshold=0 vs. transaction control commands
In-Reply-To: <A3F31011DB93D443CAA72041@apophis.local>
References: <A3F31011DB93D443CAA72041@apophis.local>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox