Re: Very strange performance decrease when reusing a PreparedStatement

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Frédérik Bilhaut <frederik(dot)bilhaut(at)noopsis(dot)fr>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Very strange performance decrease when reusing a PreparedStatement
Date: 2009-04-28 15:21:01
Message-ID: 49F71EDD.2070200@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Frédérik Bilhaut wrote:
> Hi everybody,
>
> I am experiencing a *very* strange problem when querying Postgres
> through JDBC using PreparedStatements.
>
> To say it short, for the same SELECT query :
>
> - when reusing a single PreparedStatement the average response time per
> query is 60 milliseconds
>
> - when creating (and closing) a new PreparedStatement each time, the
> average response time drops to only 2 milliseconds !

Try with prepareThreshold=0. Probably, your particular query benefits
from re-planning each time with the particular concrete parameter values
for each execution.

(you can either specify this as a URL parameter, or tweak it on a
per-connection or per-statement basis via methods on
PGConnection/PGStatement)

-O

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Hitz 2009-04-28 19:55:40 Re: Thread hangs in VisibleBufferedInputStream.readMore
Previous Message Oliver Hitz 2009-04-28 11:40:48 Re: Thread hangs in VisibleBufferedInputStream.readMore