Conversation
The keyset pagination clause only matched rows whose sort column compared greater (or less) than the cursor value, plus non-null rows after a null cursor under NullsFirst. It never matched null rows after a non-null cursor, so with NullsLast ordering (or NullsFirst with `before`) every row with a null sort value was unreachable by paging, and hasNextPage reported false early. Add the missing case: the column is null, the cursor value is not, and nulls sort last in the effective direction. The existing "last before w/ complex order" expectation in resolve_connection_pagination_args left out id 12 (reversed 3, title null), which sorts before the cursor [3, "a"] under title AscNullsFirst; it now appears. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
|
Closing as this is 100% AI generated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix.
What is the current behavior?
Keyset pagination never returns rows whose sort column is
nullonce the cursor holds a non-null value, whenever those nulls sort after the cursor. That coversfirst/afterwithAscNullsLastorDescNullsLast, andlast/beforewithAscNullsFirstorDescNullsFirst.hasNextPagealso turnsfalsetoo early, so a client paging through the collection stops before the null rows.Table::to_pagination_clausebuilds, per order column:This handles a null cursor under NullsFirst. The mirror case is missing: the column is null, the cursor is not, and nulls sort last.
Repro (
account(id int primary key, score int), rows(1,10) (2,null) (3,20) (4,null)):{ accountCollection(first: 2, orderBy: [{score: AscNullsLast}]) { pageInfo { hasNextPage endCursor } edges { node { id } } } } # ids 1, 3 · hasNextPage true · endCursor "WzIwLCAzXQ==" ([20, 3]) { accountCollection(first: 2, after: "WzIwLCAzXQ==", orderBy: [{score: AscNullsLast}]) { pageInfo { hasNextPage } edges { node { id } } } } # master: no edges. Expected: ids 2, 4What is the new behavior?
The clause adds
or (col is null and x is not null and <nulls_last>), so rows with null values follow a non-null cursor wherever the effective direction puts nulls last. Pages come back in the same order as the unpaginated query.One existing expectation changes. In
resolve_connection_pagination_args, "Last before w/ complex order" (orderBy: [{reversed: AscNullsLast}, {title: AscNullsFirst}],before: [3, "a"]) left out id 12 (reversed = 3,title = null). Undertitle AscNullsFirst,(3, null)comes before(3, "a"), so id 12 is the row right before the cursor. The last 5 rows before the cursor in forward order are ids 3, 18, 13, 8 and 12, which is what the query now returns.Additional context
test/sql/pagination_cursor_nulls.sqlcovers AscNullsLastafter(plushasNextPage), DescNullsLastafter, AscNullsFirstbefore, and the null-cursor case that already worked.dockerfiles/db/Dockerfiletoolchain (PG 17, pgrx 0.19.2):pagination_cursor_nullsfails. The pages after the cursor are empty andhasNextPageisfalse../bin/installcheckpasses all 123 tests.cargo fmt --checkandcargo clippy --features pg17 -- -D warningsare clean.This PR was prepared with AI assistance (Claude). I reviewed and tested the change as described above.
🤖 Generated with Claude Code