pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Dave Cramer <pg@fastcrypt.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Guillaume Smet <guillaume.smet@gmail.com>
Cc: Guillaume Cottenceau <gc@mnc.ch>
Cc: Mario Splivalo <mario.splivalo@megafon.hr>
Cc: pgsql-performance@postgresql.org
Cc: pgsql-jdbc@postgresql.org
Cc: scott@richrelevance.com
Subject: Re: [PERFORM] Query much slower when run from postgres 	function
Date: Tue, 10 Mar 2009 10:31:42 +1300
Message-ID: <49B58ABE.7070105@opencloud.com> (raw)
In-Reply-To: <491f66a50903091256n7fe4a3f6i93267d0d53b983cb@mail.gmail.com>
References: <49B51B60.6030600@megafon.hr>
	<27649.1236616294@sss.pgh.pa.us>
	<87fxhmmygj.fsf@meuh.mnc.lan>
	<1d4e0c10903091004m758d7ea2s91e33631be81215a@mail.gmail.com>
	<5165.1236618994@sss.pgh.pa.us>
	<491f66a50903091256n7fe4a3f6i93267d0d53b983cb@mail.gmail.com>

Dave Cramer wrote:
> 
> 
> On Mon, Mar 9, 2009 at 1:16 PM, Tom Lane <tgl@sss.pgh.pa.us
> <mailto:tgl@sss.pgh.pa.us>> wrote:
> 
>     Guillaume Smet <guillaume.smet@gmail.com
>     <mailto:guillaume.smet@gmail.com>> writes:
>     > Unnamed prepared statements are planned after binding the values,
>     > starting with 8.3, or more precisely starting with 8.3.2 as early 8.3
>     > versions were partially broken on this behalf.
> 
>     No, 8.2 did it too (otherwise we wouldn't have considered 8.3.0 to be
>     broken...).  The thing I'm not too clear about is what "use of an
>     unnamed statement" translates to for a JDBC user.
> 
> 
> Tom,
> 
> The driver will use unnamed statements for all statements until it sees
> the same statement N times where N is 5 I believe, after that it uses a
> named statement.

Right, with the caveat that "the same statement" means "exactly the same
PreparedStatement object". If you happen to run the same (textual) query
via two different PreparedStatement objects, they're still considered
different queries for the purposes of this threshold.

You can also tune the threshold via the prepareThreshold parameter in
the driver URL, or use org.postgresql.PGStatement.setPrepareThreshold
(an extension interface implemented by the driver on its Statement
objects) on a per-statement basis.

prepareThreshold=0 is a special value that means "never use a named
statement".

The idea behind the threshold is that if a PreparedStatement object is
reused, that's a fairly good indication that the application wants to
run the same query many times with different parameters (since it's
going to the trouble of preserving the statement object for reuse). But
it's all tunable if needed.

Also see http://jdbc.postgresql.org/documentation/head/server-prepare.html

-O



view thread (26+ messages)  latest in thread

Message-ID: <49B58ABE.7070105@opencloud.com>
Permalink:  ../49B58ABE.7070105@opencloud.com/
Also on:    postgresql.org/message-id/49B58ABE.7070105@opencloud.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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: oliver@opencloud.com, pg@fastcrypt.com, tgl@sss.pgh.pa.us, guillaume.smet@gmail.com, gc@mnc.ch, mario.splivalo@megafon.hr, pgsql-jdbc@postgresql.org, scott@richrelevance.com
  Subject: Re: [PERFORM] Query much slower when run from postgres 	function
  In-Reply-To: <49B58ABE.7070105@opencloud.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