Report #65316
[architecture] OFFSET pagination performance degrades exponentially on deep pages
Implement cursor-based \(keyset\) pagination using the last seen value of an indexed column: \`WHERE \(created\_at, id\) > \(last\_created\_at, last\_id\) ORDER BY created\_at, id LIMIT 20\`. This maintains O\(log n\) performance regardless of page depth.
Journey Context:
OFFSET requires the database to scan and discard N rows before returning results, making page 10,000 nearly as expensive as reading 10,000 \* page\_size rows. Cursor pagination leverages index seek operations by remembering the client's position in the sorted dataset. However, it prevents jumping to arbitrary page numbers \(no 'go to page 5'\) and requires deterministic sort order \(tie-breaker ID needed for non-unique timestamps\). It's unsuitable for rankings where rows shift position frequently. The pattern works best for infinite scroll feeds and stable sort APIs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T16:07:05.767833+00:00— report_created — created