Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 26D6E2E36A2 for ; Thu, 10 Jan 2008 06:53:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 35897-05 for ; Thu, 10 Jan 2008 06:53:43 -0400 (AST) Received: from mail.planwerk6.de (taube.planwerk6.de [88.198.1.9]) by postgresql.org (Postfix) with ESMTP id EDA5F2E3421 for ; Thu, 10 Jan 2008 06:53:47 -0400 (AST) Received: from localhost (taube.planwerk6.de [127.0.0.1]) by mail.planwerk6.de (Postfix) with ESMTP id 80AAA85C1C5; Thu, 10 Jan 2008 11:53:43 +0100 (CET) Received: from mail.planwerk6.de ([127.0.0.1]) by localhost (mail.planwerk6.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 21484-03; Thu, 10 Jan 2008 11:53:43 +0100 (CET) Received: from supertipp.de (pd95b4e37.dip0.t-ipconnect.de [217.91.78.55]) (using TLSv1 with cipher EXP1024-RC4-SHA (56/128 bits)) (No client certificate requested) by mail.planwerk6.de (Postfix) with ESMTP id 12F2385C145; Thu, 10 Jan 2008 11:53:43 +0100 (CET) From: mljv@planwerk6.de To: Kris Jurka Subject: Re: Prepared Statements Date: Thu, 10 Jan 2008 11:53:38 +0100 User-Agent: KMail/1.9.1 Cc: pgsql-general@postgresql.org References: <200801092002.15417.mljv@planwerk6.de> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200801101153.38782.mljv@planwerk6.de> X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at planwerk6.de X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/441 X-Sequence-Number: 126651 first: thanks a lot for your answer. it already helped me a lot, but i still have some questions: Am Mittwoch, 9. Januar 2008 21:16 schrieb Kris Jurka: > On Wed, 9 Jan 2008, mljv@planwerk6.de wrote: > > - I know there is a PREPARE Statement in Postgresql and read the docs. > > - in PostgresqlJDBC i have a prepareThreshold parameter which i left to > > default of 5. > > - in DBCP i have a property "poolPreparedStatements", set to true. Does > > ist just configure prepareThreshold of JDBC or does it maintain a > > statementPool of it's own? > > The postgresql JDBC driver does not have a statement pool of its own, so > the two options prepareThreshold and poolPreparedStatements are > complementary. By itself the JDBC driver will switch to a long term > prepared plan once you've used the exact same PreparedStatement object > prepareThreshold number of times. Since it doesn't pool things behind the > scenes, you've got to retain a reference to the same PreparedStatement > object which is difficult or impossible in many applications. ah! So it doesn't help if it's the same statement, it has to be the same object! So DBCP has a statement pool like a map, say Map so it can fetch the reference to already existing prepared Statement by looking at the statement itself, right? But JDBC itself uses the "PREPARE" sql command, right? So the statement is not really unnamed its name is "" like prepare "" as select * from table; execute ""; But i can't see any DEALLOCATE statements in my log file. > This is > where the DBCP statement pool comes in. It proxies PreparedStatement > wrappers to one underlying PG PreparedStatement object so that you can hit > prepareThreshold. > > > In my Log files of postgresql each query is called like this: > > > > EXECUTE [PREPARE: select ...] > > > > I have not found anything about preparing "unnamed" statements. What > > does it mean? > > Unnamed statements are what the driver uses before it hits the > prepareThreshold limit. Once it has determined the statement will be > reused many times it changes to a named statement that has a longer > lifespan. What do you mean with "longer lifespan"? Doesn't the JDBC driver uses the PREPARE Sql Statement and therefore the prepared Statement has the same lifespan as the connection? If so, as connections are pooled and never closed, the prepared Statement will last forever. What if the table analyzes changes and a better execution plan could be found? kind regards, janning