Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id E8A142E3A12 for ; Wed, 6 Feb 2008 07:53:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 40622-05 for ; Wed, 6 Feb 2008 07:53:01 -0400 (AST) Received: from outmail129179.authsmtp.com (outmail129179.authsmtp.com [62.13.129.179]) by postgresql.org (Postfix) with ESMTP id E696C2E1374 for ; Wed, 6 Feb 2008 07:53:00 -0400 (AST) Received: from outmail128184.authsmtp.net (outmail128184.authsmtp.net [62.13.128.184]) by punt3.authsmtp.com (8.13.8/8.13.8/Kp) with ESMTP id m16Bqw3C063927; Wed, 6 Feb 2008 11:52:59 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 m16Bqwxv088944; Wed, 6 Feb 2008 11:52:58 GMT Subject: Re: Optimizer : query rewrite and execution plan ? From: Simon Riggs To: SURANTYN Jean =?ISO-8859-1?Q?Fran=E7ois?= Cc: pgsql-performance@postgresql.org In-Reply-To: <60F4687513E90748AE8933DEA5D054E79ACBDE@SLAM0018.match-supermarket.com> References: <60F4687513E90748AE8933DEA5D054E79ACBDE@SLAM0018.match-supermarket.com> Content-Type: text/plain; charset=utf-8 Date: Wed, 06 Feb 2008 11:53:46 +0000 Message-Id: <1202298826.4252.972.camel@ebony.site> Mime-Version: 1.0 X-Mailer: Evolution 2.8.2 Content-Transfer-Encoding: 8bit X-Server-Quench: 0fa0f3c8-d4aa-11dc-9554-001185d377ca X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFaANba1xT HGQLW1xEUVx7XGF/ bgIfZQBDYEtPQQZr TkxLXVBXCwUmXB0H dF9ZGl9yfw1PfHo+ ZEFlXz5bChV6I0Uu SlMAETxXeGZhPDMC WUVdcx5UcAJLdhoR 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/65 X-Sequence-Number: 28607 On Wed, 2008-02-06 at 09:42 +0100, SURANTYN Jean François wrote: > That issue is very annoying because with generated SQL queries (from > Business Objects for example) on big tables, it is possible that some > queries have several times the same "where" condition ("where n=1 and > n=1" for example), and as the optimizer is under-estimating the number > of returned rows, some bad execution plans can be chosen (nested loops > instead of hash joins for example) I can see the annoyance there. There's a balance in the planner between time spent to optimize the query and time spent to correct mistakes. If we looked continually for mistakes then planning time would increase for everybody that didn't suffer from this problem. 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. -- Simon Riggs 2ndQuadrant http://www.2ndQuadrant.com