Re: Union strange explain - Mailing list pgsql-admin

From Tom Lane
Subject Re: Union strange explain
Date
Msg-id 6645.1025828877@sss.pgh.pa.us
Whole thread Raw
In response to Re: Union strange explain  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-admin
Stephan Szabo <sszabo@megazone23.bigpanda.com> writes:
> I think there was some question about
> whether it was safe to do that optimization (ie,
> is select * from (a union [all] b) where condition
> always the same as
>  select * from a where condition union [all]
>  select * from b where condition
> )
> This was discussed recently, but I forget what the final determination
> was.

There wasn't any final determination --- it's still an open issue
whether there are any limitations the planner would have to consider
when trying to push down conditions into UNIONs.  Offhand it seems
to me that the change is always safe when dealing with UNION ALL,
but I'm not quite convinced about UNION.  And what of INTERSECT
and EXCEPT?

Another interesting question is whether there are cases where the
planner could legally push down the condition, but should not because
it would end up with a slower plan.  I can't think of any examples
offhand, but that doesn't mean there aren't any.

            regards, tom lane



pgsql-admin by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Performance impact of record sizes
Next
From: Gregor Mosheh
Date:
Subject: memory strangeness (fwd)