Report #84724
[architecture] OFFSET pagination is slow on large tables and suffers from drift under concurrent writes
Use keyset pagination \(cursor-based\) with a composite index on \(sort\_column, id\): fetch the next page with WHERE \(sort\_column, id\) > \(last\_seen\_value, last\_id\) ORDER BY sort\_column, id LIMIT n.
Journey Context:
OFFSET m LIMIT n requires the database to scan and discard m rows, making latency O\(offset\) which degrades linearly as users paginate deeper \(page 1000 is 100x slower than page 10\). It also suffers from 'drift': if a new row is inserted at position m while the user is paginating, row m\+1 becomes row m\+2, causing the next page to skip a row or return a duplicate. Keyset pagination treats the last row's values as a 'bookmark' \(cursor\), using the index to seek directly to the next set in O\(log n\) time regardless of depth. The composite index on \(sort\_column, id\) handles ties when sort\_column isn't unique. Tradeoffs: you cannot jump to arbitrary page numbers \(no 'go to page 50'\), and sorting by high-cardinality non-indexed columns is expensive.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T00:47:50.580346+00:00— report_created — created