Report #53077
[architecture] Offset pagination performance degradation and row skipping on high-velocity tables
Implement keyset pagination \(cursor-based\) using the last seen values of the indexed sort columns as the 'cursor', with a WHERE clause like \(created\_at, id\) > \(last\_created\_at, last\_id\) and ORDER BY created\_at ASC, id ASC; always include a primary key tie-breaker to handle non-unique sort values.
Journey Context:
OFFSET/LIMIT requires the database to scan and discard all prior rows, causing linear slowdown as page number increases \(O\(n\) cost per page\) and inconsistent results if new rows are inserted during pagination \(row skipping/duplication\). Keyset pagination uses index seeks \(O\(log n\)\) regardless of page depth. The critical mistake is omitting a tie-breaker: sorting by created\_at alone is non-unique, causing missing or duplicate rows when multiple records share the same timestamp. The composite cursor \(timestamp, id\) guarantees deterministic ordering. Note that jumping to arbitrary pages \(e.g., page 47 of 100\) requires maintaining a mapping or using hybrid approaches, as cursor pagination is inherently sequential. This pattern also enables efficient 'infinite scroll' without count queries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:35:15.690908+00:00— report_created — created