Skip to content

Fill right key columns of a LEFT JOIN in 64-row chunks when the rows agree - #125542

Merged
m-selmi merged 7 commits into
ClickHouse:masterfrom
groeneai:groeneai/join-filter-with-blanks-chunks
Nov 16, 2026
Merged

m-selmi merged 7 commits into
ClickHouse:masterfrom
groeneai:groeneai/join-filter-with-blanks-chunks

Conversation

@groeneai

@groeneai groeneai commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #125351

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

LEFT JOIN queries that return a right-side key column now insert runs of unmatched (or matched) rows at once and the remaining rows without virtual calls, and Nullable columns insert default values in bulk. A LEFT JOIN on Nullable keys against a small table that returns all columns is up to 1.5 times faster.

Description

When a LEFT JOIN outputs a right key column, copyLeftKeyColumnToRight builds it from the left key with JoinCommon::filterWithBlanks, which inserted one row at a time (a virtual insertFrom or insertDefault per row). This loop is 47.5% of the CPU of join_nullable_keys_small_table #4, and it is the frame that grew in the red Performance Comparison (arm_release, master_head, 6/6) run on #125351 (report; #4 +27.7%, #8 +23%) after a code-placement change.

filterWithBlanks now calls a new IColumn::insertFromOrDefaults, which IColumnHelper implements on the concrete column type, so per-row inserts are not virtual calls. It reads the filter 64 rows at a time with bytes64MaskToBits64Mask: consecutive all-kept chunks are one insertRangeFrom, consecutive all-blank chunks one insertManyDefaults, other chunks go row by row. ColumnNullable gets an insertManyDefaults override (it used the IColumn loop of insertDefault); 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):

query wall instructions
#4 / #8 0.65x / 0.70x 0.43x / 0.52x
#3 / #7 0.77x / 0.79x 0.52x / 0.63x
UInt64 keys, runs of 1 to 100 rows 0.81x-0.89x 0.76x-0.83x
Nullable(UInt64) keys, runs of 1 to 32 rows 0.94x-1.02x 0.91x
queries not reaching filterWithBlanks 0.98x-1.02x within 0.1%

The 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, LowCardinality with 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

  • Merged into: 26.11.1.2423-master (included in 26.11 and later)

