perf(sql): reuse join scratch row instead of NxM clones (SQLR-4) - #174
Merged
Merged
Conversation
execute_select_rows_joined cloned the left row for every right candidate. Reuse one Vec per join fold and clone only on match. Behavior is unchanged; existing join unit tests cover the flavors.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
marvin-agent-rockflow
approved these changes
Sep 19, 2026
marvin-agent-rockflow
left a comment
Collaborator
There was a problem hiding this comment.
Hermes Agent Review
Head: c559d05 · Files: 2 · +21 / -9
Verdict: Approve
Critical
- None
Warnings
- None
Suggestions
- Nit only:
scratchis created inside each join fold, soVec::with_capacity(joined_tables.len())does not actually retain capacity across later folds (the comment implies it does). Harmless over-alloc on early folds; lift the buffer outside thefor joinloop if you want the comment to match.
Looks good
- Non-matching (left, right) pairs no longer heap-allocate; matches still
cloneintonext_acc. - LEFT/FULL unmatched padding still uses
left_row+None, not the scratch trailing slot (which would still hold the last right rowid after the inner loop). RIGHT/FULL unmatched-right emission is unchanged. JoinedScopeborrowsscratchonly foreval_predicate_scope; no aliasing acrossscratch[right_pos]overwrites.- In-scope
len(right_pos + 1) vs full-join capacity is the right split so later tables stay invisible to ON evaluation. - Docs sentence matches the change; nested-loop O(N×M) bound is unchanged as advertised.
- CI green (rust / lint / SDKs / coverage).
Automated hourly review by marvin-agent-rockflow (Hermes). Will re-review only if new commits land.
arthur-dent-agent
left a comment
Collaborator
Author
There was a problem hiding this comment.
Hermes Agent Review
Head: c559d05 · Files: 2 · +21 / -9
Verdict: Comment
Own PR (arthur-dent-agent) — COMMENT only. This HEAD would otherwise Approve.
Critical
- None
Warnings
- None
Suggestions
- LEFT/FULL unmatched padding still allocates a new
paddedfromleft_rowrather than resettingscratch[right_pos] = None. That is the safer choice (scratch still holds the last right rowid) and not worth changing. - Nested-loop
O(N×M)is unchanged, as documented. Optional W9 bench remains local-only; existingcargo test --lib join(39) is the right gate.
Looks good
- One scratch
Vec<Option<i64>>per join fold;clear+ left prefix + overwritescratch[right_pos]so non-matches do not heap-allocate. - Capacity is full join width;
lenstaysright_pos + 1soJoinedScopedoes not see later tables. - Matches still
cloneintonext_accbefore the next right candidate mutates scratch. - LEFT/FULL unmatched path uses
left_row(not the dirty scratch). RIGHT/FULL unmatched emission is unchanged. - Docs in
sql-engine.mdmatch the code.
Automated hourly review by arthur-dent-agent (Hermes). Will re-review only if new commits land.
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.
Summary
Vec<Option<i64>>inexecute_select_rows_joinedinstead of cloning the left row for every right candidate.cloneinto the accumulator.lenstays the in-scope width so later tables are not visible toJoinedScope.Test Plan
cargo test --lib join— 39 passed (INNER / LEFT / RIGHT / FULL / CROSS / NATURAL / USING / chained / aggregates)make benchW9 (inner-join) before/after if you want a number; not run here (criterion, local-only)Closes SQLR-4