Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 4E3E3B5DC09 for ; Tue, 20 Sep 2011 20:39:15 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 90205-08 for ; Tue, 20 Sep 2011 23:39:09 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail-vw0-f49.google.com (mail-vw0-f49.google.com [209.85.212.49]) by mail.postgresql.org (Postfix) with ESMTP id F24A5B5DBC4 for ; Tue, 20 Sep 2011 20:39:08 -0300 (ADT) Received: by vws8 with SMTP id 8so1464534vws.22 for ; Tue, 20 Sep 2011 16:39:08 -0700 (PDT) Received: by 10.52.98.226 with SMTP id el2mr1399810vdb.177.1316561948544; Tue, 20 Sep 2011 16:39:08 -0700 (PDT) Received: from [10.1.1.6] (124-148-242-247.dyn.iinet.net.au. [124.148.242.247]) by mx.google.com with ESMTPS id b13sm2327628vdj.2.2011.09.20.16.39.06 (version=SSLv3 cipher=OTHER); Tue, 20 Sep 2011 16:39:07 -0700 (PDT) Message-ID: <4E792417.5080205@ringerc.id.au> Date: Wed, 21 Sep 2011 07:39:03 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 To: Royce Ausburn CC: pgsql-performance Subject: Re: Prepared statements and suboptimal plans References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201109/295 X-Sequence-Number: 45071 On 21/09/2011 7:27 AM, Royce Ausburn wrote: > Hi all, > > It looks like I've been hit with this well known issue. I have > a complicated query that is intended to run every few minutes, I'm > using JDBC's Connection.prepareStatement() mostly for nice > parameterisation, but postgres produces a suboptimal plan due to its > lack of information when the statement is prepared. > > [snip] > > We've been worst hit by this query on an 8.3 site. Another site is > running 8.4. Have there been improvements in this area recently? > Upgrading to 9.0 might be viable for us. Tom just mentioned that 9.1 will be able to re-plan parameterized prepared statements, so this issue will go away. In the mean time you can only really use the standard workaround of setting the prepare theshold to 0 to disable server-side prepare, so you can continue to use JDBC prepared statements and have the driver do the parameter substitution for you. -- Craig Ringer