Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 99F84633703 for ; Tue, 28 Apr 2009 12:21:11 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 53393-02 for ; Tue, 28 Apr 2009 12:21:08 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by mail.postgresql.org (Postfix) with ESMTP id 5F6A96333B6 for ; Tue, 28 Apr 2009 12:21:07 -0300 (ADT) Received: from 219-89-243-186.adsl.xtra.co.nz ([219.89.243.186] helo=[192.168.1.3]) by tremor.opencloud.co.nz with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1Lyp7F-0005WF-VX; Wed, 29 Apr 2009 03:21:02 +1200 Message-ID: <49F71EDD.2070200@opencloud.com> Date: Wed, 29 Apr 2009 03:21:01 +1200 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.21 (X11/20090318) MIME-Version: 1.0 To: =?ISO-8859-1?Q?Fr=E9d=E9rik_Bilhaut?= CC: pgsql-jdbc@postgresql.org Subject: Re: Very strange performance decrease when reusing a PreparedStatement References: <5C2E1645-73B6-4509-96CD-FA77869516AB@noopsis.fr> In-Reply-To: <5C2E1645-73B6-4509-96CD-FA77869516AB@noopsis.fr> X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/99 X-Sequence-Number: 19546 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