groeneai and others added 2 commits October 13, 2026 00:04
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]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Oct 13, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (3 rounds; all AGREEd findings fixed, last round clean)
Finding Verdict
⚠️ ColumnNullable::insertManyDefaults rolled back only a null-map failure; a nested fill that throws part-way (Nullable(Tuple(...)), per-row default loop) left the nested column longer than the null map AGREE, fixed
⚠️ The rollback of that override called the nested popBack, which can allocate (Nullable(JSON) -> ColumnVariant::popBack), after a null-map allocation the replaced IColumn loop had reserved up front AGREE, fixed: the null map is reserved before the nested fill and, on a nested throw, extended to the nested size; nothing in that path allocates
⚠️ The perf test grew to 11 queries while CI samples 10 per test, so one query (possibly #4/#8) was dropped at random per run AGREE, fixed: run_all_queries="1"
💡 The inverse_filter = true chunk branches are verified by reading (all-zero null-map chunk -> insertRangeFrom, all-NULL chunk -> insertManyDefaults, mixed -> the old per-row predicate); targeted probes did not reach those call sites noted, not blocking

Round 3 (this head): no findings.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? The CI red is a code-placement flip of one build; the cost it amplifies is deterministic: perf stat user-space instructions of join_nullable_keys_small_table #4 are 34.98 G on the base and 16.47 G with this PR, each reproducible within 0.1% over 3 runs.
b Root cause explained? copyLeftKeyColumnToRight fills the right key column through filterWithBlanks one row at a time (virtual insertFrom / insertDefault per row; ColumnNullable had no insertManyDefaults). In #4/#8 almost every block is entirely unmatched, so this loop is 47.5% of #4's CPU, and it is the frame that grew in the red CI run.
c Fix matches root cause? The per-row loop is replaced only where it is pure overhead: 64-row chunks that are all kept (one insertRangeFrom) or all blank (one insertManyDefaults). Mixed chunks keep the old loop. Queries #4/#8 and the perf harness are unchanged.
d Test intent preserved / new tests added? Performance Improvement (no wrong result before), so no stateless regression test. The perf test gets one query with alternating rows, covering the per-row path.
e Both directions demonstrated? Base vs this PR on the same 19 queries: #4 0.61x wall / 0.47x instructions, #8 0.71x / 0.55x; no query executes over 0.4% more instructions than on the base (max 1.0037x, a control).
f Fix is general across code paths? All five callers (HashJoinResult.cpp x2, HashJoin.cpp, IDictionary.h x2) go through the one function; the inverse-filter instantiation keeps the old per-row meaning.
g Fix generalizes across inputs (params/datatypes/wrappers)? 9,756 differential queries byte-identical to the base (release and debug): UInt64, String, FixedString, Decimal64, Tuple, Array, Nullable(UInt64), Nullable(String), LowCardinality(String), LowCardinality(Nullable(String)), mixed left/right key types, a replicated source column, a shared LowCardinality dictionary from a wide part, runs of 1, 2, 3, 63, 64, 65, 100 and a single stray row, tails of 16 and 33 rows, LEFT / INNER / FULL / RIGHT / SEMI / ANTI, join_use_nulls 0/1, hash / parallel_hash / grace_hash.
h Backward compatible? (maintainer-approved exception only) Yes: no setting, format or protocol change; the produced values are the same.
i Invariants and contracts preserved? insertRangeFrom(src, s, 64) equals 64 insertFrom calls and insertManyDefaults(64) 64 insertDefault calls in logical values for every column type (a LowCardinality result may adopt the shared source dictionary, same values). Chunks only read row + 64 <= rows. The Nullable override reserves the null map before the nested fill; if the nested fill throws part-way, the null map is extended to the nested size, and nothing on that path allocates. Stateless join tests: 0 failures that do not also fail on the base.

Session id: cron:clickhouse-impl-slot-6:20261012-214500

@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [30fb2bc]

Summary: ✅


AI Review

Summary

Reviewed #125542 at 30fb2bcd3d5e8037b7b68a063eda7d05ada12496. The change batches uniform runs when filling right-side LEFT JOIN keys, devirtualizes mixed-row inserts, and adds bulk defaults to ColumnNullable. No new blockers or majors found. The earlier nested-reservation finding is fixed, and the reported before/after measurements support the performance claim.

Output consumers traced: HashJoinResult casts and replicates through column APIs; both join nullability-correction paths normalize null values before removing nullability; IDictionary::getByKeys materializes keys and returns columns through the existing interfaces. Bulk inserts preserve the dictionary/index relationship for LowCardinality and the nested/index relationship for ColumnReplicated.

Missing context / blind spots
  • ⚠️ No local ClickHouse executable or build was available, so runtime validation relies on the author's reported release/debug differential checks and the Praktika reports, which reported 14,364 passed tests and no failures. Independently rerunning the differential queries and allocation-failure checks would close this gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-performance Pull request with some performance improvements comp-joins JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla... labels Oct 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 31 queries analysed

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.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 9 not_sure 422 378 -10.4% <0.0001 aggregation: This ClickBench GROUP BY query has no JOIN and no Nullable columns, so the changed join blank-filling and Nullable insertManyDefaults code never runs. The -10.4% shift is within master's recent range of 361-458 ms.

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
  • StressHouse run: 9f6ea213-867f-41c8-864c-2d2375365c38
  • MIRAI run: 24bf375f-3f0d-4b63-889d-377280b8a95a
  • PR check IDs:
    • clickbench_1170353_1791857819
    • clickbench_1170359_1791857819
    • clickbench_1170365_1791857819
    • tpch_adapted_1_official_1170376_1791857819
    • tpch_adapted_1_official_1170387_1791857819
    • tpch_adapted_1_official_1170423_1791857819

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 77d81fa

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Integration tests (arm_binary, 1/4) / test_storage_iceberg_concurrent/test_concurrent_reads.py::test_concurrent_reads not from this PR (it only changes JoinCommon::filterWithBlanks and ColumnNullable::insertManyDefaults): a reused Spark JVM handed the Iceberg module the stale s3a FileSystem of the Delta interop module that ran earlier in the same job. It failed on 67 other PRs and 25 master runs since 2026-10-12. The tested tree predates the fix #125448 (mine, merged)
Mergeable Check, PR praktika rollups of the row above #125448 (mine, merged)

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261013-080005

@m-selmi m-selmi self-assigned this Oct 19, 2026

@m-selmi m-selmi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Merged master (9914b16; the failing test_storage_iceberg_concurrent is fixed there by #125448), and measured both ideas plus their combination.

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 (perf stat, median of 3, process startup subtracted, spread under 0.2%), as a ratio to master; lower is better. Every variant returns byte-identical results to master on the 9,756-query join battery used for this PR.

  • PR: the current 64-row chunks, mixed chunks row by row through virtual calls.
  • A: the per-row loop devirtualized in IColumnHelper (a new IColumn virtual; insertFrom / insertDefault called on Derived).
  • B: longest runs, found with bytes64MaskToBits64Mask + countr_zero over the value transitions; one insertRangeFrom / insertManyDefaults per run, single rows with insertFrom / insertDefault.
  • A+B: B, devirtualized.
  • PR+A: 64-row chunks devirtualized, consecutive all-kept or all-blank chunks merged into one call.
query PR A B A+B PR+A
#3 0.54 0.82 0.51 0.51 0.51
#4 0.46 0.80 0.43 0.43 0.43
#7 0.64 0.86 0.62 0.62 0.62
#8 0.55 0.83 0.51 0.51 0.52
UInt64, runs of 1 (#10) 0.95 0.81 1.08 0.95 0.82
UInt64, runs of 2 0.95 0.81 1.19 1.16 0.82
UInt64, runs of 8 0.95 0.81 0.75 0.75 0.82
UInt64, runs of 100 0.83 0.81 0.62 0.62 0.75
Nullable(UInt64), runs of 1 0.96 0.90 1.06 0.99 0.91
Nullable(UInt64), runs of 2 0.96 0.90 1.28 1.28 0.91
Nullable(UInt64), runs of 8 0.96 0.90 0.70 0.70 0.91
Nullable(UInt64), runs of 32 0.96 0.90 0.55 0.55 0.91

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.

  • A alone helps only where rows are inserted one by one: 0.81x on UInt64 short runs, 0.90x on Nullable(UInt64), where the nested insert stays virtual (a ColumnNullable override that recurses into the nested column takes that to 0.72x). On the blank blocks of BaseDaemon: terminate on double SIGINT #3/doc: fix typo #4/Error fetching data from materialized view #7/Add Dockerfiles for client and server #8 it keeps 0.80-0.86x, versus 0.43-0.64x with bulk inserts.
  • B is the best on runs of 8 and longer, but a 2-row insertRangeFrom / insertManyDefaults costs more than two single inserts, so runs of 2 take 16-28% more instructions than master (12-23% more wall time), devirtualized or not. My first draft of this change used runs too (never pushed) and hit the same regression, which is why the PR uses 64-row chunks.
  • PR+A never takes more instructions than master or the current PR on any of these queries: B's numbers on blank blocks, A's on short runs. On runs of 8 to 100 it stays at A's level, where B is better.

I'd switch the PR to PR+A (the loop in IColumnHelper, with JoinCommon::filterWithBlanks calling it) and push it here after validation, unless you prefer B's numbers on medium runs despite the runs-of-2 regression.

Comment thread src/Columns/ColumnNullable.cpp Resolved
groeneai and others added 2 commits October 19, 2026 13:52
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]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 30fb2bcd3 with master ad36c6520 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

517 object files changed (+187.54 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Columns/IColumn.cpp.o 1.84 MiB 1.96 MiB +120.02 KiB (+6.36%)

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

2652 translation units recompiled, 15590 s compile time in total, 2652 of them have a recent master baseline.

Job report

@groeneai

groeneai commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

Switched the PR to PR+A: 956417d moves the loop into a new IColumn::insertFromOrDefaults implemented in IColumnHelper, and 661380f makes ColumnNullable::insertManyDefaults reserve the whole column first. Re-measured against master 870f005 on the final head (table in the description): #4 0.43x instructions / 0.65x wall, UInt64 runs of 1 to 3 rows 0.82x / 0.82x-0.88x, queries that do not reach the function unchanged; results byte-identical to master on the join battery in release and debug.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 661380f

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (amd_msan) / Logical error: 'persistent_components.format_version == metadata_object->getValue<int>(f_format_version)' (STID: 2508-400e) not from this PR (it changes only the IColumn / ColumnNullable bulk inserts used by JoinCommon::filterWithBlanks): the server-side AST fuzzer read system.iceberg_history across databases and reached an Iceberg table of another test whose metadata had been upgraded to a newer format version while it stayed attached, so the chassert in IcebergMetadata::getHistory aborted the server #126801 (mine, open)
Mergeable Check, PR praktika rollups of the row above #126801 (mine, open)
CH Inc sync - CH Inc sync (private, not actionable by me)

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261019-213007

opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Oct 22, 2026
…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]>
@m-selmi

m-selmi commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

@groeneai figure out where the overhead in A+B on short runs come from. If it's from insertRangeFrom and not from run detection, we can detect runs and fall back to a loop of insertFrom for short runs. Benchmark this new approach.

@groeneai

Copy link
Copy Markdown
Collaborator Author

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 (perf stat, median of 3, process startup subtracted, spread under 0.15%) as a ratio to master; lower is better. PR, A+B, C and D return byte-identical results to master on the 9,756-query join battery.

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:

runs of 2 UInt64 Nullable(UInt64)
A: per-row loop, devirtualized, no run detection 0.83 0.91
runs detected, every run inserted by a loop of insertFrom / insertDefault 1.01 1.06
... kept runs with insertRangeFrom 1.17 1.17
... blank runs with insertManyDefaults 1.12 1.30
... both bulk calls (A+B; 1.20 / 1.35 in its own function) 1.25 1.39

Each 2-row bulk call is an out-of-line insertRangeFrom with a memcpy, or insertManyDefaults with a memset; for Nullable each runs once for the nested column and once for the null map (and insertManyDefaults also reserves both), while the loop inserts inline. On runs of 1, A+B makes no bulk call at all and is still at 1.00 against A's 0.83, so there it is detection alone (countr_zero plus one dispatch per run).

C, your approach: runs detected, a run shorter than 4 rows inserted by a loop of insertFrom / insertDefault, a single row by one call. I used 4: a bulk call starts to win at 4 rows for Nullable(UInt64) and at 5 to 6 for UInt64.

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 popcount per mixed chunk.

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.

query PR A+B C D
UInt64, runs of 1 0.83 / 0.85 1.00 / 0.94 0.97 / 0.96 0.83 / 0.91
UInt64, runs of 2 0.83 / 0.82 1.20 / 1.05 0.94 / 0.89 0.83 / 0.87
UInt64, runs of 3 0.82 / 0.81 1.01 / 0.92 0.88 / 0.82 0.82 / 0.83
UInt64, runs of 4 0.83 / 0.88 0.92 / 0.88 0.92 / 0.91 0.83 / 0.87
UInt64, runs of 6 0.82 / 0.85 0.81 / 0.80 0.81 / 0.79 0.82 / 0.74
UInt64, runs of 8 0.83 / 0.76 0.77 / 0.76 0.77 / 0.75 0.78 / 0.70
UInt64, runs of 32 0.83 / 0.86 0.67 / 0.73 0.67 / 0.74 0.69 / 0.67
UInt64, runs of 100 0.76 / 0.78 0.64 / 0.73 0.64 / 0.73 0.66 / 0.74
Nullable(UInt64), runs of 1 0.92 / 0.97 1.05 / 1.04 1.06 / 1.10 0.92 / 0.98
Nullable(UInt64), runs of 2 0.92 / 0.96 1.35 / 1.19 1.06 / 1.01 0.92 / 0.97
Nullable(UInt64), runs of 3 0.92 / 1.04 1.09 / 1.03 1.02 / 1.05 0.92 / 1.04
Nullable(UInt64), runs of 4 0.92 / 1.03 0.93 / 0.92 0.95 / 0.93 0.92 / 1.03
Nullable(UInt64), runs of 6 0.92 / 1.00 0.78 / 0.79 0.80 / 0.81 0.81 / 0.82
Nullable(UInt64), runs of 8 0.92 / 0.99 0.72 / 0.72 0.73 / 0.73 0.75 / 0.69
Nullable(UInt64), runs of 32 0.92 / 0.97 0.57 / 0.65 0.57 / 0.65 0.60 / 0.61
Nullable(String), runs of 3 0.96 1.00 1.01 0.96
Nullable(String), runs of 8 0.97 0.81 0.82 0.82
Nullable(String), runs of 32 0.96 0.72 0.72 0.74
LowCardinality(String), runs of 1 1.00 1.02 1.02 1.00
LowCardinality(String), runs of 8 1.00 1.02 1.02 1.02
LowCardinality(String), runs of 32 1.00 0.99 0.99 0.99

Queries #3 / #4 / #7 / #8 of join_nullable_keys_small_table are within 0.003 between all four variants (0.53 / 0.44 / 0.64 / 0.53), controls 1.00.

  • C removes only the bulk-call part. It fixes A+B's regression on runs of 2, but detection costs about as much as devirtualization saves, so it stays above the PR on runs of 1 to 4 (UInt64 0.88-0.97 vs 0.82-0.83, Nullable(UInt64) 0.95-1.06 vs 0.92). It wins from runs of 6 on.
  • D matches the PR on runs of 1 to 4 (+0.1% instructions) and gets most of C's gain from runs of 8 (UInt64) or 6 (Nullable) on, up to 0.60 vs 0.92. The exception is LowCardinality(String) with runs of 8: 1.02 vs 1.00, because its insertRangeFrom costs more than eight single inserts. A per-type threshold would fix that, at the cost of more code.

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 IColumn.cpp), I'll switch it.

groeneai and others added 2 commits November 9, 2026 13:26
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]>
@m-selmi
m-selmi added this pull request to the merge queue Nov 16, 2026
Merged via the queue into ClickHouse:master with commit afc888d Nov 16, 2026
187 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-joins JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla... groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants