Report #5601
[architecture] OFFSET pagination performance degradation and skipped rows on high-churn datasets
Implement keyset pagination \(cursor-based\) using the last seen values of indexed columns with a WHERE \(sort\_col, id\) > \(?, ?\) clause
Journey Context:
OFFSET requires the database to scan and discard N rows before returning results, creating O\(offset\) complexity that causes linear slowdown as users paginate deep \(page 10000\). Additionally, concurrent insertions/deletions cause item duplication or skipping across pages when using OFFSET/LIMIT. Keyset pagination stores the last seen values \(e.g., last\_timestamp, last\_id\) and uses WHERE \(timestamp, id\) > \(?, ?\) with a composite index. This is O\(1\) regardless of depth and immune to churn-induced skipping. Tradeoffs: Cannot jump to arbitrary page numbers \(no "go to page 50"\), requires a strictly unique ordering column \(or composite tie-breaker like id\), and cursors must be opaque \(base64-encoded\) to prevent API consumers from constructing arbitrary queries. Null handling in sort columns requires COALESCE to sentinel values. Essential for infinite scroll feeds and high-volume APIs where OFFSET would scan millions of rows.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:44:02.123223+00:00— report_created — created