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 1EE79D1B89C for ; Sun, 17 Aug 2003 15:23:16 +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 93667-01 for ; Sun, 17 Aug 2003 12:23:05 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 1EC5ED1B8A4 for ; Sun, 17 Aug 2003 12:23:05 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h7HFN15H011423; Sun, 17 Aug 2003 11:23:02 -0400 (EDT) To: Richard Huxton Cc: pgsql-sql@postgresql.org Subject: Re: Expression transformation curiosity In-reply-to: <200308171132.58073.dev@archonet.com> References: <200308171132.58073.dev@archonet.com> Comments: In-reply-to Richard Huxton message dated "Sun, 17 Aug 2003 11:32:58 +0100" Date: Sun, 17 Aug 2003 11:23:01 -0400 Message-ID: <11422.1061133781@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/205 X-Sequence-Number: 14821 Richard Huxton writes: > 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. It's actually done that way --- see the comments near the head of src/backend/optimizer/prep/prepqual.c. There are some heuristics to not do it if the expression expands "a lot", though. regards, tom lane