X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 166019FB288 for ; Thu, 3 Aug 2006 06:18:03 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 86106-04 for ; Thu, 3 Aug 2006 06:17:51 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.ecircle.de (mail.ecircle.de [195.140.186.200]) by postgresql.org (Postfix) with ESMTP id 169059FB282 for ; Thu, 3 Aug 2006 06:17:53 -0300 (ADT) Received: from einstein.muc.ecircle.de (einstein.muc.ecircle.de [192.168.1.7]) by mail.ecircle.de (READY) with ESMTP id 3E5E455C01F; Thu, 3 Aug 2006 11:17:50 +0200 (CEST) Received: from [192.168.1.91] ([192.168.1.91]) by einstein.muc.ecircle.de with Microsoft SMTPSVC(6.0.3790.1830); Thu, 3 Aug 2006 11:18:13 +0200 Subject: Re: PGStatement#setPrepareThreshold From: Csaba Nagy To: Oliver Jowett Cc: Postgres JDBC In-Reply-To: <44D19215.1070002@opencloud.com> References: <1154529173.21451.27.camel@coppola.muc.ecircle.de> <44D19215.1070002@opencloud.com> Content-Type: text/plain Message-Id: <1154596670.21451.44.camel@coppola.muc.ecircle.de> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Thu, 03 Aug 2006 11:17:50 +0200 Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 03 Aug 2006 09:18:13.0667 (UTC) FILETIME=[BF17BF30:01C6B6DD] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.461 tagged_above=0 required=5 tests=AWL, SPF_PASS X-Spam-Level: X-Archive-Number: 200608/10 X-Sequence-Number: 15537 Oliver, Thanks for your answer. > The logic looks like: > - On statement creation set count=0 > - On each execution: > - If this statement is a PreparedStatement, increment count > - If threshold == 0 or count < threshold, make this execution "oneshot" > - Execute query OK, I've checked the sources. I'm using postgresql-jdbc-8.1dev-400. The relevant piece of code looks to me to be in AbstractJdbc2Statement#execute(Query,ParameterList,int): // Only use named statements after we hit the threshold if (preparedQuery != null) { ++m_useCount; // We used this statement once more. if (m_prepareThreshold == 0 || m_useCount < m_prepareThreshold) flags |= QueryExecutor.QUERY_ONESHOT; } So if preparedQuery is not null for prepared statements, it should work as you said... > "oneshot" queries use the unnamed statement (with one exception: queries > that will be backed by a portal use a named statement) > > > I couldn't figure out this from the log files... postgres logs the > > queries as , but that doesn't tell me too much. > > If you're seeing then those queries aren't using server-side > prepare (the unnamed statement is also special as it's the trigger for > the planner behaviour that you are trying to avoid..) .. so it seems > that you are not managing to trigger server-side prepare for some > reason. Maybe you are using a plain Statement? No, I definitely use a prepared statement, I have lots of parameters in the IN clause... that's part of the problem. And I checked again, and it is logged as in the postgres logs. So the only remaining suspect is that the threshold is not really set to 1. This is somewhat strange, as I use a connection pool and set it to 1 on each connection, and only set it to 0 on specific statements where I do want the parameter values to be taken into account (I know, I'll have to change this, but it was the easiest way to get the system stable after switching from Oracle to postgres). I will have to investigate what is the real problem. Thanks, Csaba.