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