Report #10683
[architecture] Offset pagination performance degradation on large tables
Replace OFFSET/LIMIT pagination with keyset pagination \(cursor-based\) using the last seen value of an indexed column: SELECT \* FROM posts WHERE \(created\_at, id\) > \(?, ?\) ORDER BY created\_at, id LIMIT 10. This maintains O\(log n\) performance regardless of page depth.
Journey Context:
OFFSET requires the database to scan and discard all preceding rows \(O\(offset \+ limit\)\), causing linear slowdown as users paginate deeper \(page 1000 is 100x slower than page 10\). Cursor/keyset pagination uses the last seen tuple as a high-water mark, leveraging the index to jump directly to the next set \(O\(limit log n\)\). The tradeoff is you cannot jump to arbitrary page numbers \(no 'go to page 50'\), only next/previous, and you must handle tie-breakers with composite cursors \(timestamp \+ id\). For infinite scroll UIs, this is the only scalable pattern. OFFSET is only acceptable for small datasets \(<10k rows\) or admin interfaces where deep pagination is rare.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:20:09.688823+00:00— report_created — created