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 D029ED1B8A3 for ; Sun, 17 Aug 2003 10:33:36 +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 50464-02 for ; Sun, 17 Aug 2003 07:33:26 -0300 (ADT) Received: from anchor-post-31.mail.demon.net (anchor-post-31.mail.demon.net [194.217.242.89]) by svr1.postgresql.org (Postfix) with ESMTP id 843E9D1B8A1 for ; Sun, 17 Aug 2003 07:33:08 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-31.mail.demon.net with esmtp (Exim 3.35 #1) id 19oKqU-000AU3-0V for pgsql-sql@postgresql.org; Sun, 17 Aug 2003 11:33:11 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 741FC1781B for ; Sun, 17 Aug 2003 11:33:08 +0100 (BST) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id D50261781A for ; Sun, 17 Aug 2003 11:32:58 +0100 (BST) From: Richard Huxton To: pgsql-sql@postgresql.org Subject: Expression transformation curiosity Date: Sun, 17 Aug 2003 11:32:58 +0100 User-Agent: KMail/1.5 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200308171132.58073.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/204 X-Sequence-Number: 14820 I just had a look at EXPLAIN ANALYSE output for an SQL function I'm trying to write. The WHERE clause wasn't too complex, but the explain output took up a dozen lines. 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) Now these two are equivalent, but it would take me forever to demonstrate that with the full query. I'm happy the planner is going to get it right, but I'm confused as to why the transformation occurs. 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. Oh, btw - 7.3.2 on this box, I'll be looking at 7.3.3/4 later today. -- Richard Huxton Archonet Ltd