Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 7BDD62E3985 for ; Wed, 6 Feb 2008 08:13:01 -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 74097-04-2 for ; Wed, 6 Feb 2008 08:12:45 -0400 (AST) Received: from flame.co.za (ns.flame.co.za [160.124.170.1]) by postgresql.org (Postfix) with ESMTP id 987B32E38DF for ; Wed, 6 Feb 2008 08:12:51 -0400 (AST) Received: from [192.168.0.138] (unknown [196.209.200.95]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by flame.co.za (Postfix) with ESMTP id A634780306 for ; Wed, 6 Feb 2008 14:12:43 +0200 (SAST) Subject: Re: Optimizer : query rewrite and execution plan ? From: Theo Kramer Reply-To: theo@flame.co.za To: pgsql-performance@postgresql.org In-Reply-To: <1202298826.4252.972.camel@ebony.site> References: <60F4687513E90748AE8933DEA5D054E79ACBDE@SLAM0018.match-supermarket.com> <1202298826.4252.972.camel@ebony.site> Content-Type: text/plain; charset=ISO-8859-1 Organization: Flame Computing Enterprises cc Date: Wed, 06 Feb 2008 14:12:42 +0200 Message-Id: <1202299962.4274.22.camel@localhost6.localdomain6> Mime-Version: 1.0 X-Mailer: Evolution 2.10.3 (2.10.3-4.fc7) Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/66 X-Sequence-Number: 28608 On Wed, 2008-02-06 at 11:53 +0000, Simon Riggs wrote: > 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. I would have to disagree. I spend a lot of time writing code that generates SQL from a business app and feel strongly that any optimisation is my responsibility. Having to re-configure PG to switch on a planner mode, as suggested above, to address badly generated SQL is not a good idea. This with experience on having to talk business application developers through re-configuring a database. -- Regards Theo