Report #7279
[architecture] Database queries slow down dramatically when paginating deep into large datasets using LIMIT/OFFSET
Implement keyset pagination \(cursor-based\) using the last seen column values \(e.g., WHERE \(created\_at, id\) > \($last\_ts, $last\_id\)\) with a composite index on the sort columns, instead of using OFFSET.
Journey Context:
OFFSET seems simple but requires the database to scan and discard all preceding rows \(O\(n\) cost\). At page 10,000, you're scanning millions of rows just to return 20. Keyset pagination has O\(log n\) cost because it uses the index to jump directly to the starting point. The tradeoff is you cannot jump to arbitrary page numbers \(no 'go to page 50'\) and you must handle tie-breakers \(composite keys\) to avoid missing rows with duplicate sort values. It's the only viable pattern for high-scale feeds and APIs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T02:16:23.055774+00:00— report_created — created