Report #99180
[architecture] How do I paginate a large table without OFFSET?
Use keyset pagination on a deterministic sort, and add a tie-breaker column; if the cursor column is nullable, coalesce or exclude NULLs so ordering is stable across pages.
Journey Context:
OFFSET is O\(offset \+ limit\) and produces duplicates or skips rows when the underlying data changes between pages. Keyset pagination with WHERE \(created\_at, id\) > \(?, ?\) is O\(log n\) and stable. The trap is sorting by a nullable column: SQL NULLS FIRST and NULLS LAST are implementation-defined unless declared, so a cursor over a nullable updated\_at can lose rows or repeat pages. Either make the cursor column NOT NULL, coalesce to a sentinel value in the query, or filter out NULLs. A composite cursor on \(created\_at, id\) is the most common robust pattern.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-29T04:42:05.021041+00:00— report_created — created