keyset pagination

Paging by remembering the last key the reader saw and asking for rows after it, which does not drift.

In more detail

The next page is WHERE id > last_seen_id ORDER BY id LIMIT n. New rows cannot shift it, and an index on the key lets the database jump straight to the right place however deep the page.

Example

SELECT id, name FROM products WHERE id > 3 ORDER BY id LIMIT 3;

Related terms

Taught in

References