pushing order by + limit to union subqueries

Поиск
Список
Период
Сортировка
От Paolo Losi
Тема pushing order by + limit to union subqueries
Дата
Msg-id CAP=2L=FRza_catqP9LRfJOMybzoorpxSBxSP=J1o9WZnFp1USg@mail.gmail.com
обсуждение исходный текст
Ответы Re: pushing order by + limit to union subqueries  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-performance
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

В списке pgsql-performance по дате отправления:

Предыдущее
От: Josh Berkus
Дата:
Сообщение: Bad cost estimate with FALSE filter condition
Следующее
От: Tom Lane
Дата:
Сообщение: Re: pushing order by + limit to union subqueries