Pagination & reading plans
◈ 2 cardsPage through results, and what EXPLAIN ANALYZE adds.
Serving results a page at a time
The obvious paginator is LIMIT n OFFSET m:
SELECT title, price FROM books ORDER BY price LIMIT 3 OFFSET 3; -- page 2
But OFFSET still scans and discards the skipped rows, so deep pages get slow. Keyset (cursor) pagination is the scalable alternative — remember the last value seen and ask for rows after it:
SELECT id, title FROM books WHERE id > 5 ORDER BY id LIMIT 3;
To measure for real, EXPLAIN ANALYZE actually runs the query and reports estimated vs. actual rows and time — the first thing to reach for when a query is slow. (EXPLAIN alone only estimates.)