From: John Lister <john.lister-ps@kickstone.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: John Lister <john.lister-ps@kickstone.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Very strange performance decrease when reusing a PreparedStatement
Date: Sun, 03 May 2009 18:50:45 +0100
Message-ID: <49FDD975.1020002@kickstone.com> (raw)
In-Reply-To: <11395.1241361696@sss.pgh.pa.us>
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>
<49FD7383.1010005@kickstone.com>
<11395.1241361696@sss.pgh.pa.us>
Tom Lane wrote:
> John Lister <john.lister-ps@kickstone.com> writes:
>
>> However it seems that other optimisations can't be made for example it
>> doesn't seem possible to tell the server that parameter 1 is always
>> going to be an int and therefore it should be using index A. The current
>> implementation may not use index A as it is unaware as to the type of
>> the supplied parameter.
>>
>
> I don't think this is true either. The wire protocol certainly provides
> the ability for the client to tell the server what data type a parameter
> has. I don't know whether the JDBC driver makes use of that, but if it
> does not, then something like
> variable = ?
> is going to be treated exactly like
> variable = 'unmarked literal'
> and in both cases the parser's default assumption is that the
> unknown-type value has the same data type as the thing it's being
> compared to. So if the variable is indexed this would always be
> seen as a indexable comparison.
>
The JDBC driver tries to mitigate this by delaying the parse until
execution time when all the query parameters are known.
> There are certainly cases where lack of parameter type information could
> lead to a poor plan, but they are corner cases.
>
>
I was guessing on the server implementation (wrongly probably) based on
a some other posts and comments in the code. My knowledge of the query
planner is limited but i would hope there are only a few cases where
knowing the types isn't sufficient to generate good plans without
knowing the values
JOHN
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-ps@kickstone.com, tgl@sss.pgh.pa.us
Subject: Re: Very strange performance decrease when reusing a PreparedStatement
In-Reply-To: <49FDD975.1020002@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> <49FD7383.1010005@kickstone.com> <11395.1241361696@sss.pgh.pa.us> <49FDD975.1020002@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