UNION messing up sorting WAS: psql performance

From: Joseph Shraibman <jks(at)selectacast(dot)net>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: UNION messing up sorting WAS: psql performance
Date: 2005-04-15 04:23:14
Message-ID: 425F41B2.5000004@selectacast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alvaro Herrera wrote:

>>Incidentally when I did that I only got back one row. What's up with that?
>
>
> Try with "union all" instead of plain union.
>
Talk about serendipity. The problem I've been struggling with for the
last few hours has been why my query wasn't producing sorted output even
though I put in an ORDER BY and the EXPLAIN shows that it is ordering.
The DISTINCT implied by the UNION must have been messing up the sorting.

The docs say
(http://www.postgresql.org/docs/7.4/interactive/sql-select.html#SQL-UNION):

select_statement is any SELECT statement without an ORDER BY, LIMIT, or
FOR UPDATE clause. (ORDER BY and LIMIT can be attached to a
subexpression if it is enclosed in parentheses.

... but I *did* put my SELECTs in parentheses. This is either a bug in
pg or a serious ommision from the docs.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joseph Shraibman 2005-04-15 04:33:41 Re: psql performance
Previous Message Tom Lane 2005-04-15 04:21:31 Re: Assigning password to the superuser