Re: Sorted union

Поиск
Список
Период
Сортировка
От Kevin Grittner
Тема Re: Sorted union
Дата
Msg-id 436A03660200002500000452@gwmta.wicourts.gov
обсуждение исходный текст
Ответ на Sorted union  (Scott Lamb <slamb@slamb.org>)
Список pgsql-performance
The ANSI/ISO specs are not at all ambiguous on this.  An
ORDER BY is not allowed for the SELECT statements within
a UNION.  It must come at the end and applied to the resulting
UNION.

Similarly, the column names in the result come from the first
query in the UNION.  Column names in the query on the right
side of a UNION are immaterial.

Unless we have reason to believe that PostgreSQL is
non-compliant on this point, I don't think it is a good idea to
slow the query down with the subquery.

-Kevin


>>> "Merlin Moncure" <merlin.moncure@rcsonline.com>  >>>

> Merlin Moncure wrote:
> > hmm, try pushing the union into a subquery...this is better style
> > because it's kind of ambiguous if the ordering will apply
before/after
> > the union.
>
> Seems to be a little slower. There's a new "subquery scan" step.

I figured.  However it's more correct, I'm not sure if the original
query is necessarily guaranteed to give the right answer (in terms of
ordering).  It might though.


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

Предыдущее
От: "Merlin Moncure"
Дата:
Сообщение: Re: Sorted union
Следующее
От: "Merlin Moncure"
Дата:
Сообщение: Re: Sorted union