14.6 Keyset Pagination: The Scalable Alternative to OFFSET
Right, let’s talk about pagination. You’ve probably done the OFFSET 100 LIMIT 10 dance a thousand times. It’s the default. It’s also a performance nightmare waiting to happen, and I’m going to show you exactly why. The problem with OFFSET is that it’s a dumb skip. The database has to read the first 100 rows, count them, and then throw them away to give you the 10 you actually want. It’s like asking a librarian to count out the first 100 books in the library, then hand you the 101st. It gets slower and more expensive the deeper you paginate. It’s absurd.