Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 4AD0B1337BA0 for ; Mon, 4 Oct 2010 01:00:20 -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 47838-10 for ; Mon, 4 Oct 2010 04:00:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id 8D70F1337B63 for ; Mon, 4 Oct 2010 01:00:12 -0300 (ADT) Received: from [10.0.0.53] (wallace.localnet [10.0.0.53]) by mail.postnewspapers.com.au (Postfix) with ESMTP id A7B44AEDC3; Mon, 4 Oct 2010 12:00:10 +0800 (WST) Message-ID: <4CA9514A.4090404@postnewspapers.com.au> Date: Mon, 04 Oct 2010 12:00:10 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4 MIME-Version: 1.0 To: Maciek Sakrejda CC: Boris , PG-JDBC Mailing List Subject: Re: Upgrading JDBC driver from 7.3 to 8.4 affected execution plans References: <9c7afd41-61f0-4acb-bc14-bb10aeaf395f@d17g2000yqm.googlegroups.com> <4CA91F81.4050505@opencloud.com> In-Reply-To: X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 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: 201010/35 X-Sequence-Number: 21003 On 04/10/10 11:35, Maciek Sakrejda wrote: > Could this be related to how planning works with respect to > parameterized queries [1]? If memory serves, a prepared statement is > typically planned once and that plan is used each time the statement > is executed. There can be some issues around this because when you > have a query like "SELECT * FROM foo WHERE bar > ?", the planner has > no idea of the selectivity of that predicate if it has to plan the > query before it knows what the parameters will be. E.g., if it picks > an index scan and then a query is submitted where ? is 10, if 95% of > bars are greater than 10, the executor will waste a lot of time > mucking around with the index where it should just be doing a seq > scan. IMO Pg would be well served by supporting something like "EXECUTE WITH REPLAN" or a PREPARE that doesn't cache the plan, only storing the parsed statement and handling parameter substitution. This is in the TODO as "Allow finer control over the caching of prepared query plans" http://wiki.postgresql.org/wiki/Todo . Perhaps this is something a few commercial users of Pg might consider getting together and sponsoring work on? -- Craig Ringer Tech-related writing: http://soapyfrogs.blogspot.com/