From: Oliver Jowett <oliver@opencloud.com>
To: Csaba Nagy <nagy@ecircle-ag.com>
Cc: Dave Cramer <pg@fastcrypt.com>
Cc: Postgres JDBC <pgsql-jdbc@postgresql.org>
Subject: Re: Prepared statements, parameters and logging
Date: Tue, 26 Jun 2007 21:10:58 +1200
Message-ID: <4680D822.20205@opencloud.com> (raw)
In-Reply-To: <1182846145.13328.95.camel@coppola.muc.ecircle.de>
References: <1182768449.13328.60.camel@coppola.muc.ecircle.de>
<6A182763-97EC-43C9-BD13-EE5375A83AC2@fastcrypt.com>
<1182770018.13328.63.camel@coppola.muc.ecircle.de>
<C8485EE8-2EA6-4C87-91CB-E5370A3BDC53@fastcrypt.com>
<1182775348.13328.69.camel@coppola.muc.ecircle.de>
<9537AA08-53BB-434E-9E62-F326AADED792@fastcrypt.com>
<1182778475.13328.79.camel@coppola.muc.ecircle.de>
<46803664.3060701@opencloud.com>
<1182846145.13328.95.camel@coppola.muc.ecircle.de>
Csaba Nagy wrote:
> My real question is: am I turning the right knob with
> "prepareThreshold=0" ? I want all queries to be planned taking into
> account the parameter values by default. I can turn this off on special
> cases by setting the prepare threashold on the statement level - if the
> prepareThreshold is affecting at all the fact that parameters are sent
> for planning or not... is it ?
Short answer: yes, prepareThreshold=0 is the right knob. (with one
exception, see below)
Long answer:
The parameters are always sent out-of-line from the query when using
protocol version 3.
When the driver decides to use a "server prepared statement" (i.e. when
prepareThreshold > 0 and you've reused the same PreparedStatement
enough) it parses the query into a named statement at the protocol
level. Otherwise, it parses it into the unnamed statement.
When a named statement is parsed, the server also generates a generic
plan immediately.
When an unnamed statement is parsed, the parse phase is done but query
planning is not done. Later, when actual parameter values are bound,
planning is done using those actual parameter values for selectivity
purposes.
So the issue is not so much "how are the parameters sent?" but "is a
named statement being used or not?"
If you set prepareThreshold=0 then an unnamed statement should always be
used (& therefore actual parameter values should be taken into account
when planning), with one exception: the setFetchSize() case I described
in my earlier email. In that case the driver simply can't use the
unnamed statement because it needs the statement and portal to survive
for longer than using the unnamed statement would allow. Ideally the
protocol would let clients specify when to defer planning on a
per-statement basis, but the current situation is a result of wanting to
avoid exactly that sort of protocol change.. it's a bit of a compromise.
If you set logLevel=2 on the driver, you should be able to see the
differences in the protocol flow in more detail than the server logging
lets you see.
-O
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: oliver@opencloud.com, nagy@ecircle-ag.com, pg@fastcrypt.com
Subject: Re: Prepared statements, parameters and logging
In-Reply-To: <4680D822.20205@opencloud.com>
References: <1182768449.13328.60.camel@coppola.muc.ecircle.de> <6A182763-97EC-43C9-BD13-EE5375A83AC2@fastcrypt.com> <1182770018.13328.63.camel@coppola.muc.ecircle.de> <C8485EE8-2EA6-4C87-91CB-E5370A3BDC53@fastcrypt.com> <1182775348.13328.69.camel@coppola.muc.ecircle.de> <9537AA08-53BB-434E-9E62-F326AADED792@fastcrypt.com> <1182778475.13328.79.camel@coppola.muc.ecircle.de> <46803664.3060701@opencloud.com> <1182846145.13328.95.camel@coppola.muc.ecircle.de> <4680D822.20205@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