Re: subselect, order by and left join - Mailing list pgsql-general

From Stephan Szabo
Subject Re: subselect, order by and left join
Date
Msg-id 20041108045256.V86244@megazone.bigpanda.com
Whole thread Raw
In response to subselect, order by and left join  ("Morten K. Poulsen" <morten-postgresql@afdelingp.dk>)
Responses Re: subselect, order by and left join
Re: subselect, order by and left join
List pgsql-general
On Mon, 8 Nov 2004, Morten K. Poulsen wrote:

> Please let me know if this is not the list to ask this kind of question.
>
> I am trying to optimize a query that joins two relatively large (750000 rows in
> each) tables. If I do it using a subselect, I can "force" the planner to choose
> the fastest path. Now, my question is:
>
> If I have a subselect with an ORDER BY, and I LEFT JOIN the result with the
> other table, is the order maintained? Or is PostgreSQL free to return the rows
> in any order, after the join?

AFAIK, you have no guarantees as to the output order unless you have
another order by.  The join may destroy the ordering, so even if you get
the ordering you want right now, you shouldn't rely on it.

pgsql-general by date:

Previous
From: Masse Jacques
Date:
Subject: Re: Visual DATA MODEL Designer in linux?
Next
From: "Morten K. Poulsen"
Date:
Subject: Re: subselect, order by and left join