Re: subselect, order by and left join

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: "Morten K(dot) Poulsen" <morten-postgresql(at)afdelingp(dot)dk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: subselect, order by and left join
Date: 2004-11-08 12:54:40
Message-ID: 20041108045256.V86244@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Morten K. Poulsen 2004-11-08 14:58:37 Re: subselect, order by and left join
Previous Message Masse Jacques 2004-11-08 10:45:56 Re: Visual DATA MODEL Designer in linux?