Re:Faster offset pagination for Rails apps
by ajsharp on Sunday August 21, 2022 @09:04PM
(#32546141)
A much more complete post covering cursor-based pagination: https://www.moderntreasury.com/journal/shifting-our-apis-pag...
If you're OFFSET-ing, say, 1000 records, I believe the database needs to load those 1000 records in some way, to exclude them from the result set (it's possible mysql does this differently than postgres). With a ranged query and a cursor (e.g. select * from tweets where created_at > CURSOR LIMIT 20) is, generally, more efficient. But cursored range queries don't make sense in a lot of cases and often come with some additional complexity in the code.