Repository navigation
Normalize IJoin::addBlockToJoin to one signature with num_rows and a JoinBuildContext - #120002
Conversation
|
Workflow [PR], commit [7404447] Summary: ✅
AI ReviewSummaryThis PR is a mechanical refactor that collapses Final Verdict
LLVM Coverage ReportMeasured on commit 7404447.
Changed lines: Changed C/C++ lines covered: 193/214 (90.19%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes40 object files changed (+86.15 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units173 translation units recompiled, 1837 s compile time in total, 173 of them have a recent master baseline. |
|
📊 Cloud Performance Report
This PR refactors the join build interface: addBlockToJoin now takes a row count and a JoinBuildContext, and requestSpill now takes a JoinBuildContext. It also adds getMaxBuildThreads, which defaults to 0 and leaves the parallel build stream count unchanged. None of the three flagged ClickBench queries (Q18 at -10.2%, Q33 at -11.9%, Q34 at -12.9%) contain a JOIN, so the changed code can't affect them. All three are on the list of queries whose master baseline shifted mid-window, and Q18's measurements were noisy with the two tests disagreeing. They stay not_sure with no attribution to this PR, and tpch_adapted_1_official, the benchmark that does run joins, flagged nothing. clickbenchFlagged queries (3 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
…rker_id` build signature The base now carries one `HashJoin` for both layouts (#115605) and the `addBlockToJoin(block, num_rows, worker_id, check_limits)` signature of #120002, so the partitioned join drops its own `build_lane` overload: the build worker id indexes the fill lanes, and an id past the lane table takes the thread-keyed lane as before. The inner `HashJoin` is created with one worker and the serial layout; the stored blocks and null maps live in that worker's lists, and the byte counters go through `RightTableData::addBytes`. Key getters take the `use_offset` argument: false for the build inserts, `need_flags` for the probe. The gtest feeds blocks through the `IJoin` signature.
Follow-up of the retro three-skill pass (`reduce-complexity`, `humanize`, `plain-prose`) over PR #120002. Only comment lines in `IJoin.h` change; behaviour and every signature stay the same. The parameter paragraphs of `addBlockToJoin` now use one idea per sentence. `PREWHERE` and `CROSS JOIN` are written as SQL names. The four blank `///` separator lines are gone, because the file does not use them elsewhere. The `getMaxBuildThreads` comment is split at its semicolon. Every fact of the old text is kept. `reduce-complexity` found no structural change to make: the layer above (PR #115605) reads `worker_id` and `getMaxBuildThreads`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
101485e to
15da2f0
Compare
Follow-up of the retro three-skill pass (`reduce-complexity`, `humanize`, `plain-prose`) over PR #120002. Only comment lines in `IJoin.h` change; behaviour and every signature stay the same. The parameter paragraphs of `addBlockToJoin` now use one idea per sentence. `PREWHERE` and `CROSS JOIN` are written as SQL names. The four blank `///` separator lines are gone, because the file does not use them elsewhere. The `getMaxBuildThreads` comment is split at its semicolon. Every fact of the old text is kept. `reduce-complexity` found no structural change to make: the layer above (PR #115605) reads `worker_id` and `getMaxBuildThreads`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
c8878c6 to
5fffcd9
Compare
Follow-up of the retro three-skill pass (`reduce-complexity`, `humanize`, `plain-prose`) over PR #120002. Only comment lines in `IJoin.h` change; behaviour and every signature stay the same. The parameter paragraphs of `addBlockToJoin` now use one idea per sentence. `PREWHERE` and `CROSS JOIN` are written as SQL names. The four blank `///` separator lines are gone, because the file does not use them elsewhere. The `getMaxBuildThreads` comment is split at its semicolon. Every fact of the old text is kept. `reduce-complexity` found no structural change to make: the layer above (PR #115605) reads `worker_id` and `getMaxBuildThreads`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
5fffcd9 to
8abba29
Compare
5b6af6e to
47c1a80
Compare
Follow-up of the retro three-skill pass (`reduce-complexity`, `humanize`, `plain-prose`) over PR ClickHouse#120002. Only comment lines in `IJoin.h` change; behaviour and every signature stay the same. The parameter paragraphs of `addBlockToJoin` now use one idea per sentence. `PREWHERE` and `CROSS JOIN` are written as SQL names. The four blank `///` separator lines are gone, because the file does not use them elsewhere. The `getMaxBuildThreads` comment is split at its semicolon. Every fact of the old text is kept. `reduce-complexity` found no structural change to make: the layer above (PR ClickHouse#115605) reads `worker_id` and `getMaxBuildThreads`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
IJoin::addBlockToJoin to one signature with num_rows and worker_idIJoin::addBlockToJoin to one signature with num_rows and a JoinBuildContext
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
Unifies IJoin::addBlockToJoin into a single virtual API that always receives an explicit row count and a build-stream context, enabling future parallel join build with per-stream state and consistent limit-check semantics.
Changes:
- Replaces the two
addBlockToJoinoverloads withaddBlockToJoin(block, num_rows, JoinBuildContext)and threads this through join implementations and callers. - Introduces
JoinBuildContext/JoinBuildStreamKeyplusIJoin::getMaxBuildThreads()to support capped parallel build stream assignment. - Updates build-side pipeline wiring (
FillingRightJoinSideTransform,QueryPipelineBuilder,StorageJoin) and adjusts tests accordingly.
| File | Description |
|---|---|
| src/Interpreters/IJoin.h | Introduces JoinBuildContext, JoinBuildStreamKey, new addBlockToJoin signature, getMaxBuildThreads(), and contextual requestSpill. |
| src/Interpreters/IJoin.cpp | Implements JoinBuildContext::forStream validation and error reporting. |
| src/QueryPipeline/QueryPipelineBuilder.cpp | Caps right-side build streams via getMaxBuildThreads() and assigns per-stream JoinBuildContext. |
| src/Processors/Transforms/JoiningTransform.h | Extends FillingRightJoinSideTransform ctor to accept/store JoinBuildContext. |
| src/Processors/Transforms/JoiningTransform.cpp | Passes JoinBuildContext through to addBlockToJoin and requestSpill. |
| src/Storages/StorageJoin.cpp | Updates JOIN-engine mutation/insert paths to call the new addBlockToJoin signature with serial() context. |
| src/Interpreters/HashJoin/HashJoin.h | Updates HashJoin to the unified addBlockToJoin signature. |
| src/Interpreters/HashJoin/HashJoin.cpp | Routes limit checking through context.joinChecksLimits() in HashJoin::addBlockToJoin. |
| src/Interpreters/ConcurrentHashJoin.h | Updates ConcurrentHashJoin to the unified addBlockToJoin signature. |
| src/Interpreters/ConcurrentHashJoin.cpp | Routes limit checking through context.joinChecksLimits() in parallel build. |
| src/Interpreters/GraceHashJoin.h | Updates GraceHashJoin build/spill APIs to accept JoinBuildContext. |
| src/Interpreters/GraceHashJoin.cpp | Threads JoinBuildContext through repartition/spill/add paths and limit checks. |
| src/Interpreters/SpillingHashJoin.h | Updates build/spill/conversion helpers to accept JoinBuildContext. |
| src/Interpreters/SpillingHashJoin.cpp | Threads JoinBuildContext through spill-triggered switching and block draining. |
| src/Interpreters/JoinSwitcher.h | Updates JoinSwitcher add/switch APIs to accept JoinBuildContext/num_rows. |
| src/Interpreters/JoinSwitcher.cpp | Forwards num_rows and JoinBuildContext through switching and replay paths. |
| src/Interpreters/ConstantJoin.h | Collapses overloads into the unified addBlockToJoin signature. |
| src/Interpreters/ConstantJoin.cpp | Uses num_rows directly and consults context.joinChecksLimits(). |
| src/Interpreters/MergeJoin.h | Updates MergeJoin to the unified addBlockToJoin signature. |
| src/Interpreters/MergeJoin.cpp | Updates MergeJoin::addBlockToJoin signature (ignoring new args). |
| src/Interpreters/PasteJoin.h | Updates PasteJoin signature to match new pure virtual method. |
| src/Interpreters/FullSortingMergeJoin.h | Updates FullSortingMergeJoin signature to match new pure virtual method. |
| src/Interpreters/DirectJoin.h | Updates DirectKeyValueJoin signature to match new pure virtual method. |
| src/Interpreters/DirectJoin.cpp | Updates DirectKeyValueJoin::addBlockToJoin signature (still throws). |
| src/Processors/tests/gtest_merge_join_starved_totals.cpp | Adjusts test to construct FillingRightJoinSideTransform with JoinBuildContext::serial(). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| bool HashJoin::addBlockToJoin(const Block & source_block, size_t /* num_rows */, JoinBuildContext context) | ||
| { | ||
| /// `materializeColumnsFromRightBlock` dereferences `data`, so the identical check in the | ||
| /// overload below is reached too late to guard it. | ||
| if (!data) | ||
| throw Exception(ErrorCodes::LOGICAL_ERROR, "Join data was released"); | ||
|
|
||
| auto materialized = materializeColumnsFromRightBlock(source_block); | ||
| return addBlockToJoin(materialized, ScatteredBlock::Selector(materialized.rows()), check_limits); | ||
| return addBlockToJoin(materialized, ScatteredBlock::Selector(materialized.rows()), context.joinChecksLimits()); |
| bool success = true; | ||
| for (const Block & saved_block : right_blocks) | ||
| success = success && join->addBlockToJoin(saved_block); | ||
| success = success && join->addBlockToJoin(saved_block, saved_block.rows(), context); |
Follow-up of the retro three-skill pass (`reduce-complexity`, `humanize`, `plain-prose`) over PR #120002. Only comment lines in `IJoin.h` change; behaviour and every signature stay the same. The parameter paragraphs of `addBlockToJoin` now use one idea per sentence. `PREWHERE` and `CROSS JOIN` are written as SQL names. The four blank `///` separator lines are gone, because the file does not use them elsewhere. The `getMaxBuildThreads` comment is split at its semicolon. Every fact of the old text is kept. `reduce-complexity` found no structural change to make: the layer above (PR #115605) reads `worker_id` and `getMaxBuildThreads`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…d `worker_id` `IJoin` had two overloads, `(block, check_limits = true)` and `(block, num_rows, check_limits = true)`, the second forwarding to the first everywhere except `ConstantJoin`. There is one pure virtual now: `addBlockToJoin(const Block & block, size_t num_rows, size_t worker_id, bool check_limits)`. Every entry point passes `worker_id = 0`, the wrapper joins forward `num_rows`, `worker_id` and `check_limits` to the join they wrap, and `check_limits` is spelled out where the old default applied, so behavior does not change. No implementation reads `worker_id` yet: concurrent fillers will pass distinct ids, and `IJoin::getMaxBuildThreads` (default 0, the pipeline decides) is where a join will cap them. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ches The blocks are replayed into the new `MergeJoin` under the switch lock by the one thread that triggered the switch, so the id it was called with carries no information there; pass 0, like every other single-threaded caller. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Follow-up of the retro three-skill pass (`reduce-complexity`, `humanize`, `plain-prose`) over PR #120002. Only comment lines in `IJoin.h` change; behaviour and every signature stay the same. The parameter paragraphs of `addBlockToJoin` now use one idea per sentence. `PREWHERE` and `CROSS JOIN` are written as SQL names. The four blank `///` separator lines are gone, because the file does not use them elsewhere. The `getMaxBuildThreads` comment is split at its semicolon. Every fact of the old text is kept. `reduce-complexity` found no structural change to make: the layer above (PR #115605) reads `worker_id` and `getMaxBuildThreads`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…er_id` and `check_limits` `JoinBuildContext` says which build stream makes a build-side call and whether the join checks the size limits. Only `QueryPipelineBuilder` can number the streams, through `forStream`. An owner that fills a join one call at a time uses `serial`. `callerChecksLimits` keeps the stream and turns the limit checks off. A join that inserts into another join passes the context of the stream it works for. That covers the `JoinSwitcher::switchJoin` replay, the `GraceHashJoin` re-bucketing and the inserts that `requestSpill` starts. So `requestSpill` takes the context too. `GraceHashJoin::getDelayedBlocks` and the `onBuildPhaseFinish` paths use `serial`. The pipeline numbers its build streams and caps them by `getMaxBuildThreads`. No join reads the stream yet and none overrides `getMaxBuildThreads`, so behavior does not change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Only `FillingRightJoinSideTransform` fills a `ConstantJoin`, and it passes the row count of the chunk. That count equals `Block::rows` whenever the block has columns, so the fallback to `Block::rows` is not needed. A `chassert` checks the equality in debug builds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
9a0209a to
9538760
Compare
It only kept code other than `QueryPipelineBuilder` from calling `JoinBuildContext::forStream`. Review found it overcomplicated for that. Review: #120002 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
The rebuild only served the estimate of the right table size in the old analyzer's `chooseJoinAlgorithm`. #115605 no longer makes that estimate. No other caller leaves `indexes` for `applyFilters` to find, so `ReadFromMergeTree` goes back to the code on master. Related: #120011 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This brings in `master` through #120002. In `HashJoin`, the row store now follows master. It holds only output columns and the ASOF key, and `initRowStore` builds it only when it saves enough cache misses. Non-joined rows collect only row references, and `gatherJoinOutputColumns` reads the row store for them. The non-joined scan keeps its per-stream bucket ownership. `JoinStep` takes master's bounded squash. The single-stream queries of `05337_parallel_join_max_joined_block_size` now use `grace_hash`, because a `hash` join with one slot adds no squash. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`QueryPipelineBuilder.cpp` conflicted. Master now registers the filling transforms for the seal gates, and this branch passes them a `JoinBuildContext`. The resolution keeps both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This brings the latest master through #120002. The generated `SessionSettingsExplorer.jsx` conflicted. It takes master's version and keeps the `join_algorithm` default of this branch, `direct,hash,ie_join`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This brings in #120002, which `uhj` was stacked on, so the pull request now targets `master` directly. The merge has no conflicts. Co-Authored-By: Claude Opus 5.5 <[email protected]>

#115605 sits on this.
Split out of #115605 as asked in #115605 (comment).
Related: #115605
IJoinhas twoaddBlockToJoinoverloads. The second forwards to the first, except inConstantJoin. There is no worker id. Several threads can fill one join, but the join cannot tell them apart.The unified
HashJoinin #115605 is one object. Several threads insert into it, and each thread needs its own id so it can keep its own stored blocks, null maps and used-flag lists. Two overloads cannot grow a third argument without another copy of every implementation.There is one pure virtual now. It takes a
JoinBuildContext: the build stream that makes the call, and whether the join checks the size limits.getMaxBuildThreads()is added with default 0, so the pipeline decides, and nothing overrides it yet. The pipeline caps the build streams by it.The split plan linked above asked for a bare
worker_idthat every caller sets to 0. A value type cannot be swapped withnum_rows.QueryPipelineBuildernumbers the streams, and they get their real numbers here. So the contract inIJoin.his true where it lands.All 10 implementations on master are adapted:
ConcurrentHashJoin,ConstantJoin,DirectKeyValueJoin,FullSortingMergeJoin,GraceHashJoin,HashJoin,JoinSwitcher,MergeJoin,PasteJoin,SpillingHashJoin. Callers inFillingRightJoinSideTransformandStorageJoinare adapted too, andQueryPipelineBuildergives eachFillingRightJoinSideTransformits stream.Behavior is unchanged. A single filler, join by layers and
StorageJoinuseserial. A join that inserts into another join passes the context of the stream it works for.JoinSwitcherandSpillingHashJoinforward it,JoinSwitcher::switchJoinreplays its saved blocks with it, andGraceHashJoinre-buckets with it. Re-inserts of blocks that the limits already admitted usecallerChecksLimits.GraceHashJoin::getDelayedBlocksand theonBuildPhaseFinishpaths useserial.requestSpilltakes the context of the stream that asks for the spill.GraceHashJoin, as before, inserts each rescattered bucket block with its own row count.ConstantJoinis the only implementation that readsnum_rows, and onlyFillingRightJoinSideTransformfills it, with the chunk row count. No implementation reads the stream yet.Changelog category (leave one):
Workflow [PR]
Sync PR [sync-upstream/pr/120002]
Version info
26.10.1.1907-master(included in26.10and later)