pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Radosław Smogura <rsmogura@softperience.eu>
To: pgsql-jdbc@postgresql.org
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Subject: Re: binary patch problems
Date: Mon, 19 Sep 2011 19:26:43 +0200
Message-ID: <201109191926.43305.rsmogura@softperience.eu> (raw)
In-Reply-To: <16752.1316443632@sss.pgh.pa.us>
References: <4E4ADB2A.5040902@gmail.com>
	<4E774962.4060904@nitorcreations.com>
	<16752.1316443632@sss.pgh.pa.us>

Tom Lane <tgl@sss.pgh.pa.us> Monday 19 of September 2011 16:47:12
> Mikko Tiihonen <mikko.tiihonen@nitorcreations.com> writes:
> > On 09/19/2011 01:11 PM, Bodor Andras wrote:
> >> Why don't you set prepareThreshold to 0 for your test cases?
> >> In this case parameter passing starts immediately for the
> >> prepared statement, and ForceBinaryTransfers can be dropped.
> > 
> > AbstractJdbc2Statement:
> >      public boolean isUseServerPrepare() {
> >      
> >          return (preparedQuery != null && m_prepareThreshold != 0 &&
> >          m_useCount + 1 >= m_prepareThreshold);
> >      
> >      }
> > 
> > If I read the above correctly then prepareThreshold of 0 disables
> > prepared statements.
> 
> But "1" would do what you want, no?
> 
> FWIW, I'm hoping that this entire business of delaying the server-side
> prepare will be obsolete as of 9.2.  There is already code committed in
> HEAD that allows "prepared" statements to be re-planned for each new set
> of parameter values, with a somewhat-informed choice of whether and when
> to switch over to the traditional generic-plan approach.  It needs
> tweaking for performance still, no doubt, but there is not going to be a
> reason for the driver to do this anymore.
> 
> Obviously that's not much use for solving your immediate problem, but it
> might lead you to conclude that putting a large amount of effort into
> improving this mechanism would be a dead end.
> 
> 			regards, tom lane

The whole logic about this was, because PreparedStatement are not used in Java 
to be prepared in means of database server. It's normal technique to write 
even one shoot statements
ps = conn.prepareStatemn(SELECT * FROM foo where id = ?)
This simple techinique makes code more simple and saftly; it prevents SQL 
injection, as well no one need to care about proper data escaping. So If 
someone uses statements once, there may be no need to parsing plan for this 
(prove why server should do this for you by invoking it 5 times).
As side effect of this popular concept many J2EE servers provides new pool, 
with ecah connection (connection are pooled), you get statement pool, so web-
based and J2EE environments (which are mainly single-request based) may with 
no effort form developer side use benefits of preparation.

The PG "one shot" statements will not make this obsolete
1) Driver will be backward compatible (it's still supports 7.x editions)
2) Above problem will be still present.
3) Java perpared statements uses ? inseted of positional parameters, so driver 
need to parse query in any way.

Regards
Radek
http://www.softperience.eu/



view thread (20+ messages)  latest in thread

Message-ID: <201109191926.43305.rsmogura@softperience.eu>
Permalink:  ../201109191926.43305.rsmogura@softperience.eu/
Also on:    postgresql.org/message-id/201109191926.43305.rsmogura@softperience.eu

 · 

reply

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: rsmogura@softperience.eu, tgl@sss.pgh.pa.us
  Subject: Re: binary patch problems
  In-Reply-To: <201109191926.43305.rsmogura@softperience.eu>
  References: <4E4ADB2A.5040902@gmail.com> <4E774962.4060904@nitorcreations.com> <16752.1316443632@sss.pgh.pa.us> <201109191926.43305.rsmogura@softperience.eu>

* 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