I have a MySQL table with about 10000 entries. I want to represent these entries sorted by name. The page should only show 20 entries at a time.
My question is, is it more efficient to
- Let the database sort it, this means load corresponding 20 entries by using a sorting, limit, select query.
or should one rather
- Sort the list of entries once, save them in an array in a file, load file and only look at the 20 indices of interest.
Both seems terrible to me. I do not want to sort a database with 10000 entries each time a user loads the page just to show 20 entries, nor do I want to load an array with more then 10000 entries to have access to corresponding 20 entries.
Remark: I am not asking is php sort better than mysql "order by"? or database sort vs. programmatic java sort - I want to know if it is better to presort a database, save it in an array and then load the complete sorted array including all entries.