Databases · Middle · Question 36 of 75
Why is keyset (cursor) pagination faster than OFFSET for deep pages?
SELECT * FROM posts
WHERE (created_at, id) < ($1, $2)
ORDER BY created_at DESC, id DESC
LIMIT 20;- ✓Correct answer: It seeks directly to the position using an index instead of reading and discarding all earlier rows
- 2It caches all pages in memory
- 3It returns fewer columns
Explanation
Include a unique column (like id) as a tiebreaker. The trade-off: no jumping to an arbitrary page number.