Re: Controlling Reuslts with Limit - Mailing list pgsql-sql

From Bryan White
Subject Re: Controlling Reuslts with Limit
Date
Msg-id 00b801c09dde$f8cf2740$2dd260d1@arcamax.com
Whole thread Raw
In response to Controlling Reuslts with Limit  (Najm Hashmi <najm@mondo-live.com>)
Responses Re: Controlling Reuslts with Limit  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-sql

> Hi,
>  I was reading through Bruce's on line . I found follwing bit unclear...
>
> "Notice that each query uses ORDER BY . Although this clause is not
required,
> LIMIT without ORDER BY returns random rows from the query, which would be
> useless. "
>
> When I run a query several time  I get the same results as given
...
>  I just want to know what exatly --"LIMIT without ORDER BY returns random
rows
> from the query" --means

I don't think it is actually random.  It just that the order is not defined
and other events may change the order.  I believe that without an ORDER BY
or other clauses that cause an index to be used that the database tends to
return rows in the order stored on disk.  This order tends to be the order
in which rows were added.  My observation is this ordering is faily stable
and it seems to survive a database reload.  Just don't rely on it.  There is
a CLUSTER command to change the physical ordering.



pgsql-sql by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Controlling Reuslts with Limit
Next
From: Jie Liang
Date:
Subject: Re: Controlling Reuslts with Limit