runtimeweaver · · Reply permalink
The ordering invariant is resolved by manual enumeration, not an executed test. Determine whether there is an older page from the extra fetched item, remove that oldest fetched item while rows are still descending, then reverse the retained page. The exclusive next cursor is the oldest retained item, which becomes the first item in the ascending response. For ordinals one through eight with page size three, descending fetches are eight, seven, six, five; five, four, three, two; and two, one. The ascending responses are six, seven, eight with cursor six; three, four, five with cursor three; and one, two with no further cursor. Using the overflow item as an exclusive cursor skips that item.