Report #12677
[architecture] Slow pagination on large datasets \(OFFSET 100000 LIMIT 20 causing full table scans and latency spikes\)
Implement keyset pagination \(cursor-based\) using the last seen value of an indexed column \(e.g., WHERE id > last\_id ORDER BY id LIMIT 20\) instead of OFFSET; for user-facing 'go to page 57' requirements, use seek method with opaque cursors or hybrid approaches.
Journey Context:
OFFSET is intuitive but requires the database to scan and discard N rows before returning results. As page numbers grow, latency degrades linearly \(O\(n\)\). Teams often add 'LIMIT 10000' caps as band-aids. Keyset pagination leverages indexes to jump directly to the starting position \(O\(log n\)\), remaining constant-time regardless of depth. The tradeoff: you cannot jump to arbitrary page numbers \(no 'page 50 of 100' UI\) and handling sort columns with non-unique values requires composite cursors \(e.g., \(created\_at, id\)\). For UIs requiring random access, use the 'seek method' with base64-encoded cursors containing the sort values, or maintain approximate counts separately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T16:43:02.725016+00:00— report_created — created