Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No, that behavior cannot be relied on. The order is determined by the way the query planner has decided to build up the result set. simple queries like <code>select * from foo_table</code> are likely to be returned in the order they are stored on disk, which may be in primary key order or the order they were created, or some other random order. more complex queries, such as <code>select * from foo where bar &lt; 10</code> may instead be returned in order of a different column, based on an index read, or by the table order, for a table scan. even more elaborate queries, with multipe <code>where</code> conditions, <code>group by</code> clauses, <code>union</code>s, will be in whatever order the planner decides is most efficient to generate.</p> <p>The order could even change between two identical queries just because of data that has changed between those queries. a "where" clause may be satisfied with an index scan in one query, but later inserts could make that condition less selective, and the planner could decide to perform a subsequent query using a table scan.</p> <hr> <p>To put a finer point on it. RDBMS systems have the mandate to give you <em>exactly</em> what you asked for, as efficiently as possible. That efficiency can take many forms, including minimizing IO (both to disk as well as over the network to send data to you), minimizing CPU and keeping the size of its working set small (using methods that require minimal temporary storage).</p> <p>without an <code>ORDER BY</code> clause, you will have not asked <em>exactly</em> for a particular order, and so the RDBMS will give you those rows in some order that (maybe) corresponds with some coincidental aspect of the query, based on whichever algorithm the RDBMS expects to produce the data the fastest.</p> <p>If you care about efficiency, but not order, skip the <code>ORDER BY</code> clause. If you care about the order but not efficiency, use the <code>ORDER BY</code> clause.</p> <p>Since you actually care about <em>BOTH</em> use <code>ORDER BY</code> and then carefully tune your query and database so that it is efficient.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload