Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 70B159F9A0A for ; Thu, 27 Sep 2007 12:26:12 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 24380-06 for ; Thu, 27 Sep 2007 12:25:54 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from outmail128148.authsmtp.net (outmail128148.authsmtp.net [62.13.128.148]) by postgresql.org (Postfix) with ESMTP id 611639F9A00 for ; Thu, 27 Sep 2007 12:26:00 -0300 (ADT) Received: from outmail128176.authsmtp.co.uk (outmail128176.authsmtp.co.uk [62.13.128.176]) by punt3.authsmtp.com (8.13.8/8.13.8/Kp) with ESMTP id l8RFPtWl071643; Thu, 27 Sep 2007 16:25:57 +0100 (BST) Received: from [192.168.0.3] (85-211-149-22.dyn.gotadsl.co.uk [85.211.149.22]) (authenticated bits=0) by mail.authsmtp.com (8.13.8/8.13.8/Kp) with ESMTP id l8RFPtFa092580; Thu, 27 Sep 2007 16:25:55 +0100 (BST) Subject: Re: Searching for the cause of a bad plan From: Simon Riggs To: Tom Lane Cc: Csaba Nagy , postgres performance list In-Reply-To: <29186.1190904025@sss.pgh.pa.us> References: <1190369024.4661.173.camel@PCD12478> <6175.1190390913@sss.pgh.pa.us> <1190396352.4202.109.camel@ebony.site> <13644.1190397220@sss.pgh.pa.us> <1190399879.4202.127.camel@ebony.site> <27857.1190417434@sss.pgh.pa.us> <1190640429.4181.165.camel@ebony.site> <1190818357.5430.29.camel@PCD12478> <21582.1190820137@sss.pgh.pa.us> <1190894004.5430.46.camel@PCD12478> <29186.1190904025@sss.pgh.pa.us> Content-Type: text/plain Date: Thu, 27 Sep 2007 16:24:37 +0100 Message-Id: <1190906677.4194.78.camel@ebony.site> Mime-Version: 1.0 X-Mailer: Evolution 2.8.2 Content-Transfer-Encoding: 7bit X-Server-Quench: f0f7ff14-6d0d-11dc-b86a-001185d377ca X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadRtFagJbflxB HGQLW1NEUVt7W2Z/ bg8fZQBDYEtPQQRu WVZLQE1QERpoT0AJ ZGh+Fm8jdwxEfXZw K0RiXHgVCkQschAr Q0pJEzkGMXphaTRM TRJQcVJJcANLfxdA PlN4UyBcLwdSbGoL JyIJERcLGAAXEylc WAoNLFQdCUgMBHYg Rx1KFjwyBkBNQCt7 JlQsI1JUBEIYNC0A X-Authentic-SMTP: 61633235383639.squirrel.dmpriest.net.uk:752/Kp X-Report-SPAM: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-Virus-Status: No virus detected - but ensure you scan with your own anti-virus system! X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/458 X-Sequence-Number: 27003 On Thu, 2007-09-27 at 10:40 -0400, Tom Lane wrote: > And yet there's another trap here: if the parameter you passed in > chanced to be one of the very common values, a plan that was optimized > for a small number of matches would perform terribly. I wonder could we move prepare_threshold onto the server? (from JDBC). When we prepare a statement, we record the current setting of the prepare_threshold parameter into the plan for that statement. Valid settings are -1, 0 or more. If the setting is -1 then we always re-plan the statement. If the setting is 0 then we plan the statement generically. If the setting is > 0 then we plan the statement according to the specific parameter value and then decrement the prepare count, so eventually the executions will hit 0 (above). That would also simplify JDBC and allow the functionality from other clients, as well as from within PLs. We could also force the plan to be -1 when the planning involves something that would force it to be a one-time plan, e.g. constraint exclusion. (So we could then get rid of that parameter). -- Simon Riggs 2ndQuadrant http://www.2ndQuadrant.com