Keyset pagination

Keyset (or cursor) pagination loads the next page by filtering on the last key value seen, with WHERE (date, id) < (...) ORDER BY ... LIMIT, instead of OFFSET. It stays fast on large volumes and stable when rows are inserted. It requires a deterministic sort on indexed columns.

Example

SELECT * FROM articles
WHERE (cree_le, id) < ('2025-03-01 10:00', 120)
ORDER BY cree_le DESC, id DESC LIMIT 20;

Related concepts

The whole glossary