Skip to content

fix(orm): read a wide index union from its probes instead of scanning - #456

Merged
zbeyens merged 8 commits into
mainfrom
fix/wide-index-union-stays-indexed
Sep 7, 2026
Merged

zbeyens merged 8 commits into
mainfrom
fix/wide-index-union-stays-indexed

Conversation

@MikeyZhang75

@MikeyZhang75 MikeyZhang75 commented Sep 6, 2026 •

Copy link
Copy Markdown
Collaborator
  • Auto release

🐛 Fixes #445

🧭 Task plan: docs/plans/445-index-union-bounded-on-pipeline-path.md

🟢 90% confidence

Phase 🧪 Tests 🌐 Browser
Reproduced 🔴 Wide pipeline filter scanned 120 rows for a sparse result ➖ N/A: server read planning
Verified 🟢 1,423 Bun · 1,047 Vitest · 124 CLI · full check 🟢 Local pagination docs

✅ Outcome

Wide indexed filters stay index-bounded through select(), cursor pagination
and additional scalar conditions. Limited residual reads stop after enough
matches when the index supplies the requested order.

⚠️ Caveat

Above 64 ranges, index-ordered pages read the ranges sequentially. Cross-value
sorting still needs maxScan. Pages without orderBy follow index order;
the changeset includes a newest-first paging example.

🏗️ Design

Wide unions concatenate only proven disjoint, ordered leading-field ranges.
Temporal bounds use their stored representation for ordering and overlap
checks. Non-cursor limits use the canonical filtered per-probe reader.

🧪 Verified

  • bun check: passed, including all eight fixtures and verify/runtime.
  • Focused union/pipeline/pagination/filter tests: 132 passed, one skipped.
  • Read-bound tests: 11 passed; compiler/temporal tests: 29 passed.
  • Typecheck, lint and package build passed.
  • Published ORM guidance and generated local copy match; pagination docs render.
  • Independent P0/P1 autoreview: no actionable findings.
  • Installed Intent CLI lacks validate/stale; source mapping,
    discoverability and generated-copy checks passed directly.

Auto release is disabled for this merge.

A compiled index union past MAX_INDEX_UNION_PROBES declined to a full table
scan. Give the executor a second option: concatenate the probe ranges when
they are provably disjoint and ordered on the index's leading field, so the
cap picks merged vs sequential rather than index vs scan.

Also drop the compiler-side cap, which refused to compile a union at all for
an `in` beside another AND term once the list passed 64 values.

Fixes #445
@changeset-bot

changeset-bot Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cf288a2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
kitcn Minor
@kitcn/resend Minor

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

@vercel

vercel Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
better-convex Ready Ready Preview Sep 7, 2026 4:00pm UTC

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c6dd8d244b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/kitcn/src/orm/query.ts Resolved
…opulation

The non-cursor multi-probe branch drops its per-probe bound when a residual
filter is present, then collects every probe before applying it. For a common
probed value that reads most of the table to answer a one-row page.

Read that shape as one ordered union stream instead, so the residual runs in
filterWith while rows are pulled and take() counts matches. 400 reads -> 1 on
the dense case, at every probe width.

Also compare probe bounds in their stored representation when ordering them,
matching what _applyFilterToQuery pushes into the range.

Addresses review feedback on #456.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f34dc171d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 65002eebdc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: afb94ac15d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@zbeyens

zbeyens commented Sep 7, 2026

Copy link
Copy Markdown
Member

P1 closeout receipt for head 1a5aa73dc9dc377492b94192427ae07ea5d47644.

Local HEAD, fetched PR ref and live PR head match. After publishing, 143
query/pipeline/pagination/read-bound tests and 29 compiler tests passed.
The changeset audit passed all six approved-verb public bullets and the
Before/After paging example. Full bun check passed: 1,423 Bun, 1,047 Vitest,
124 CLI, all eight fixtures, verify and runtime. Independent P0/P1 autoreview
passed with no actionable findings.

All five review threads are resolved. Fresh helper inventory: 0 unresolved
threads, 2 comments, 4 review bodies. Unfiltered: 5 resolved threads (3
outdated), 13 inline comments, 3 top-level comments, 12 review bodies. All
pages exhausted. Zero actionable P0/P1; no deferred P2.

Source-backed dispositions and read-back replies:

Other initial feedback URLs are in the dedicated task-plan ledger. New
non-actionable items read in full:

Hosted pagination docs rendered successfully. Vercel deployment
dpl_Hev5UXAXL3KkfxHZXXG8pGmo8w72 is READY and identifies this exact commit.
Auto release is off. This receipt does not claim merge; versioned closeout
records and final-head CI remain to finish. Any further push requires another
proof replay and superseding external receipt before merge.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@zbeyens

zbeyens commented Sep 7, 2026

Copy link
Copy Markdown
Member

P1 closeout receipt — final head cf288a2f6eba0f1ba2a745197344c95c82325875.

  • Both task-plan checkers pass. All versioned source and plan updates are
    pushed. Local HEAD, fetched PR ref and live PR head match this OID.
  • After the final push, 143 query/pipeline/pagination/read-bound tests and 29
    compiler tests passed. The resolved residual-read P1 remains covered at
    widths 64/65 on 400 common-status rows, with global top-k, RLS and relation
    fan-out checks. All three resolved/outdated changeset P1s passed the final
    artifact audit: six approved-verb public outcomes, no private executor
    narrative, and the preserved Before/After orderBy/maxScan example.
  • Full bun check passed: 1,423 Bun tests, 1,047 Vitest tests, 124 CLI tests,
    typecheck, all eight fixtures, verify and runtime. Independent P0/P1
    autoreview passed with no actionable findings. Only versioned plan evidence
    changed after that proof; source, docs and tests are unchanged.
  • Fresh helper inventory: 0 unresolved threads, 4 comments, 4 review bodies.
    Unfiltered: 5 resolved threads (3 outdated), 13 inline comments, 5 top-level
    comments, 12 review bodies. All pages exhausted. Raw thread/review snapshots
    match the verified first receipt. Zero actionable P0/P1; no deferred P2.
  • Every feedback URL and verdict is in the dedicated task-plan ledger except
    this new notice, read in full:
    fix(orm): read a wide index union from its probes instead of scanning #456 (comment) — hosted
    review quota only, not a source finding; independent review already passed.
    The earlier receipt at
    fix(orm): read a wide index union from its probes instead of scanning #456 (comment) is superseded.
  • Local and hosted pagination docs rendered the wide-union index-order and
    scan-budget constraints. Final-head CI and Vercel checks remain the merge
    gate; no merge or release is claimed by this receipt.

Auto release is off. Merge requires this exact receipt/live/fetched/local OID
match, a post-receipt full helper/raw inventory with no unledgered finding,
and successful final-head CI/Preview checks. No branch push is needed to
record this external receipt.

@zbeyens
zbeyens merged commit 5b0bd5a into main Sep 7, 2026
6 checks passed

This branch was successfully deployed

1 active deployment
Preview — cf288a2f Deployed Sep 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ORM: declined index-union on the non-cursor select() path anchors no index, with no guard and no available bound

2 participants