Re: Expression transformation curiosity

From: "Alexander M(dot) Pravking" <fduch(at)antar(dot)bryansk(dot)ru>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Expression transformation curiosity
Date: 2003-08-17 15:39:38
Message-ID: 20030817153938.GA437@dyatel.antar.bryansk.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sun, Aug 17, 2003 at 11:32:58AM +0100, Richard Huxton wrote:
> 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.

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.

--
Fduch M. Pravking

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2003-08-17 17:01:23 Re: Expression transformation curiosity
Previous Message Tom Lane 2003-08-17 15:23:01 Re: Expression transformation curiosity