From: Kris Jurka <books@ejurka.com>
To: Josh Berkus <josh@agliodbs.com>
Cc: PostgreSQL - JDBC <pgsql-jdbc@postgresql.org>
Subject: Re: JDBC, prepared queries, and partitioning
Date: Wed, 13 Feb 2008 14:18:54 -0500 (EST)
Message-ID: <Pine.BSO.4.64.0802131404090.6785@leary.csoft.net> (raw)
In-Reply-To: <Pine.BSO.4.64.0802131348050.27322@leary.csoft.net>
References: <200802131005.30553.josh@agliodbs.com>
<Pine.BSO.4.64.0802131348050.27322@leary.csoft.net>
On Wed, 13 Feb 2008, Kris Jurka wrote:
> Using protocol version 2 will not prepare queries so constraint exclusion can
> be used. Just append protocolVersion=2 to your URL.
>
Also, to add what a real fix would look like:
Right now the JDBC driver always uses server side prepared statements for
Java PreparedStatements. There are two reasons to use a
PreparedStatement: to send parameters out of line and to avoid replanning.
Neither the JDBC API nor the fe-be protocol really allow the user to
specify why they are using a prepared statement, so the driver has to
guess and provide a weak hint to the server.
We have a prepare threshold (settable per connection or per statement)
that indicates the number of times the statement has been executed to
consider it as a prepared statement that's used to avoid replanning.
Once we hit that the threshold we tell the server to use a named statement
and it comes up with a generic plan that should theoretically be
acceptable for a wide variety of parameter values. Prior to this
switchover we use an unnamed statement that indicates to the server that
it should use the first set of parameters it gets to construct the best
plan for those parameters.
So on an unnamed statement the server considers the parameter values in
the plan cost estimates, but it can't do constraint exclusion because
there is no guarantee that the plan generated won't be used again with
other parameters (even though the JDBC driver won't). So the disconnect
currently is that the JDBC driver has no way of telling the server, "I
promise I'll never use this plan for anything else" to allow it to do
constraint exclusion. So this requires an extension to the protocol
to fix properly.
Kris Jurka
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: books@ejurka.com, josh@agliodbs.com
Subject: Re: JDBC, prepared queries, and partitioning
In-Reply-To: <Pine.BSO.4.64.0802131404090.6785@leary.csoft.net>
References: <200802131005.30553.josh@agliodbs.com> <Pine.BSO.4.64.0802131348050.27322@leary.csoft.net> <Pine.BSO.4.64.0802131404090.6785@leary.csoft.net>
* 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