Re: Expression transformation curiosity - Mailing list pgsql-sql

From Tom Lane
Subject Re: Expression transformation curiosity
Date
Msg-id 11422.1061133781@sss.pgh.pa.us
Whole thread Raw
In response to Expression transformation curiosity  (Richard Huxton <dev@archonet.com>)
List pgsql-sql
Richard Huxton <dev@archonet.com> 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


pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Expression transformation curiosity
Next
From: "Alexander M. Pravking"
Date:
Subject: Re: Expression transformation curiosity