Re: OR vs UNION vs UNION ALL

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: OR vs UNION vs UNION ALL
Дата
Msg-id CAHyXU0zstNjDcaW-ZYOV_dh9rsLpE-N05x37r_waS=jOjo5WYA@mail.gmail.com
обсуждение исходный текст
Ответ на OR vs UNION vs UNION ALL  (Etienne Champetier <champetier.etienne@gmail.com>)
Список pgsql-general
On Wed, Sep 23, 2015 at 8:38 AM, Etienne Champetier
<champetier.etienne@gmail.com> wrote:
> Two questions:
> 1) Is it normal to have such a big difference between OR and UNION and
> should i always prefer UNION when possible?

yes, it's unfortunate but true.  I consider automatic transformation
of these expressions to possible enhancements to the planner.
Although the fact it hasn't already been done hints at high difficulty
or complicated trade-offs.

Note, these queries are not the same.  OR/UNION ALL should give the
same result regardless of input but UNION has a deduplication step
that gives a different answer.  Avoid pure UNION unless it's very
specifically what you want; it can act as an optimization fence in
more complex queries.

> 2) How can UNION ALL be slower than UNION, it's not doing the HashAggregate
> but is 0.2s slower?

likely measurement noise.  take 10 samples and take a median.

merlin


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

Предыдущее
От: Ramesh T
Дата:
Сообщение: pgcrypto
Следующее
От: Jeff Janes
Дата:
Сообщение: Re: pgcrypto