Suppose there are 1,000,000 entries in a table. I need to find the record 999,999.
Will ORDER BY affect the sampling rate?
At work, they tell me that with ORDER BY ASC request will have to process the lines from 0 to 999,999, and if DESC , then only from 1,000,000 to 999,999, that is, one line.
|
1 answer
The sorting direction does not affect anything. There is no difference: take numbers from the end or from the beginning. But if you do a LIMIT 125551, 10 selection, and if there are additional conditions (or as you do not have indices), mysql will select and sort 125551 rows and select the latter from them.
With regards to the lack of indexes, it’s not a fact that they were not cached, even if they are not there.
|
SELECT * FROM ChatMessages ORDER BY text ASC LIMIT 125551, 10runs for 650-800ms, and theSELECT * FROM ChatMessages ORDER BY text DESC LIMIT 0, 10for 150-190ms. Indices in both queries are not used. - Regent