Repository navigation
fix(orm): serve multi-field orderBy from a compound index - #426
Merged
Merged
Conversation
Any 2+ field `orderBy` collected the whole table and re-sorted in JS, even when a declared compound index produced that exact order. Two independent bails caused it: `resolveIndexOrderPushdown` refused anything but one spec, and the planner re-decided on `orderSpecs.length` afterwards. Three of five call sites truncated the spec list before the helper ever saw it. The helper now walks the list: eq-pinned fields are absorbed at any position and direction, the rest must be contiguous from the first unpinned key in one shared direction, and `_creationTime` is legal only as the final spec. The planner reads that answer instead of counting specs, and index selection scores how much of the sort a candidate carries. Sorts over a column that can be missing or null keep the post-fetch sort: Convex orders those first ascending and `_compareByOrderSpecs` orders them last, so only sorts the two agree on may move into the index. Also fixes cursor pages ordering the wrong way when an eq-pinned field leads the sort and the next spec points the other way.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
🦋 Changeset detectedLatest commit: 1c1d8e8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…derby-index-pushdown # Conflicts: # packages/kitcn/src/orm/query.ts
Member
|
Autoclosure receipt for exact head
Feedback ledger:
Zero unresolved actionable P1-or-higher feedback remains. |
This was referenced Sep 5, 2026
Closed
This branch was successfully deployed
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.
🐛 Fixes #416
🧭 Task plan: docs/plans/416-orm-multi-field-orderby-index-pushdown.md
🟢 95-100% confidence
bun checkgreen✅ Outcome
A multi-field
orderBywalks a declared compound index only when that index produces the complete requested order without changing tied-row identity. Safe top-level and relation queries stay limit-bound instead of collecting the full candidate set.Mixed directions, nullable fields, skipped keys, unsafe pinned-direction ties, and unrequested trailing index keys keep the post-fetch sort. Add
createdAtin the moving direction when an explicit creation-time tie-break makes a pinned sort safe.🏗️ Design
resolveIndexOrderPushdownowns whole-sort eligibility. Equality-pinned fields are absorbed without consuming a moving key; remaining fields must be contiguous, share one direction, and consume every moving declared key before the implicit creation-time suffix. Candidate scoring prefers fuller indexes only when their extra coverage is safe.🧪 Verified
limit.bun check: green across lint, typecheck, unit/integration suites, CLI and Concave smoke, fixture parity, package builds, and bare/Expo/Next/Start/Vite runtime lanes.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.