Reputation: 15909
It appears that OFFSET
is not recommended when dealing with large records because of slow performance and instead just use something like WHERE id < x LIMIT y
.
If this is the case why does OFFSET exists, is there another use for it?
Upvotes: 3
Views: 193
Reputation: 1270421
Conceptually, the way that offset
(and limit
for that matter) works is that the entire result set is filtered after it is generated. So, in order to get the the "y"th row, all the rows up that one need to be generated.
If there is another method to get the same rows using where
, then that will normally be faster (for large values of "y"), because the intermediate rows don't have to be generated.
However, offset
is still very useful. How else would you easily get the candidates who are 11+ in average poll ratings from candidates, so you know who to put in the "also-ran" debate? How would you get the second highest value, fi that is what you want? For smaller datasets, offset
can be very useful for these types of questions. It is also useful for paging on smaller result sets.
Upvotes: 2