Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It doesn't make sense to implement paging using LIMIT without an ORDER BY.</p> <p>Yes, you're right that it's faster without the ORDER BY, because the server is free to return arbitrary results in any order and the results don't have to be consistent from one query to the next.</p> <p>If you want correct and consistent results, you <em>must</em> have the ORDER BY. If you are concerned about performance consider adding on index for the column you are ordering by.</p> <p>From the manual page <a href="http://dev.mysql.com/doc/refman/5.6/en/limit-optimization.html" rel="nofollow"><code>LIMIT optimization</code></a>:</p> <blockquote> <p>If you use LIMIT row_count with ORDER BY, MySQL ends the sorting as soon as it has found the first row_count rows of the sorted result, rather than sorting the entire result. If ordering is done by using an index, this is very fast. </p> </blockquote> <hr> <blockquote> <p>The reason for paginating the query is because I don't like to lock the tables for longer periods at a time. Does anyone have a insight how to achieve this and at the same time get all the data?</p> </blockquote> <p>If you're trying to perform some operation on every row then your approach won't work if data can be added or removed. This is because it will push all the following rows and some rows will be moved onto different pages. Adding a row will push some rows onto the next page, meaning that you see one row twice. Removing a row from an earlier page will cause you to skip a row.</p> <p>Instead you could use one of these approaches:</p> <ul> <li>Use some <code>id</code> to keep track of how far you have progressed. Select the next n rows with higher <code>id</code>. </li> <li>Record which rows you have handled by storing a boolean in a column. Select any n rows that you haven't handled yet.</li> </ul>
    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.
 

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