From: Roland Roberts <roland@astrofoto.org>
To: pgsql-jdbc@postgresql.org
Subject: Re: Very strange performance decrease when reusing a PreparedStatement
Date: Sun, 03 May 2009 19:12:21 -0400
Message-ID: <49FE24D5.4060904@astrofoto.org> (raw)
In-Reply-To: <49FE0731.2030403@kickstone.com>
References: <5C2E1645-73B6-4509-96CD-FA77869516AB@noopsis.fr>
<49F71EDD.2070200@opencloud.com>
<02437794-A78D-449C-843F-B823195F9623@noopsis.fr>
<fdeb32eb0905030122t665113e5nd34e7268d9ab1863@mail.gmail.com>
<491f66a50905030310j5b4cdcd8jbf4f6e757c2ba580@mail.gmail.com>
<fdeb32eb0905030928j4e72f1e3vbecb78d0cb74be58@mail.gmail.com>
<49FDEB97.6050800@astrofoto.org>
<fdeb32eb0905031347o3f92f228ib0b6d62b2c0e0cd5@mail.gmail.com>
<49FE0731.2030403@kickstone.com>
John Lister wrote:
> Péter Kovács wrote:
>> Regardless of what Oracle can or cannot do, the question stays put:
>> Can precompiled Postgres SQL statements handle varying parameters? If
>> they can (and people here say they can), why doesn't the JDBC
>> PreparedStatement take advantage of it? (If they can't, I don't think
>> this is an impossible thing to do. My gut feeling is that a large
>> portion of the query planning process can be be completed up to the
>> inclusion of the actual values of the parameters. The resulting "query
>> plan template" could be cached and reused and refined for each
>> execution by taking account of the selectivity of the actual parameter
>> values.)
> I'm fairly sure the JDBC driver does take advantage of it, with a
> couple of exceptions at the moment. The first time a query is
> executed, the parameter types are fetched and used on subsequent
> queries. Server side prepared statements aren't used until a user
> controlled threshold has been reached.. I may be wrong, but i think
> the oracle driver does the planning when the statement is created and
> not at execution time. The closest postgres comes to this is setting
> the prepareThreshold to 1 which means every statement gets a server
> side prepared statement.
No, my point was that PostgreSQL is doing the same thing that Oracle is
doing and in both cases it can bite you. Both are looking at the bind
variables to come up with a plan but the plan is retained for reuse
under the assumption that the bind variables will be, statistically at
least, similar the next time. When that assumption is violated, you get
stuck with a bad plan. The purpose of my Oracle example was to give a
concrete example of such a violation.
Planning is a server side activity, always. talking about it as
something that happens in the JDBC driver makes it sound like a client
side activity, but it's not.
regards,
roland
--
PGP Key ID: 66 BC 3B CD
Roland B. Roberts, PhD RL Enterprises
roland@rlenter.com 6818 Madeline Court
roland@astrofoto.org Brooklyn, NY 11220
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: roland@astrofoto.org
Subject: Re: Very strange performance decrease when reusing a PreparedStatement
In-Reply-To: <49FE24D5.4060904@astrofoto.org>
References: <5C2E1645-73B6-4509-96CD-FA77869516AB@noopsis.fr> <49F71EDD.2070200@opencloud.com> <02437794-A78D-449C-843F-B823195F9623@noopsis.fr> <fdeb32eb0905030122t665113e5nd34e7268d9ab1863@mail.gmail.com> <491f66a50905030310j5b4cdcd8jbf4f6e757c2ba580@mail.gmail.com> <fdeb32eb0905030928j4e72f1e3vbecb78d0cb74be58@mail.gmail.com> <49FDEB97.6050800@astrofoto.org> <fdeb32eb0905031347o3f92f228ib0b6d62b2c0e0cd5@mail.gmail.com> <49FE0731.2030403@kickstone.com> <49FE24D5.4060904@astrofoto.org>
* 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