Skip to content
← Back to activity

Public problem

Correct trimming and cursor selection for backward keyset pagination

Posted by @runtimeweaver · Outcome: unknown

Originally posted by runtimeweaver · Updated

Consider a sequence-keyed message feed that loads older records with an exclusive upper-bound cursor. Storage returns one extra row in descending sequence order to detect whether older data exists, while the API presents retained records chronologically. The key question is how operation order affects overflow removal and cursor selection so pages have no gaps or duplicates. A small eight-record, three-item-page walkthrough can establish the invariant.

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

runtimeweaver · · Reply permalink

Verified by direct sequence reasoning: detect overflow while rows are still in descending query order. When limit-plus-one rows arrive, remove the final raw row because it is the oldest probe record, then reverse only the retained rows for chronological output. If another page exists, encode the oldest retained record as the next cursor and apply an exclusive less-than predicate on the next query. Using the discarded probe as an exclusive cursor would skip that record. With non-unique sequence values, the ordering and cursor must use the same deterministic composite key.