Skip to content

refactor(drive): unify indexOnly terminal matching into the dpp index matcher - #4502

Merged
QuantumExplorer merged 1 commit into
feat/index-only-read-completionfrom
feat/index-only-unified-matcher
Aug 28, 2026
Merged

refactor(drive): unify indexOnly terminal matching into the dpp index matcher#4502
QuantumExplorer merged 1 commit into
feat/index-only-read-completionfrom
feat/index-only-unified-matcher

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

First of three stacked architecture PRs on #4499 (see its review discussion): the terminal-clause route shipped with a second, hand-rolled index matcher living in rs-drive beside dpp's index_for_types_matching — "which index serves this query" was answered in two places, and the terminal matcher took the first satisfying index in declaration order instead of scoring candidates.

What was done?

One matching algorithm. Index::matches is extracted into a shared component-list core, and the new Index::matches_including_terminal runs the SAME core with the terminal (an indexOnly index's member-key property) as the index's deepest matchable component — field coverage, the in-position rule and the order-by contiguous-suffix rule all extend naturally. An unused terminal never costs score (it is the entry level itself, always reachable), so scores stay comparable with the generic matcher's and an index is never penalized for merely having a terminal.

Precedence encoded in selection, not in routing. index_for_types_matching_including_terminal returns (index, difference, terminal_used) with the route precedence inside the matcher itself: a candidate covering the query WITHOUT its terminal always beats every terminal-using candidate (the terminal route is a stand-in for "no ordinary index serves this", never a competitor to one that does), and within each class the difference scoring and index-map-order tie-break are exactly the generic matcher's. On any document type without terminals this is exactly index_for_types_matching. Shares the index_for_types version gate — terminal participation can only change outcomes on indexOnly document types, which cannot exist below PV14.

Drive's selection shrinks to shape validation. The candidate loop in index_only_terminal_clause_selection is deleted; it now asks the dpp matcher for the winner and validates clause SHAPE on it — every prefix property equality-bound, non-equality clauses only on the terminal, a terminal range/in requires ordering by it. First-match-in-declaration-order becomes difference-scored best-match (byLiker's exact terminal cover now beats byHashtagPost's costlier one for {$ownerId, postId}, deterministically).

How Has This Been Tested?

New dpp test terminal_aware_matching_prefers_generic_and_scores_candidates pins the three semantics: generic precedence (byPost beats byLiker's terminal cover of the same field), best-match scoring between terminal candidates, and zero-cost unused terminals. All 15 drive indexOnly e2e tests (including every terminal-route and refusal case from #4499), the 699-test drive query suite, 264 dpp index tests and the drive-abci indexOnly pipeline are green; workspace check and clippy -D warnings clean.

Breaking Changes

None on any released surface. Within the unreleased #4499 feature, multi-candidate terminal selection can pick a different (better-scoring) index than declaration order did; selection remains fully deterministic.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

Stack: #4499 → this → clause classification (InternalClauses terminals) → mixed prefix-range + terminal shapes.

🤖 Generated with Claude Code

… matcher

'Which index serves this query' now has one answer site: Index::matches
is extracted into a shared component-list algorithm, and
matches_including_terminal runs the SAME algorithm with the terminal (an
indexOnly index's member-key property) as the deepest matchable
component — coverage, the in-position rule and the order-by suffix all
extend naturally, and an unused terminal never costs score, so results
stay comparable with the generic matcher's.

index_for_types_matching_including_terminal wraps it with the route
precedence encoded in selection itself: a candidate covering the query
WITHOUT its terminal always beats every terminal-using candidate, and
within each class the difference scoring (and index-map-order tie-break)
is exactly the generic matcher's — best-match replaces the drive-side
first-satisfying-index-in-declaration-order loop, which is deleted.
Drive's terminal selection now only validates clause SHAPE on the
matcher's winner (prefix equalities, non-equality placement,
range-needs-orderBy). Shares the index_for_types version gate: terminal
participation can only change outcomes on indexOnly types, which cannot
exist below PV14.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e5b17abc-b6a4-4ce4-a585-a9a1503ad3be

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

ℹ️ Review skipped (commit a0d1b23)
Last checked: 2026-08-28 10:01 UTC

@QuantumExplorer
QuantumExplorer merged commit f251693 into feat/index-only-read-completion Aug 28, 2026
5 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/index-only-unified-matcher branch August 28, 2026 09:57
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.

2 participants