MySQL Forums :: Performance :: order by primary key slowly


Advanced Search

Re: order by primary key slowly
Posted by: Rick James ()
Date: April 12, 2016 07:42PM

Maybe the real answer is "Don't do that!".

Why are you using huge offsets? Are you walking through the table? Is a human doing such? I doubt it. It would be painfully tedious to press the Next button 100000 times.

A better way is to "remember where you left off". See my blog on such: http://mysql.rjweb.org/doc.php/pagination

Back to the question and replies...
* Neither query sorts. The one using the 'type' index has no ORDER BY; the one by 'id' takes advantage of the table being ordered by 'id'.
* When using LIMIT, EXPLAIN often lies in the 'Rows' and 'Filter' columns.
* Did you "time" your queries twice? The first time may be slow because of I/O; the second may be faster because of caching. Use the second.
* Add SQL_NO_CACHE (or turn off the Query cache) so that the QC does not give you a time of "0.00 seconds".

Options: ReplyQuote


Subject Views Written By Posted
order by primary key slowly 903 varky chan 04/05/2016 10:42PM
Re: order by primary key slowly 403 Øystein Grøvlen 04/06/2016 04:35AM
Re: order by primary key slowly 442 varky chan 04/06/2016 10:15AM
Re: order by primary key slowly 416 Peter Brawley 04/06/2016 11:23AM
Re: order by primary key slowly 489 varky chan 04/06/2016 08:11PM
Re: order by primary key slowly 383 Peter Brawley 04/06/2016 10:35PM
Re: order by primary key slowly 394 varky chan 04/07/2016 12:34AM
Re: order by primary key slowly 428 Øystein Grøvlen 04/07/2016 07:21AM
Re: order by primary key slowly 412 Peter Brawley 04/07/2016 10:20AM
Re: order by primary key slowly 393 varky chan 04/07/2016 11:26PM
Re: order by primary key slowly 378 Rick James 04/12/2016 07:42PM
Re: order by primary key slowly 395 Peter Brawley 04/06/2016 08:57AM
Re: order by primary key slowly 387 varky chan 04/06/2016 10:17AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.