Repository navigation
perf: unstable sorts for unique query metadata (#795) - #799
Merged
Merged
Conversation
Prepared slot names and an `or`'s branch variables come from a set or a map's keys, so they are unique. Every variable in the planner's slot map has its own slot, so a subplan's imports tie only when a join variable is named twice, and those entries are identical. Sorting all three with `sort_unstable` keeps order and plans unchanged and drops the stable sort's merge code. Release sizes on v3 (rustc 1.99.1): native CLI 1,263,592 -> 1,262,584 (-1,008), WASI 879,785 -> 878,033 (-1,752), browser lib 1,525,738 -> 1,523,852 (-1,886). Prepare/plan micro-benchmark unchanged within noise. Adds a test that a repeated join variable in `not-join`/`or-join` answers as the same clause naming it once, under every body form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01H2a7Qo5yfvBEjzSuUoB2n9
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Part of #795 (follow-up to the #772 audit, #798).
Change
sort→sort_unstableat the three sites the audit found:prepared.rs::collect_slot_names— names drained from aHashSet: unique.plan.rs::Builder::union— a branch's own variables fromby_varkeys: unique.plan.rs::Builder::sub— imports(name, slot)sorted by slot.Import-slot invariant. Every
Slots::by_varinsertion inplan.rs(7 sites) uses a slot fresh fromSlots::add, so distinct names never share a slot. Equal keys therefore mean the same variable named twice ((not-join [?x ?x] …)), whose entries are identical: tie order cannot change the plan or results. Comment added at the sort. Optimizer cost/selectivity sorts and legacy replay sorts are untouched.Tests
New
repeated_join_variable_matches_single(engine/tests.rs): repeated join variables innot-joinandor-joinanswer exactly as the same clause naming each once, under the chosen, hashed and correlated body forms. Fullcargo testpasses; MSRV 1.89check --all-targetspasses; clippy findings identical to base.Measurements (v3
8c6c4a1ac, rustc 1.99.1, release)--libSavings are additive here. Prepare + plan + execute micro-benchmark (3 slots,
or-join,not-join; ad-hocor+not-joinquery), base and candidate on separate sockets, swapped over 4 rounds: prepared 77,352 → 77,467 ns (+0.15%), ad-hoc 73,950 → 73,550 ns (−0.5%), i.e. within noise.No public API, format, size cap or coverage floor change. CHANGELOG, TEST_COVERAGE and CLAUDE.md test counts updated; no docs-site change (no syntax or architecture change).
🤖 Generated with Claude Code
https://claude.ai/code/session_01H2a7Qo5yfvBEjzSuUoB2n9