X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 53FF6D1B56B for ; Sun, 17 Aug 2003 17:01:40 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 95490-05 for ; Sun, 17 Aug 2003 14:01:30 -0300 (ADT) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by svr1.postgresql.org (Postfix) with ESMTP id 272ECD1B523 for ; Sun, 17 Aug 2003 14:01:26 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-35.mail.demon.net with esmtp (Exim 3.36 #2) id 19oQuD-00006D-0Z; Sun, 17 Aug 2003 18:01:25 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 25AF916950; Sun, 17 Aug 2003 18:01:23 +0100 (BST) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 55EDA16947; Sun, 17 Aug 2003 18:01:23 +0100 (BST) From: Richard Huxton To: "Alexander M. Pravking" Subject: Re: Expression transformation curiosity Date: Sun, 17 Aug 2003 18:01:23 +0100 User-Agent: KMail/1.5 Cc: pgsql-sql@postgresql.org References: <200308171132.58073.dev@archonet.com> <20030817153938.GA437@dyatel.antar.bryansk.ru> In-Reply-To: <20030817153938.GA437@dyatel.antar.bryansk.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200308171801.23667.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/207 X-Sequence-Number: 14823 On Sunday 17 August 2003 16:39, Alexander M. Pravking wrote: > On Sun, Aug 17, 2003 at 11:32:58AM +0100, Richard Huxton wrote: > > Boiling the problem down, I've looked at a clause of the form: > > a OR (b AND c) > > which PG converts to: > > (a OR b) AND (a OR c) > > Is it an artefact of displaying the EXPLAIN, or is it actually processed > > that way? You could see how testing "a" twice could be expensive in some > > situations. > > Looks like it actually works this way. > I had the same problem several weeks ago on 7.3.3 with 4 such OR's. > The final filter became monsterous, and the query was very slow. > > I've simply rewritten the query using UNION, and it became much faster. Doesn't seem to matter much in this case, although I tried it as a UNION just to check the results were the same. Thanks Alexander -- Richard Huxton Archonet Ltd