Grzegorz Jaskiewicz <g...@pointblue.com.pl> writes:

> Say I have:
>
> select foo (
>  select foo from bar1
>   union all
>  select foo from bar2
>   union all
>  select foo from bar3
>   ...
> ) a order by foo desc limit X;
>
>
> (and I can give you few other examples around the same 'note', say with when
> foo=N in outer subselect)
>
> Would anyone consider such optimization, when postgres will apply the same
> condition to inner queries, providing that their size is substantial?

Well you haven't said what optimization you're looking for here. 

I posted a patch to look for an ordered path for members of a union a while
back but it still needed a fair amount of work before it was usable.

The LIMIT can't be pushed into the union unless we do have ordered paths so
that's further down the line. (And even then it would only work if there are
no conditions on there append path.)

And I believe we already do push down where clauses like foo=N.

> Same would actually apply for different subqueries, without union/
> intersect/etc:
>
> select foo( select foo from bar1 ) a where foo in (x,y,z) order by foo  desc
> limit N

huh?

-- 
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com
  Ask me about EnterpriseDB's RemoteDBA services!

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to