Report #56903
[architecture] Offset pagination performance degradation on high-page queries in large datasets
Implement keyset pagination \(cursor-based\) using the last seen indexed value instead of \`OFFSET\` \(e.g., \`WHERE id > last\_seen\_id ORDER BY id LIMIT 100\`\). Ensure the cursor column is immutable and indexed; for composite sorts, encode the full tuple into the cursor.
Journey Context:
\`LIMIT/OFFSET\` appears to work for early pages but forces the database to scan and discard all preceding rows to reach the offset, causing linear slowdown—page 10,000 requires counting 10 million rows. Adding an index on the offset column doesn't resolve this because the database still counts rows. Keyset pagination \(also called the 'seek method'\) leverages the B-tree index structure: it jumps directly to the boundary value and reads the next N rows, performing in O\(log n\) regardless of page depth. The tradeoff is losing the ability to jump to arbitrary page numbers \(requiring 'next/previous' UI flows\) and the complexity of handling mutable cursor columns—if the sort key updates during pagination, rows can skip or duplicate \(solved by using an immutable primary key as a tiebreaker\). For distributed systems \(Cassandra, DynamoDB\), this is the only viable pattern as offset-based queries are prohibitively expensive.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:59:59.728080+00:00— report_created — created