Repository navigation
Run joins with several ON disjuncts on the partitioned hash join - #120595
harikrishnan94 wants to merge 22 commits into
Conversation
|
Workflow [PR], commit [3f8a873] Summary: ❌
AI ReviewSummaryThe PR builds and probes a separate partitioned hash table for each Findings
Tests
Final Verdict |
| clause.reserveFor(build_rows_hint.value_or(keys), static_cast<double>(keys)), | ||
| accumulated_rows.load(std::memory_order_relaxed), | ||
| /*grow_at_max_fill_=*/true); | ||
| for (auto & clause : clauses) |
There was a problem hiding this comment.
Now that this branch inserts the same build block into every clause table, the sizeLimits() check below is no longer measuring the object it is supposed to cap. accumulated_rows counts the right-side rows once and accumulated_bytes only tracks the stored blocks, but a several-disjunct build can produce more hash-table keys than input rows and can spend most of its memory in the per-clause tables and arenas.
The new gtest already demonstrates the row-count side of this: 60000 build rows become 80000 keys (getTotalRowCount()). With max_rows_in_join between those values, or with a tight max_bytes_in_join, this path will accept a join that HashJoin would reject. Please switch this check to getTotalRowCount() and getTotalByteCount() once the clause inserts have run.
Build profile diff (arm_release)Comparing Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Interpreters/PartitionedHashJoin/PartitionedHashJoinProbeLeft.cpp.o |
new | 12.92 MiB | +12.92 MiB |
src/CMakeFiles/dbms.dir/Interpreters/PartitionedHashJoin/PartitionedHashJoinProbeInner.cpp.o |
new | 8.13 MiB | +8.13 MiB |
src/CMakeFiles/dbms.dir/Interpreters/PartitionedHashJoin/PartitionedHashJoinProbeRight.cpp.o |
new | 7.59 MiB | +7.59 MiB |
src/CMakeFiles/dbms.dir/Interpreters/PartitionedHashJoin/PartitionedHashJoinProbeFull.cpp.o |
new | 3.48 MiB | +3.48 MiB |
src/CMakeFiles/dbms.dir/Interpreters/PartitionedHashJoin/HashJoinClause.cpp.o |
new | 1.96 MiB | +1.96 MiB |
src/CMakeFiles/dbms.dir/Interpreters/PartitionedHashJoin/PartitionedHashJoin.cpp.o |
new | 1.22 MiB | +1.22 MiB |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/HashJoin.cpp.o |
3.36 MiB | 4.23 MiB | +882.78 KiB (+25.62%) |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/FullHashJoinAll.cpp.o |
3.57 MiB | 2.85 MiB | -737.27 KiB (-20.18%) |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/LeftHashJoinAll.cpp.o |
3.38 MiB | 2.70 MiB | -699.49 KiB (-20.21%) |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/LeftHashJoinAnti.cpp.o |
2.63 MiB | 1.96 MiB | -677.23 KiB (-25.19%) |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/InnerHashJoinAny.cpp.o |
2.68 MiB | 2.02 MiB | -673.27 KiB (-24.56%) |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/LeftHashJoinAntiMapsAll.cpp.o |
3.08 MiB | 2.43 MiB | -664.28 KiB (-21.07%) |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/FullHashJoinRightAny.cpp.o |
3.31 MiB | 2.67 MiB | -662.55 KiB (-19.52%) |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/RightHashJoinAll.cpp.o |
3.47 MiB | 2.82 MiB | -661.44 KiB (-18.64%) |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/FullHashJoinAnti.cpp.o |
2.59 MiB | 1.95 MiB | -653.20 KiB (-24.61%) |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/LeftHashJoinAntiMapsSet.cpp.o |
2.41 MiB | 1.78 MiB | -648.39 KiB (-26.29%) |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/LeftHashJoinAny.cpp.o |
2.64 MiB | 2.01 MiB | -646.48 KiB (-23.92%) |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/LeftHashJoinRightAny.cpp.o |
2.64 MiB | 2.01 MiB | -646.47 KiB (-23.92%) |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/FullHashJoinAny.cpp.o |
3.05 MiB | 2.43 MiB | -639.04 KiB (-20.44%) |
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/InnerHashJoinAnyMapsAll.cpp.o |
3.16 MiB | 2.54 MiB | -636.89 KiB (-19.66%) |
720 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units ⚠️
2144 translation units recompiled, 14108 s compile time in total, 2129 of them have a recent master baseline.
Median compile-time ratio to the baselines is ×1.08 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +970.4 s (+8%) in total before that adjustment.
Translation units without a recent master baseline:
src/Interpreters/PartitionedHashJoin/PartitionedHashJoinProbeLeft.cpp: 54.9 ssrc/Interpreters/PartitionedHashJoin/PartitionedHashJoinProbeInner.cpp: 38.7 ssrc/Interpreters/PartitionedHashJoin/PartitionedHashJoinProbeRight.cpp: 34.1 ssrc/Interpreters/PartitionedHashJoin/PartitionedHashJoinProbeFull.cpp: 20.8 ssrc/Interpreters/PartitionedHashJoin/HashJoinClause.cpp: 19.6 ssrc/Interpreters/PartitionedHashJoin/PartitionedHashJoin.cpp: 11.8 sprograms/keeper/Keeper.cpp (clickhouse-keeper): 8.6 ssrc/Interpreters/PartitionedHashJoin/PartitionedHashJoinNotJoined.cpp: 7.9 ssrc/Interpreters/HashJoin/SharedFixedHashTableFilter.cpp: 6.0 ssrc/Interpreters/PartitionedHashJoin/JoinRouteHashing.cpp: 5.2 s
Symbol sizes
| Binary | Symbol | Master | PR | Δ |
|---|---|---|---|---|
programs/clickhouse-keeper |
ProfileEvents::global_counters_storage |
13.38 MiB | 13.56 MiB | +192.00 KiB (+1.40%) |
programs/clickhouse |
ProfileEvents::global_counters_storage |
13.38 MiB | 13.56 MiB | +192.00 KiB (+1.40%) |
programs/clickhouse |
auto DB::HashJoinClause::insertPartitionSection(DB::HashJoinClause::PostBuildContext&, unsigned lon… |
new | 66.93 KiB | +66.93 KiB |
programs/clickhouse-keeper |
auto DB::HashJoinClause::insertPartitionSection(DB::HashJoinClause::PostBuildContext&, unsigned lon… |
new | 66.93 KiB | +66.93 KiB |
c85fc8d to
8e69471
Compare
8e5aa95 to
37bfc7c
Compare
8e69471 to
e5fa97b
Compare
08a577a to
129f7a9
Compare
0b22791 to
9343d75
Compare
129f7a9 to
0be9a63
Compare
…ows` The probe of a join with several ON disjuncts (`ON a OR b`) on `PartitionedHashJoin` walked the whole left block before returning. When each left row matches thousands of right rows through the clauses together, the whole result was built in one `AddedColumns`: the first query of `03748_join_on_complex_condition_result_memory`, pinned to `partitioned_hash`, produces 18.75 million rows from 5000 and fails with `Code: 241` while allocating a 31.98 MiB chunk under its 50M limit. `hash` and `parallel_hash` pass it at 2-4 MiB. `HashJoinMethods::joinRightColumns` over several maps stops once the result reaches `max_joined_block_rows` and returns the rows it processed, and `PartitionedHashJoin::probeImpl` already splits the block on that count and hands the rest back through `setNextBlock`. Do the same here: stop the row loop at the limit, append the replication offsets instead of pre-sizing them, and return the number of rows processed. Before this layer every disjunctive join was delegated to `HashJoin::joinBlock`, which has that split. The new test runs the `03748` query on `partitioned_hash`, and checks every kind and strictness of an `ON a OR b` join against `hash` at `max_joined_block_size_rows` 1, 7, 100 and 1000000. It fails with `Code: 241` on the parent and passes here. Co-Authored-By: Claude Opus 5.5 <[email protected]>
9343d75 to
7432df3
Compare
0be9a63 to
123fc7a
Compare
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep a dirty lane sketch for each clause and sum their table predictions. Reuse the cached summed key count for warm fills without spill. The gated prediction trace matches a full merge across clauses. Focused unit tests, aarch64 TSan tests, and functional tests 05229 and 05227 passed.
The parent now carries the rewritten `uhj`. The conflicts were in the partitioned join, where this branch runs several ON clauses on its own tables. They are resolved on top of the interfaces the parent ported: `JoinBuildContext` for the fill lanes and the drain, `KeyGetterForType` without the offset flag, and the non-joined scan that emits the row store columns through `gatherJoinOutputColumns`. The scan over the stored blocks, for per-row used flags, is written the same way. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ined filler The scan over the stored blocks was in the tree twice after the merge, once in the old form and once ported, and the cursor member was declared twice. The row count of a Join table reads the first clause's tables, as the other readers of `clauses` do. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… constructor Two tests of the several-clause build compared the partitioned join with a standard `HashJoin` that was built with the thread count and layout flag of the old constructor. They pass a `HashJoinBuildLayout::oneBucket(1)` now. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brings in the declaration of `UNSUPPORTED_JOIN_KEYS` in `PartitionedHashJoin.cpp` that the style check asks for. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brings in the restored `isHashFamilyEnabled` checks of the planner, the switch log line of `JoinSwitcher` and the `hash` name of a Join table. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brings in the adjusted general join planning and grace buckets tests. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brings in the last two commits of `uhj`: the key and byte count of a slot insert that throws, and the rename of the `StorageJoin` count test. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brings in the fixes of the previous layers. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
`readability-qualified-auto` rejects the plain `auto &` in the loop over the lane sketches. The lane is `const`, so the reference already was `const`. The type now says so. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brings in the few-keys test fix. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brings in the latest merge of master into `uhj` and the port of the spilling joins to `ISpillable`. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brings in the continuation of the partitioned join result. This layer probes every disjunct itself, so the probe of the rest is `probeDispatch` alone. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
| for (size_t clause_idx = 1; clause_idx < clauses.size(); ++clause_idx) | ||
| clause_pool->scheduleOrThrow( | ||
| [this, clause_idx, rows, &clause_unique, thread_group = CurrentThread::getGroup()] | ||
| { | ||
| ThreadGroupSwitcher switcher(thread_group, ThreadName::PARTITIONED_JOIN); | ||
| clause_unique[clause_idx] = clauses[clause_idx].postBuild(rows, *post_build_pools[clause_idx]); |
There was a problem hiding this comment.
[P2] Share the worker budget across concurrently built clauses
Every clause launched here calls postBuildPool, which independently allocates up to num_threads workers. With eight disjuncts, at least 16 build blocks, and max_threads = 16, the partitioned build can therefore run 128 worker tasks, plus seven clause coordinators, for one join. These pools do not acquire query CPU slots or share a concurrency limit.
This path is also the normal path for several-disjunct SQL joins: both planners disable spilling for that shape and construct this join with a zero external-memory budget. Increasing the number of OR terms therefore multiplies CPU concurrency and thread demand even with a fixed max_threads, which can oversubscribe the server or exhaust its thread pool under concurrent queries. Please divide a shared worker budget among the active clauses, or build the clauses sequentially while retaining parallelism within each clause.
Brings in the merge of `uhj` that repairs the `gtest_functions_stress` build. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brings in the fix of the inserted row count of the single-lane build and the pinned settings of the tests. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brings in the latest merge of `uhj`, the fixes of the scatter check and of the spill hand-over, and the test changes of the earlier branches. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…sing `05229` and `05238` took more than the limit of a flaky check, so they carry the `long` tag like the other slow tests of this join. `05229` asserts that the non-joined rows of a `FULL` join come from several streams, which only `parallel_non_joined_rows_processing` allows, so it sets that setting. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Brings in the fixes of the `05227`, `05218`, `05139` and `04931` tests and the sanitizer guard of the `HashJoinTable` unit test. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Part of https://github.com/ClickHouse/ClickHouse/pull/120423. Sits on #120585. #121707 sits on this.
A join whose
ONhas several disjuncts (ON a = b OR c = d) builds one hash table per disjunct and probes them one after another.partitioned_hashhas one table, so this shape falls back toHashJoineven when you asked forpartitioned_hash.Each clause now gets its own partitioned table. Each build row is routed into each clause's table. The probe walks the clauses with per-row flags, and non-joined rows are emitted from the stored blocks.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
partitioned_hashnow runs joins whoseONclause has several disjuncts.Workflow [PR]
Sync PR [sync-upstream/pr/120595]