Repository navigation
Do not call a function per matched row in hash joins that output no right-table column - #126173
Conversation
…ight-table column The hash join probe loops called the out-of-line AddedColumns::appendFromBlock for every matched row. When the join outputs no column of the right table, record_row_refs is false and the callee returned immediately, but the call stayed in the loop, and its cost depended on where the linker placed the loop and the callee: join_squashing_blocks #0/ClickHouse#1 ran 17-20% slower in about one build in 64 (the amd_release reds on ClickHouse#122184 and ClickHouse#120758), and 1.4x slower in some process starts. Make appendFromBlock ALWAYS_INLINE so the record_row_refs test happens in the loop, and keep the recording part, LazyOutput::addRef, out of line with NO_INLINE: inlining its body into every probe loop made hashjoin_low_cardinality_key #0 5-10% slower and pushed processMatch out of line, even in loops where addRef never runs. Joins that record row refs keep one call per match, to the same body as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck), plus my own cold review of the same head (0 blocker, 0 major).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20261016-010311 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261015-225400 |
|
Workflow [PR], commit [6c65317] Summary: ✅
AI ReviewSummaryThe PR inlines Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested. |
|
cc @harikrishnan94 @nickitat, could you review this? It makes |
|
@groeneai Make CI green |
The previous run's Performance Comparison shards timed out while the CI logs cluster check was blocked, before the perf queries finished. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
All 7 red shards are job timeouts, not perf results. In each of them at least one of the two In the finished shards I can't re-run jobs, so I pushed an empty commit (6c65317) to re-run CI. A fix that bounds this probe is in progress; I'll link its PR here when it opens. |
|
Fixing PR for the Performance Comparison job timeouts (CI logs cluster check in setup_log_cluster.sh): #126217 |
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/DataTypes/TypeFunctions.cpp.o |
new | 1.00 MiB | +1.00 MiB |
src/CMakeFiles/dbms.dir/Interpreters/Aggregator.cpp.o |
25.56 MiB | 26.43 MiB | +895.89 KiB (+3.42%) |
src/CMakeFiles/dbms.dir/DataTypes/TypeMatchers.cpp.o |
new | 692.78 KiB | +692.78 KiB |
src/CMakeFiles/dbms.dir/DataTypes/FunctionSignature.cpp.o |
new | 417.14 KiB | +417.14 KiB |
src/Functions/array/CMakeFiles/clickhouse_functions_array.dir/arrayDotProduct.cpp.o |
1.75 MiB | 1.55 MiB | -201.52 KiB (-11.24%) |
src/CMakeFiles/dbms.dir/Functions/FunctionsConversion_impl2.cpp.o |
1.31 MiB | 1.14 MiB | -174.78 KiB (-13.07%) |
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/FunctionsBitmap.cpp.o |
2.58 MiB | 2.41 MiB | -167.40 KiB (-6.35%) |
src/CMakeFiles/dbms.dir/Functions/FunctionsConversion_impl1.cpp.o |
1.12 MiB | 986.07 KiB | -160.78 KiB (-14.02%) |
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/vectorFunctions.cpp.o |
3.29 MiB | 3.43 MiB | +148.59 KiB (+4.41%) |
src/Functions/array/CMakeFiles/clickhouse_functions_array.dir/arrayCumSumNonNegative.cpp.o |
603.16 KiB | 466.82 KiB | -136.34 KiB (-22.60%) |
src/Functions/array/CMakeFiles/clickhouse_functions_array.dir/arrayCumSum.cpp.o |
673.15 KiB | 538.16 KiB | -134.99 KiB (-20.05%) |
src/Functions/array/CMakeFiles/clickhouse_functions_array.dir/arrayAggregation.cpp.o |
1.29 MiB | 1.16 MiB | -134.86 KiB (-10.22%) |
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/FunctionsCodingIP.cpp.o |
1.27 MiB | 1.13 MiB | -133.67 KiB (-10.32%) |
src/Functions/array/CMakeFiles/clickhouse_functions_array.dir/arrayDifference.cpp.o |
592.61 KiB | 478.04 KiB | -114.56 KiB (-19.33%) |
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/FunctionsJSON.cpp.o |
4.26 MiB | 4.37 MiB | +111.80 KiB (+2.57%) |
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/FunctionsHashingMisc.cpp.o |
5.53 MiB | 5.61 MiB | +83.25 KiB (+1.47%) |
src/Functions/array/CMakeFiles/clickhouse_functions_array.dir/arrayDistance.cpp.o |
10.19 MiB | 10.11 MiB | -78.98 KiB (-0.76%) |
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/FunctionsConversion_reg.cpp.o |
6.83 MiB | 6.75 MiB | -78.39 KiB (-1.12%) |
src/CMakeFiles/dbms.dir/Functions/FunctionsConversion_impl3.cpp.o |
1.87 MiB | 1.80 MiB | -76.37 KiB (-3.98%) |
src/CMakeFiles/dbms.dir/Functions/IFunction.cpp.o |
555.11 KiB | 631.16 KiB | +76.05 KiB (+13.70%) |
719 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
2853 translation units recompiled, 16566 s compile time in total, 2848 of them have a recent master baseline.
Translation units without a recent master baseline:
programs/keeper/Keeper.cpp (clickhouse-keeper): 8.5 ssrc/DataTypes/TypeFunctions.cpp: 7.0 s
Related: #125949 (comment)
Related: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=122184&sha=e2db640da2cfb61837f14e5451dc416acbf86161&name_0=PR&name_1=Performance%20Comparison%20%28amd_release%2C%20master_head%2C%205%2F6%29
Related: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=120758&sha=3451905c0a13c854593622761c4fc79a1deefcbd&name_0=PR&name_1=Performance%20Comparison%20%28amd_release%2C%20master_head%2C%206%2F6%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Hash joins that output no column of the right table, for example
SELECT count() FROM t LEFT JOIN r ON t.x = r.y, no longer call a function for every matched row, which makes their probe loop up to about 20% faster.Description
The hash join probe loops call
AddedColumns::appendFromBlockout of line for every matched row. When the join outputs no right-table column,record_row_refsis false and the callee only tests that flag and returns. The cost of this call depends on where the linker places the loop and the callee:join_squashing_blocks#0/#1 ran 17-20% slower in about one build in 64, which is what made the two amd_release reds linked above (on #120758 it survived the confirmation restart), and 1.4x slower in some process starts.appendFromBlockis now inline, so the flag is tested in the loop. Its recording part,LazyOutput::addRef, stays out of line withNO_INLINE: inlining its body into every probe loop madehashjoin_low_cardinality_key#0 5-10% slower in an-O3build and pushedprocessMatchout of line, even in loops whereaddRefnever runs. Joins that record row refs keep one call per match, to the same body.Measured on a local x86-64 ThinLTO
-g0build in the PR CI configuration, 20 interleaved rounds per query:join_squashing_blocks#0/#1 0.81x,hashjoin_low_cardinality_key#0/#1 0.88x/0.87x,join_main_loop0.86x to 1.01x, and two queries that output a right column (join_append_block#0 and anALL INNER JOINreturningr.w) 1.00x/1.01x. Forjoin_squashing_blocks#0 the retired near calls drop from 331.9M to 31.8M (300M probe rows). The 1334 join/asof stateless tests show no new failure against master in a debug build. The placement effect does not reproduce on my machine, so the amd/arm numbers are in this PR's Performance Comparison.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126173]
Version info
26.11.1.165-master(included in26.11and later)