Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id C8557632B72 for ; Mon, 1 Mar 2010 14:49:20 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 02153-06 for ; Mon, 1 Mar 2010 18:49:10 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from Acrys.COM (vpn.acrys.com [195.145.38.66]) by mail.postgresql.org (Postfix) with ESMTP id 0C517633085 for ; Mon, 1 Mar 2010 14:49:09 -0400 (AST) Received: from [10.0.2.73] (nb-pruy.acrys.com [10.0.2.73]) by Acrys.COM (8.14.4/8.14.4/2.13) with ESMTP id o21In8ct000070; Mon, 1 Mar 2010 19:49:08 +0100 (CET) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.95.3 at gaia.acrys.com Message-ID: <4B8C0C23.9000107@acrys.com> Date: Mon, 01 Mar 2010 19:49:07 +0100 From: Rainer Pruy Organization: Acrys Consult GmbH & Co. KG User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.1.5) Gecko/20091130 SUSE/3.0.0-1.1.1 Lightning/1.0b1 Thunderbird/3.0 MIME-Version: 1.0 To: Tom Lane CC: "pgsql-performance@postgresql.org" Subject: Re: Query slowing down significantly?? References: <4B8BB815.4060104@acrys.com> <17910.1267460132@sss.pgh.pa.us> <4B8BFDEF.1080006@acrys.com> <20628.1267467300@sss.pgh.pa.us> In-Reply-To: <20628.1267467300@sss.pgh.pa.us> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201003/11 X-Sequence-Number: 37836 I'm already at it It is a Java app, using jdbc, but through a proprietary persistence framework. I'm just busy evaluating the effects on the app of prohibiting prepared statements via jdbc. If this is not worthwhile, I'm bound to some expensive reorganizations, sigh. Nevertheless, thanks for your help in reminding me about obvious use of prepared statements. Rainer PS: I've just read the thread on "Avoiding bad prepared-statement plans". Very interesting. Will track this... Am 01.03.2010 19:15, wrote Tom Lane: > Rainer Pruy writes: >> The prepared statement gives: >> ... >> And that is quite a bad plan given the current distribution of values. > > Yeah. The planner really needs to know the actual parameter values in > order to pick the best plan for this case. > > One thing that you might be able to do to avoid giving up on prepared > statements entirely is to use an "unnamed" rather than named prepared > statement here. That will lead to the query plan being prepared only > when the parameter values are made available, rather than in advance. > It'd depend on what client library you're using whether this is a simple > change or not. > > regards, tom lane