pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John Lister <john.lister@kickstone.com>
To: Dave Cramer <pg@fastcrypt.com>
Cc: Thomas Finneid <tfinneid@fcon.no>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: pooled prepared statements
Date: Tue, 12 May 2009 18:48:01 +0100
Message-ID: <4A09B651.4010409@kickstone.com> (raw)
In-Reply-To: <491f66a50905121016r39d78f29k145e2cc53c498586@mail.gmail.com>
References: <4A0978A3.6030900@fcon.no>
	<4A099C8F.60709@kickstone.com>
	<491f66a50905121016r39d78f29k145e2cc53c498586@mail.gmail.com>



Dave Cramer wrote:
>
>
> On Tue, May 12, 2009 at 11:58 AM, John Lister 
> <john.lister@kickstone.com <mailto:john.lister@kickstone.com>> wrote:
>
>     Thomas Finneid wrote:
>
>         When a PreparedStatment is created by a pooled connection, as
>         far as I understand if, that creation happens on the server
>         side, and a reference, of sorts, is returned to the client jdbc.
>
>         Is that prepared statement shared among the connections or is
>         it only available to that single connection? and more
>         importantly, can many connections use that prepared statement
>         concurrently?
>
>         If it is shared, then it must be usable by concurrent
>         connections, otherwise it will be difficult for the client to
>         know if the statement is occupied or not. So I just want to
>         confirm that I understand how the JDBC driver works.
>
>     Once the query usage count exceeds the prepareThreshold parameter,
>     then the driver does create a "prepare statement object" on the
>     server. This is only valid for the time the PreparedStatement is
>     open and only on that connection. So to answer your question, they
>     cannot be shared by multiple connections.
>
>     You can create your own using the PREPARE and EXECUTE sql commands
>     so long as you track them across different connections...
>
>
> AFAIK, you can't do that either assuming you mean prepare on one 
> connection and execute on another ?
No, I meant, prepare on one connection, next time detect if you've 
prepared on that connection and execute it, otherwise prepare again. 
Hopefully at some point all connections in the pool would have the 
connection prepared... Not sure how heavy that would be on resources - 
and if possible with the current setup.

Also what would be nice is some form of server side caching of the 
preparation (if requested by the client) so that things like JPA can get 
the benefits of planning once across multiple prepareStatement objects.

Just a thought

JOHN



view thread (13+ messages)  latest in thread

Message-ID: <4A09B651.4010409@kickstone.com>
Permalink:  ../4A09B651.4010409@kickstone.com/
Also on:    postgresql.org/message-id/4A09B651.4010409@kickstone.com

 · 

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: john.lister@kickstone.com, pg@fastcrypt.com, tfinneid@fcon.no
  Subject: Re: pooled prepared statements
  In-Reply-To: <4A09B651.4010409@kickstone.com>
  References: <4A0978A3.6030900@fcon.no> <4A099C8F.60709@kickstone.com> <491f66a50905121016r39d78f29k145e2cc53c498586@mail.gmail.com> <4A09B651.4010409@kickstone.com>

* 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