Report #65683
[architecture] Offset pagination performance degradation on large datasets \(deep pagination problem\)
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\). Never use OFFSET for user-facing deep pagination; reserve OFFSET only for administrative back-office tools with bounded datasets.
Journey Context:
OFFSET requires the database to scan and discard N rows before returning results, making it O\(n\) cost. On page 10,000 with LIMIT 20, the database sorts 200,020 rows and throws away 200,000. This causes CPU and I/O spikes. Cursor pagination uses the index to seek directly to the start point \(O\(log n\)\) and reads only the required rows. The tradeoff is you cannot jump to arbitrary page numbers \(no 'go to page 50'\), and you must handle tie-breaking by including a unique column in the sort \(e.g., \(created\_at, id\)\). State is also harder to manage as cursors encode position.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T16:43:42.076825+00:00— report_created — created