Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you are concerned about performance, you should probably not discard the use of order by too early.</p> <p>Queries like that can be implemende as Top-N query supported by an appropriate index, that's running very fast because it doesn't need to sort the entire table, not even the selecte rows, because the data is already sorted in the index.</p> <p>example:</p> <pre><code>select * from table where A = ? order by creation_date limit 10; </code></pre> <p>without appropriate index it will be slow if you are having lot's of data. However, if you create an index like that:</p> <pre><code>create index test on table (A, creation_date ); </code></pre> <p>The query will be able to start fetching the rows in the correct order, without sorting, and stop when the limit is reached.</p> <p><strong>Recipe</strong>: put the where columns in the index, followed by the order by columns.</p> <p>If there is no where clause, just put the order by into the index. The order by must match the index definition, especially if there are mixed asc/desc orders.</p> <p>The indexed Top-N query is the performance king--make sure to use them.</p> <p>I few links for further reading (all mine):</p> <p><a href="https://stackoverflow.com/questions/3778319/how-to-use-index-efficienty-in-mysql-query/3778542#3778542">How to use index efficienty in mysql query</a></p> <p><a href="http://blog.fatalmind.com/2010/07/30/analytic-top-n-queries/" rel="nofollow noreferrer">http://blog.fatalmind.com/2010/07/30/analytic-top-n-queries/</a> (Oracle centric)</p> <p><a href="http://Use-The-Index-Luke.com/" rel="nofollow noreferrer">http://Use-The-Index-Luke.com/</a> (not yet covering Top-N queries, but that's to come in 2011).</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