pushing order by + limit to union subqueries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,
 I've noticed that order by / limit are not distributed to union subqueries
by the planner:

Example:

q1: (select * from t1) union all (select * from t2) order by x limit 10;
q2: (select * from t1 order by x limit 10) union all (select * from t2 order by x limit 10)
      order by x limit 10;

both queries should be equivalent, but the planner provides hugely different
plans. I was expecting that the planner could rewrite the first to the second.
Am I overlooking something? If this is the case, can anyone explain why this
optimization is not performed?

Thanks!
Paolo

[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux