feat(query): omitted order_by nulls= means last - #397
Merged
Conversation
Omitted nulls= compiles to last on every backend; native is the explicit dialect-default escape. QueryIR bumps to v12 with required nulls on every order_by term. Closes #392 Co-authored-by: Cursor <cursoragent@cursor.com>
Future-reject test now uses ir_version 13; add v11 stale-envelope reject. Repair broken IR vectors README paragraph. Co-authored-by: Cursor <cursoragent@cursor.com>
3 tasks
0x054
added a commit
that referenced
this pull request
Aug 30, 2026
## Summary Keyset `after()` / `before()` derived from a query's `order_by`, NULL-placement aware (ADR-0018). A position is the ordered tuple of order-key values; `position_of(row)` reads it; `after(row)` / `before(row)` are sugar. Cursor encoding stays the caller's. - Omitted `nulls=` is `"last"` on every dialect (ADR-0017 — **breaking** vs native PG DESC / SQLite ASC). `"native"` is the explicit escape. - `after(position)` pages forward (exclusive). `None` is legal in every non-PK slot so a pinned-first list can cross into unpinned rows in one query. - `before(position).limit(n)` is the adjacent previous page in declared order; unbounded `before()` is the earlier-row prefix (`first()` and `all()[0]` disagree — documented). - Traversed order keys and projected records page from a tuple (`include()` not required). `position_of` still requires populated relations / selected keys. QueryIR is v14. One Rust expander (`exclusive_stepwise_compare`) owns the compare tree; `before` inverts keys then reuses it. ## Test plan - [x] Slice CI on `feat/position-paging`: #397–#403 (rust, python PR, sqlite+postgres matrix) - [ ] Confirm CI on this PR against `main` - [ ] Smoke: `order_by(pinned_at, "desc").order_by(id).after((None, id))` and `before(pos).limit(n)` Closes #372 Made with [Cursor](https://cursor.com) --------- Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
nulls=onorder_bynow compiles tolaston every backend (breaking change: Postgres DESC and SQLite ASC no longer use dialect defaults).nulls="native"restores plain ASC/DESC per dialect.order_byterm carries requirednulls(first|last|native); missing key fails at decode.Breaking change
nulls=)Use
nulls="native"when you want the old dialect-default behavior.Test plan
pytest tests/test_order_by_nulls.py— omittednulls=cross-asserted as last on SQLitepytest tests/test_order_by_nulls_wire.py— v12 wire, every term hasnulls,nativetokenpytest tests/test_query_wire_vectors.py— golden vectors at ir_version 12pytest tests/test_ir_vectors_contract.py— contract requiresnullson every order_by termcargo test -p ferro-schema-ir query_order_by query_card_nulls— required nulls decode/roundtrippytest tests/test_query_column_validation.py— builder acceptsnative, omitted →lastCloses #392
Made with Cursor