Report #7823
[architecture] Pagination becomes slow on large tables when using LIMIT/OFFSET
Implement keyset pagination \(cursor-based\) using the last seen value of an indexed column \(e.g., WHERE id > last\_id ORDER BY id LIMIT 100\) instead of OFFSET. For complex sort orders, encode the tuple \(sort\_column, id\) as the cursor.
Journey Context:
OFFSET-based pagination requires the database to scan and discard all preceding rows, causing linear slowdown as page number increases \(O\(n\) cost\). Developers often don't notice this until tables reach millions of rows. Keyset pagination has O\(log n\) cost using index seeks, but requires a strictly sortable column \(usually primary key\) and cannot jump to arbitrary page numbers \(only next/previous\). The 'seek method' or 'cursor pagination' pattern requires encoding the last seen values into a cursor token \(base64 encoded JSON or similar\). Common pitfall: using UUIDs as cursors without proper ordering \(UUIDv4 is random; use ULIDs or time-based UUIDv7 for cursor friendliness\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T03:47:26.637985+00:00— report_created — created