Repository navigation
Fill right key columns of a LEFT JOIN in 64-row chunks when the rows agree - #125542
Conversation
filterWithBlanks copied the left key into the right key column of a LEFT JOIN one row at a time, with a virtual insertFrom or insertDefault per row. It now reads the filter 64 rows at a time (bytes64MaskToBits64Mask, as in filterArraysImpl): a chunk whose rows are all kept is one insertRangeFrom, a chunk whose rows are all blank is one insertManyDefaults, and any other chunk keeps the per-row loop. ColumnNullable gets an insertManyDefaults override, so a blank Nullable chunk fills the nested column and the null map in bulk instead of 64 virtual insertDefault calls. Measured on x86 release (8 pinned cores; wall = median of 21 runs, user-space instructions = median of 3 perf stat runs minus startup), base -> this commit: - join_nullable_keys_small_table ClickHouse#4: 0.61x wall, 0.47x instructions; ClickHouse#8: 0.71x / 0.55x; ClickHouse#3: 0.66x / 0.55x; ClickHouse#7: 0.80x / 0.66x. - Alternating rows and runs of 2, 3 and 100 rows: 0.86x-0.99x instructions. - Queries of the same test that do not reach filterWithBlanks: within 0.4% instructions (wall moves up to +23% between the two builds from code placement alone, with the same instruction count). The added perf query covers the per-row path (alternating matched and unmatched rows), which the existing queries of the test do not reach. The test runs all its queries (`run_all_queries`), as it now has more than the 10 that CI samples. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rewrite the ColumnNullable::insertManyDefaults catch comment as a standalone invariant. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (3 rounds; all AGREEd findings fixed, last round clean)
Round 3 (this head): no findings. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261012-214500 |
|
Workflow [PR], commit [30fb2bc] Summary: ✅
AI ReviewSummaryReviewed #125542 at Output consumers traced: Missing context / blind spots
Final VerdictStatus: ✅ Approve |
|
📊 Cloud Performance Report ✅ AI verdict: The PR speeds up filterWithBlanks, which hash joins use to fill unmatched rows. Fully kept or fully blank 64-row chunks are now inserted in a single call, and ColumnNullable gets a bulk insertManyDefaults. The only flagged query, clickbench Q9 (-10.4%), was downgraded to not_sure. It is a single-table aggregation with no join and no Nullable columns, its baseline was thin and had to be refit after a recent master era break, and both medians sit inside master's current range of 361-458 ms. None of the benchmarked queries here exercise the hash-join path this PR targets, so the added join_nullable_keys_small_table perf test is the right place to measure its effect. clickbenchFlagged queries (1 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
|
CI finish ledger - 77d81faEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261013-080005 |
m-selmi
left a comment
There was a problem hiding this comment.
@groeneai experiment with the following ideas:
- de-virtualizing the loop following the pattern used in IColumnHelper.
- try to compute the longest run of consecutive values instead of stoping at 64 size chunks or falling back to individual inserts per row for mixed chunks.
Report back the performance of these suggestions.
Also merge master to fix the failing test.
…r-with-blanks-chunks
|
Merged master (9914b16; the failing Setup. One x86 release binary (clang-22, this PR on master 870f005) with every variant behind an environment switch, so all variants share one code layout (experiment only, not pushed). Metric: user-space instructions per query (
Wall time (median of 21 runs on 8 pinned cores; a control query that never reaches this code moves +2..9% between variants here) keeps the same order: #4 0.66 / 0.89 / 0.72 / 0.70 / 0.66, UInt64 runs of 2 1.08 / 0.85 / 1.15 / 1.12 / 0.88, Nullable(UInt64) runs of 2 0.95 / 0.92 / 1.23 / 1.18 / 0.93.
I'd switch the PR to PR+A (the loop in |
The loop moves into a new IColumn::insertFromOrDefaults, which IColumnHelper implements on the concrete column type, so insertFrom, insertDefault, insertRangeFrom and insertManyDefaults are no longer virtual calls. Consecutive 64-row chunks that are entirely kept or entirely blank are inserted with one call. User-space instructions relative to master (x86 release, join_nullable_keys_small_table and probes with runs of matched rows): ClickHouse#4 0.43x (0.46x with plain 64-row chunks), UInt64 runs of 1 to 3 rows 0.80x to 0.82x (0.94x to 0.95x), Nullable(UInt64) runs of 1 to 3 rows 0.90x (0.96x); queries that do not reach the function are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The inherited IColumn::insertManyDefaults reserves the whole column before filling it, and a nested column whose own bulk fill rolls back with allocations (Object paths through ColumnVariant::popBack) relies on that. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes517 object files changed (+187.54 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 units2652 translation units recompiled, 15590 s compile time in total, 2652 of them have a recent master baseline. |
|
Switched the PR to PR+A: 956417d moves the loop into a new |
CI finish ledger - 661380fEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261019-213007 |
…story `PersistentTableComponents::format_version` is captured when the table is opened and is documented as allowed to go stale after an external upgrade. `getHistory` re-reads the latest metadata file and asserted that its `format-version` still equals the cached value, so a debug or sanitizer server aborted when another engine upgraded an attached table and then `system.iceberg_history` or `OPTIMIZE` (which calls `getHistory`) ran. Seen in Stress test (amd_msan) on PR ClickHouse#125542 (STID 2508-400e), where the AST fuzzer turned a `system.iceberg_history` query into an unfiltered scan that reached the table 05394 had just upgraded to format version 3. ClickHouse#100407 removed this comparison from both `getState` and `getHistory`; the ClickHouse#108080 sync brought both back and 6520200 removed only the `getState` one. `getHistory` computes everything from the freshly read metadata, and release builds compile `chassert` out, so there is no release-build behavior change. Extend the ClickHouse#86776 regression case to compare `system.iceberg_history` before and after the v1 -> v2 upgrade; it aborts node1 on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@groeneai figure out where the overhead in A+B on short runs come from. If it's from |
|
Profiled and benchmarked. Setup as last time: one x86 release binary (this PR's head 661380f) with every variant behind an environment switch, so all of them share one code layout (local only, not pushed). Metric: user-space instructions per query ( Where A+B's overhead on short runs comes from: both. On runs of 2, run detection is 30-40% of A+B's extra instructions and the bulk calls are the rest. I split it inside one function by switching paths at run time:
Each 2-row bulk call is an out-of-line C, your approach: runs detected, a run shorter than 4 rows inserted by a loop of D: the PR's 64-row chunks, where a mixed chunk with at most 12 value changes goes to an out-of-line function that inserts it run by run like C; a chunk with more changes keeps the per-row loop. Detection is then paid only where the runs are long enough to pay it back, plus one Instructions / wall time, ratio to master. Wall is the median of 21 runs on 8 pinned cores; a control query that never reaches this code moves 1.01-1.03x between variants and the per-round medians of one variant spread by 10-20%, so wall differences under ~5% are noise.
Queries #3 / #4 / #7 / #8 of
Neither beats the PR on every row, so I'm keeping the PR as it is. If you want D anyway (one out-of-line function, about 35 lines in |
…r-with-blanks-chunks
Since the unified hash join (ClickHouse#115605), `join_algorithm = 'hash'` with the default `hash_join_layout = 'auto'` takes the parallel layout when the right side has no row estimate, which is the case for this query (`EXPLAIN PIPELINE` shows 8 `FillingRightJoinSide`). The parallel layout scatters the left block by key hash, so the per-shard blocks no longer alternate matched and unmatched rows, which is the shape this query was added to measure. Master pinned the layout of every other query in this file the same way (6a6e4d5). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #125351
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
LEFT JOINqueries that return a right-side key column now insert runs of unmatched (or matched) rows at once and the remaining rows without virtual calls, andNullablecolumns insert default values in bulk. ALEFT JOINonNullablekeys against a small table that returns all columns is up to 1.5 times faster.Description
When a
LEFT JOINoutputs a right key column,copyLeftKeyColumnToRightbuilds it from the left key withJoinCommon::filterWithBlanks, which inserted one row at a time (a virtualinsertFromorinsertDefaultper row). This loop is 47.5% of the CPU ofjoin_nullable_keys_small_table#4, and it is the frame that grew in the redPerformance Comparison (arm_release, master_head, 6/6)run on #125351 (report; #4 +27.7%, #8 +23%) after a code-placement change.filterWithBlanksnow calls a newIColumn::insertFromOrDefaults, whichIColumnHelperimplements on the concrete column type, so per-row inserts are not virtual calls. It reads the filter 64 rows at a time withbytes64MaskToBits64Mask: consecutive all-kept chunks are oneinsertRangeFrom, consecutive all-blank chunks oneinsertManyDefaults, other chunks go row by row.ColumnNullablegets aninsertManyDefaultsoverride (it used theIColumnloop ofinsertDefault); the open #115024 adds an equivalent one, so whichever PR lands second drops its copy. Variants measured in review: comment.x86 release, 8 pinned cores, master vs this PR (wall: median of 21 runs; user-space instructions from
perf stat):UInt64keys, runs of 1 to 100 rowsNullable(UInt64)keys, runs of 1 to 32 rowsfilterWithBlanksThe perf test gets one query with alternating matched and unmatched rows (the per-row path) and runs all its 11 queries (
run_all_queries="1") instead of a random 10. Output is byte-identical to master on 9,756 differential join queries (incl.Nullable,LowCardinalitywith a shared dictionary, replicated columns, runs around the 64-row boundary) in release and debug builds.Workflow [PR]
Sync PR [sync-upstream/pr/125542]
Version info
26.11.1.2423-master(included in26.11and later)