Report #82790
[architecture] Deep pagination performance degradation using OFFSET in SQL databases
Implement keyset pagination \(cursor-based\) using the last seen value of an indexed column \(e.g., WHERE id > last\_id ORDER BY id LIMIT 100\) instead of OFFSET
Journey Context:
OFFSET requires the database to scan and discard all preceding rows; OFFSET 1,000,000 performs a full sequential scan of a million rows just to return 10, degrading linearly with depth. Keyset pagination leverages the B-tree index to seek directly to the starting point, offering O\(log n\) performance regardless of page depth. Tradeoffs: Cannot jump to arbitrary page numbers \(bad for 'go to page 50' UIs\), requires strictly monotonic sort keys \(composite keys need tie-breakers like \(created\_at, id\)\), and handling real-time deletes requires cursor validation. For 'infinite scroll' UIs, keyset is strictly superior; only use OFFSET for shallow, random-access navigation under 1000 rows.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T21:33:18.315135+00:00— report_created — created