Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id E7BA02E39EE for ; Mon, 11 Feb 2008 06:22:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 19450-01 for ; Mon, 11 Feb 2008 06:22:20 -0400 (AST) Received: from outmail128141.authsmtp.com (outmail128141.authsmtp.com [62.13.128.141]) by postgresql.org (Postfix) with ESMTP id 1E9962E392A for ; Mon, 11 Feb 2008 05:44:18 -0400 (AST) Received: from outmail128184.authsmtp.net (outmail128184.authsmtp.net [62.13.128.184]) by punt2.authsmtp.com (8.13.8/8.13.8/Kp) with ESMTP id m1B9hxO0090205; Mon, 11 Feb 2008 09:44:00 GMT Received: from [192.168.0.3] (85-211-31-42.dyn.gotadsl.co.uk [85.211.31.42]) (authenticated bits=0) by mail.authsmtp.com (8.13.8/8.13.8/Kp) with ESMTP id m1B9hwth059875; Mon, 11 Feb 2008 09:43:58 GMT Subject: Re: Optimizer : query rewrite and execution plan ? From: Simon Riggs To: Tom Lane Cc: theo@flame.co.za, pgsql-performance@postgresql.org In-Reply-To: <9924.1202313626@sss.pgh.pa.us> References: <60F4687513E90748AE8933DEA5D054E79ACBDE@SLAM0018.match-supermarket.com> <1202298826.4252.972.camel@ebony.site> <1202299962.4274.22.camel@localhost6.localdomain6> <9924.1202313626@sss.pgh.pa.us> Content-Type: text/plain Date: Mon, 11 Feb 2008 09:44:47 +0000 Message-Id: <1202723087.4247.150.camel@ebony.site> Mime-Version: 1.0 X-Mailer: Evolution 2.8.2 Content-Transfer-Encoding: 7bit X-Server-Quench: de2edf9b-d885-11dc-9670-001185d377ca X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadRtFaQRba1xT HGQLW1xEUFR7XWB/ bgIfZQBDYEtPQQZr TkxLXVBXCwUmXB1z D0ZZFkFycgxOf3s+ Z0ZlVz4PCUYvIRB0 EFMAHWUDeGZhPDMC WUZfdx5UcAJLdhoR aVd4ByJDAzANdhEA MjUdGAoUCH14MDhU RwAfIEhaEw4SAzMm VlgYECo1HFEIDyw1 I1QrOlMXAVoQNUN6 KV8oXxpPW3Vp X-Authentic-SMTP: 61633235383639.squirrel.dmpriest.net.uk:787/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: 200802/96 X-Sequence-Number: 28638 On Wed, 2008-02-06 at 11:00 -0500, Tom Lane wrote: > Theo Kramer writes: > > On Wed, 2008-02-06 at 11:53 +0000, Simon Riggs wrote: > >> Since the SQL is not your fault and difficult to control, it is an > >> argument in favour of an optional planner mode that would perform > >> additional checks for redundant clauses of various kinds. The default > >> for that would be "off" since most people don't suffer from this > >> problem. BO isn't the only SQL generating-client out there, so I think > >> this is a fairly wide problem. > We used to have code that removed duplicate WHERE clauses (check the > revision history for prepqual.c). It was taken out because it consumed > excessive amounts of planning time without accomplishing a darn thing > for most queries. There is no chance that it will be put back in as the > only behavior, or even the default behavior, but I can see the reasoning > for offering an option as Simon suggests. I was wondering if we might do that automatically? It seems easy to imagine a switch, but I wonder if we'd be able to set it correctly in enough situations to make it worthwhile. Say if cost of best plan >= N then recheck query for strangeness. If anything found, re-plan query. That way we only pay the cost of checking for longer queries and we only actually re-plan for queries that will benefit. -- Simon Riggs 2ndQuadrant http://www.2ndQuadrant.com