Skip to content

Faster hash joins on wide multi-column keys and String mixes - #129328

Merged
harikrishnan94 merged 14 commits into
ClickHouse:masterfrom
harikrishnan94:siphash128-join-keys
Nov 11, 2026
Merged

harikrishnan94 merged 14 commits into
ClickHouse:masterfrom
harikrishnan94:siphash128-join-keys

Conversation

@harikrishnan94

@harikrishnan94 harikrishnan94 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Related: #129204
Related: #128972

A hash join keeps its right rows in the hashed map when its keys are, for example, several columns that do not fit in 32 bytes together, or a String with other columns. The map stores each row under hash128, the 128-bit SipHash of its key values.

master, hashed and two_level_hashed maps
  key        hash128 of one row at a time
             one virtual updateHashWithValue call per key column
             one serial chain of SipHash rounds per row
  build      parallel_hash hashes each right row twice:
             once to pick its slot, once to insert it
  prefetch   off: a prefetch would hash every row a second time

The key getter of these maps now builds the keys of many rows at once.

this PR
  key        the keys of up to 256 rows are built at once
             a batched SipHash hashes 8 rows side by side (NEON on aarch64, AVX2 on x86)
             the same bytes as hash128, so every key is the same
  build      the scatter of a right block builds its keys once, and the slots insert with them
  prefetch   on: the prefetch and the lookup read the same built key

For a user:

  1. Joins on the hashed map are faster. These are keys of several columns that do not fit in 32 bytes, a String with other columns, Tuple keys, and null-safe <=> keys on Nullable columns. The keys do not change, so the results do not change either.
  2. There is no setting. Builds without NEON or AVX2, and big-endian builds, keep hashing one row at a time.
  3. Key columns other than numbers, Decimal, FixedString, String, and Tuple and Nullable of these, keep hash128 per row. Examples are Array, Map and a LowCardinality inside a Tuple.
  4. enable_software_prefetch_in_join now covers the hashed maps too. The prefetch leaves out the rows that the join skips: those with a NULL key or a false ON condition.
  5. IN sets, the runtime filters and the other join maps are unchanged.

Sample joins, clickhouse local, median of 5 runs, each in a new process:

CREATE TABLE r ENGINE = MergeTree ORDER BY tuple() AS SELECT
    number AS x, x AS k1, x * 3 AS k2, x * 5 AS k3, x * 7 AS k4, x * 11 AS k5,
    rightPad(concat(toString(x), '_'), 16 + intHash32(x) % 25, 'k') AS s40, x * 13 AS u,
    substring(hex(intHash64(x)), 1, intHash32(x * 7 + 1) % 16) AS s15,
    if(x = 0, NULL, toNullable(s40)) AS ns, x AS v
FROM numbers(10000000);
OPTIMIZE TABLE r FINAL;
-- l: the same columns for x = (number * 2654435761) % 20000000, 10M rows, so about half of the left rows match.
--    In l, ns is NULL where x % 100 = 1 or x = 0.

SELECT count(), sum(r.v) FROM l INNER JOIN r ON l.s40 = r.s40 AND l.u = r.u
SETTINGS join_algorithm = 'parallel_hash', max_threads = 16,
    max_bytes_before_external_join = 0, max_bytes_ratio_before_external_join = 0, query_plan_join_swap_table = 'false';

The keys:

  1. 5 x UInt64: l.k1 = r.k1 AND l.k2 = r.k2 AND l.k3 = r.k3 AND l.k4 = r.k4 AND l.k5 = r.k5
  2. String of 16-40 bytes and UInt64: l.s40 = r.s40 AND l.u = r.u
  3. String of 0-15 bytes and UInt64: l.s15 = r.s15 AND l.u = r.u
  4. null-safe Nullable(String): l.ns <=> r.ns
  5. OR of 2) and 1), with join_algorithm = 'hash', the only algorithm that runs it

INNER JOIN on m8g.24xlarge (Graviton 4), master → this PR:

Keys 1 thread 16 threads 96 threads
1) 5990 → 3522 ms (0.59) 491 → 325 ms (0.66) 192 → 180 ms (0.94)
2) 5150 → 2973 ms (0.58) 459 → 250 ms (0.54) 128 → 118 ms (0.92)
3) 4709 → 2185 ms (0.46) 391 → 197 ms (0.50) 145 → 113 ms (0.78)
4) 5080 → 2091 ms (0.41) 391 → 168 ms (0.43) 118 → 91 ms (0.77)
5) 11151 → 5260 ms (0.47) 859 → 426 ms (0.50) 191 → 127 ms (0.66)

INNER JOIN on c6i.24xlarge (Xeon 8375C, AVX2):

Keys 1 thread 16 threads 96 threads
1) 6165 → 3862 ms (0.63) 640 → 460 ms (0.72) 263 → 212 ms (0.81)
2) 6296 → 3796 ms (0.60) 533 → 347 ms (0.65) 233 → 198 ms (0.85)
3) 5385 → 3026 ms (0.56) 498 → 291 ms (0.58) 219 → 174 ms (0.79)
4) 5472 → 2858 ms (0.52) 486 → 266 ms (0.55) 169 → 116 ms (0.69)
5) 12440 → 7040 ms (0.57) 1042 → 555 ms (0.53) 330 → 232 ms (0.70)

On Graviton 4, LEFT ANY JOIN takes 0.38-0.49 of the master time at 1 and 16 threads, and 0.60-0.91 at 96 threads. With 100K right rows, the ratios are 0.59-0.83 at 1 thread and 0.79-1.06 at 96 threads. At 96 threads such a query takes 30-91 ms, and the master binary differs from a copy of itself by up to 14 %.

Reading order: HashMethodHashedJoinKey and PreparedJoinKeys in KeyGetter.h -> HashedJoinKey::buildRange -> sipHash128PaddedFixedStrings and sipHash128PaddedStrings -> the prepareRows calls in insertSlotRows and joinRightColumns -> buildAllKeys in scatterImpl -> usePrebuiltKeys.

The key getter:

  1. It hashes the same bytes as hash128, in the same order. SipHash of a byte stream does not depend on how the stream is split into update calls, so a batched key equals the per-row key. The two kinds can meet in one map. That happens on the per-row fallback, and when the build and the probe pick different layouts for the same map. An example is a Tuple(LowCardinality(String)) key, which is still LowCardinality at the build but String at the probe. Debug and sanitizer builds check every key against hash128.
  2. It picks a layout once, from its key columns. The disjuncts of an OR join can have different key columns, so each disjunct gets its own. A key of one fixed-width column, such as Tuple(UInt64), is hashed where it is, like a FixedString column. Several fixed-width columns are copied side by side into rows, 256 rows at a time, and hashed the same way.
  3. A key with a String or a Nullable column is copied into a buffer laid out like a String column. Each row gets the bytes that hash128 hashes. For a String these are its size plus one, its chars and a zero byte. For a Nullable they are the null flag, then the value if it is not NULL. A chunk ends after 256 rows or 64 KiB, and a longer row is hashed by itself.
  4. The columns of a Tuple count as key columns of their own. A Nullable column is copied when its nested column is a number, Decimal, FixedString or String. A null-safe a <=> b on Nullable columns reaches the hashed map as such a Tuple(Nullable(T)). The column types are checked by exact type: a ColumnConst or a ColumnUnique reports the isFixedAndContiguous of its nested column.
  5. A join loop calls prepareRows before it creates its prefetcher. The getter then builds the keys chunk by chunk as the loop reads them, and keeps the last 32 keys of a chunk for the prefetch look-ahead. With or without prefetch, the loop passes the rows with a NULL key or a false ON condition as skipped, and the prefetch leaves them out. When at least one row in 8 of a chunk is skipped, the getter copies and hashes only the other rows.
  6. A list of rows in ascending order, such as the build of an ASOF join with a Nullable ASOF column, gets its keys built from the first listed row to the last, with the other rows skipped. An OR join with a condition in ON looks up every map for every row it does not skip, so it prepares the keys of every map.
  7. With parallel_hash, scatterImpl builds the keys of the whole right block to route its rows to the slots. The slots insert the rows with these keys. Each slot builds the key of its first row again and compares it, and a mismatch throws a LOGICAL_ERROR.
  8. The layout code is in HashedJoinKey.cpp and does not depend on the mapped type, so the many instances of the join loops share it.

Changelog category (leave one):

  • Performance Improvement

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

Hash joins whose keys use the hashed hash table, such as several columns that do not fit in 32 bytes or a String with other columns, are faster: they hash the keys of 8 rows at a time with NEON on aarch64 and AVX2 on x86, and they prefetch the hash table. The keys and the results do not change.


Workflow [PR]
Sync PR [sync-upstream/pr/129328]

Version info

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

@harikrishnan94 harikrishnan94 added the can be tested Allows running workflows for external contributors label Nov 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7b748c7]

Summary: ✅


AI Review

Summary

PR #129328, reviewed at 7b748c76a197ab9b0b639a0e9c8297421df7bdaf, batches hash128 key construction for the hashed join maps, reuses keys between parallel scatter and insertion, and enables software prefetching. No actionable findings in the current diff. The supplied benchmarks support the performance claim, and the added regression tests cover the affected key layouts and join paths.

Missing context / blind spots
  • ⚠️ Runtime validation at this head remains incomplete: the full CI suite is pending, and Fast test skipped 05494_join_hashed_keys and 05508_join_hashed_keys_prefetch. No local build or tests were run. Confirm those tests pass in the subsequent stateless and sanitizer jobs before merging.
Final Verdict

Status: ✅ Approve — no review findings; pending CI must still pass.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Nov 4, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-joins JOINs end-to-end (planning hooks + runtime join operators/algorithms). Single bucket to avoid pla... label Nov 4, 2026
@harikrishnan94
harikrishnan94 force-pushed the siphash128-join-keys branch 2 times, most recently from 34d9342 to c4bada7 Compare November 4, 2026 22:07
harikrishnan94 and others added 5 commits November 5, 2026 07:53
`PreparedJoinKeys` is a base for the hash join key getters that can build
the keys of many rows in one call, for example to hash several keys at a
time. No key getter uses it yet, so the joins behave as before.

When a parallel build scatters the rows of a right block to its slots, a key
getter with this base builds the key of each row once, with `buildAllKeys`,
and the scatter takes the slot from the bucket of that key. The slot inserts
read these keys through a new parameter of
`HashJoinMethods::insertFromBlockImpl`. Otherwise the scatter and the slot
insert would each build the key of every row.

The other join loops call the key getter's `prepareRows` before they read any
key. For a continuous range of rows, the key getter then builds the keys 256
at a time, each time a read passes the keys built so far. Before it builds the
next keys, it keeps only the last 32 keys built so far. A loop reads the rows
in order, and its lookups trail its prefetch reads by at most 32 rows, so no
loop reads a dropped key. The loops make these calls only under
`if constexpr`, so the code for the other key getters does not change.

Some loops read the rows of a block through a list of row numbers. For
example, an ASOF join whose ASOF column is `Nullable` drops the right rows
with a `NULL` there, so its build reads the other rows through such a list.
Without prepared keys, a prefetching loop would build each key twice: once
for the prefetch and once for the insert. When the list is in ascending
order, the key getter builds the keys of all the rows from the first listed
row to the last one, and passes the rows that are not listed as skipped, so
that it does not have to build their keys. It builds them all at once, not
256 at a time, because the rows left out can make the look-ahead of a
prefetching loop span more than the 32 keys kept between chunks. For a list
in any other order, the key getter builds each key where it is read.

A loop that uses software prefetch builds each key once, for both the
prefetch and the lookup. A loop skips the rows with a `NULL` key or a false
`ON` condition, and it does not prefetch them. It passes skip bytes that mark
these rows to `prepareRows`, so that the key getter does not build their
keys. After a run of 256 or more skipped rows, the next chunk of keys covers
the whole run and the row after it.

When a block has no such rows, the skip bytes are all zero. So a loop that
checks for skipped rows tests one byte per row. A key getter needs no separate
code for a block without skipped rows. The build tests this byte instead of
the `NULL` map and the `ON` mask.

The build skips a row with a `NULL` key. As with the other key getters, such
a row still keeps its right block in memory. For a map that stores one row per
key, each slot insert looks for such rows in the `NULL` map once, before its
loop. The other maps keep every block anyway. The scatter of a parallel build
routes every row by its key, so `buildAllKeys` builds the keys of the skipped
rows too.

A join with `OR` and a condition in `ON` looks up every row that it does not
skip in every map, so it prepares the keys of every map. Any other join with
`OR` prepares the keys of its first map, and with prefetch also those of each
other map that it prefetches for every row. When such a join stops at the
first match, it prefetches its later maps only while enough sampled rows
reach them. It prepares the keys of such a map when it starts to prefetch the
map. When it stops, the map builds each key where it is read again, because
few rows read it.

When the keys are inconsistent, the join throws `LOGICAL_ERROR` instead of
losing or mismatching rows. Prebuilt keys are accepted only by a key getter
with this base, and with one key per row of the block. Each slot insert builds
the key of its first row again and compares it with the prebuilt key. The key
getter throws when it reads a row that was not prepared. The scatter reads the
prebuilt keys through the same `getKeyHolder` and `getBucketOfKey` as for the
other maps, so a slot inserts only into its own buckets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The `hashed` and `two_level_hashed` maps of a hash join store a row under
`ColumnsHashing::hash128` of its key columns. `hash128` hashes one row at a
time, with one virtual `updateHashWithValue` call per column. The new key
getter `HashMethodHashedJoinKey` gives the same keys. Through
`PreparedJoinKeys`, it builds the keys of many rows in one call of
`sipHash128PaddedFixedStrings` or `sipHash128PaddedStrings`, and these
functions hash 8 rows at a time.

Each key getter has a `HashedJoinKey`. It chooses the layout of the hashed
bytes from the key columns of the getter. The maps of an `OR` join have one
map type, but each map has its own key columns.

One fixed-width column is hashed where it is. Several fixed-width columns
are copied into rows, 256 rows at a time. For a key with a `String` column,
the bytes that `hash128` hashes are copied into a buffer laid out like the
chars of a `ColumnString`. A chunk of this buffer ends after 256 rows or
64 KiB, and a longer row is hashed by itself. The layouts take number,
`Decimal`, `FixedString` and `String` columns, and `Tuple`s of them. Any
other key column, a build without NEON or AVX2, and a big-endian build use
`hash128` for each row. A join loop skips the rows with a `NULL` key or a
false `ON` condition. When a chunk of 256 rows has at least 32 such rows, the
layouts copy and hash only the other rows of the chunk.

The keys are those of `hash128`, so the getter needs no setting. They must
be exactly equal. The build and the probe of one map can see different
columns for one key, and so take different layouts: for example
`Tuple(LowCardinality(String))` at the build and `Tuple(String)` at the
probe. Debug and sanitizer builds check every key against `hash128`.

With `parallel_hash`, the scatter of a right block to the slots builds the
keys once with `buildAllKeys`, and the slots insert the rows with these
keys. Before, the scatter hashed each right row, and its slot hashed it
again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A null-safe join key `a <=> b` on nullable columns is wrapped as `tuple(a)`,
unless all keys of the clause are fixed-width and fit in 32 bytes. The
decorrelation of subqueries compares with `<=>` too. Such a
`Tuple(Nullable(T))` key goes to the `hashed` map. There, `HashedJoinKey`
hashed it with `hash128` for each row.

`ColumnNullable::updateHashWithValue` hashes the null flag, and then the
value only if it is not NULL. `HashedJoinKey` now copies these bytes into
the buffer of its `String` layout. So a `Nullable` number, `Decimal`,
`FixedString` or `String` is hashed many rows at a time, like the other key
columns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The join loops issue software prefetches only for a key getter with
`has_cheap_key_calculation`. A prefetching loop reads the key of a row
twice: once for the prefetch and once for the lookup. With `hash128` that
hashed every row twice, so the `hashed` and `two_level_hashed` maps were
never prefetched. `HashMethodHashedJoinKey` builds the keys ahead, and both
reads take the same built key. So it now sets the flag, and a large `hashed`
map is prefetched like the other maps. The prefetch leaves out the rows that
the loop skips, so it does not make the getter hash their keys.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`05494_join_hashed_keys` joins on keys that take each layout of
`HashedJoinKey`, and on keys that it hashes with `hash128` per row. It runs
them with `hash`, `parallel_hash` with 1 and 8 threads, `grace_hash`, a
spilling `parallel_hash` and `auto`. It covers every kind and strictness,
`OR` joins with and without a condition in `ON`, joins that skip many rows
for a `NULL` key or a condition in `ON`, and ASOF joins with a `Nullable`
ASOF column. It also covers block sizes around the chunks of 256 rows,
`joinGet`, and a `Join` table after `DETACH` and `ATTACH`. The keys are the
same as before, so the reference was written by a build without the batched
keys.

`benchmark_hashed_join_key` compares `HashedJoinKey::buildRange` with
`hash128` per row, for several key types.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@harikrishnan94
harikrishnan94 marked this pull request as ready for review November 5, 2026 02:50
Copilot AI balanced review requested due to automatic review settings November 5, 2026 02:50

Copilot AI 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.

🟢 Approval recommended

No active review issues block approval of the batched hashed-join key changes.

No open issues 🎉

What changed in this PR

This PR extends batched SipHash processing to the hashed and two_level_hashed join maps, improving joins on wide composite keys and mixed String keys while preserving existing key hashes.

Changes:

  • Adds batched key construction using existing NEON and AVX2 hashing kernels, with per-row hashing for unsupported layouts and platforms.
  • Reuses prepared keys for parallel-build routing, insertion, lookup, and prefetching, with skip-aware preparation.
  • Adds stateless regression coverage and microbenchmarks for supported key layouts and join paths.
File Description
tests/​queries/​0_stateless/​05494_join_hashed_keys.sh Tests key types, join variants, skipped rows, chunk boundaries, and Join storage.
tests/​queries/​0_stateless/​05494_join_hashed_keys.reference Records expected counts and checksums.
src/​Interpreters/​HashJoin/​KeyGetter.h Adds prepared-key buffering and the hashed join key getter.
src/​Interpreters/​HashJoin/​HashJoinMethodsImpl.h Integrates prepared keys and skip-aware prefetching into join loops.
src/​Interpreters/​HashJoin/​HashJoinMethods.h Extends insertion interfaces to accept prebuilt keys.
src/​Interpreters/​HashJoin/​HashJoin.cpp Builds keys during parallel scatter and passes them to insertion.
src/​Interpreters/​HashJoin/​HashedJoinKey.cpp Implements layout selection, row packing, and batched hashing.
src/​Interpreters/​HashJoin/​benchmarks/​CMakeLists.txt Registers the hashed-key microbenchmark.
src/​Interpreters/​HashJoin/​benchmarks/​benchmark_hashed_join_key.cpp Compares whole-block, chunked, and per-row key construction.
src/​Interpreters/​HashJoin/​AddedColumns.h Declares a shared row-skip helper.
src/​Interpreters/​HashJoin/​AddedColumns.cpp Shares skip-mask construction between build and probe paths.
src/​Interpreters/​CMakeLists.txt Includes the new benchmark directory.
src/​Common/​HashTable/​Prefetching.h Exposes maximum look-ahead for prepared-key retention.

Review effort: Balanced

harikrishnan94 and others added 4 commits November 5, 2026 09:02
`PreparedJoinKeys::buildAllKeys` built the key of every row of the block, even when the selector lists fewer rows. For example, `addBlockToJoin` takes the rows with a `NULL` `ASOF` key out of the selector. The scatter and the slot inserts never read the keys of those rows.

`buildAllKeys` now takes the selector and builds the keys of the listed rows only.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A probe that reaches `max_joined_block_rows` hands the rest of the block to the next call. That call built its first chunk of 256 keys at once. When each key has many matches, a call uses only a few rows, so the other keys were built for nothing and built again by the next call.

The first chunk of a call that starts after the first row of the block now has 8 rows, the group size of `SipHashStrings`. Each next chunk doubles, up to 256 rows.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
`05494_join_hashed_keys` ran for more than 180 seconds in the `amd_tsan` and `amd_msan` flaky checks.

It now runs every key with `hash` and `parallel_hash`. The other algorithms and the join kinds run with a few keys of different layouts. The queries on the table with 150000 rows moved to `05508_join_hashed_keys_prefetch`, so each test has its own time limit. The queries that stay give the same results as before.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129328&sha=829a170e6b4a020ee0f74ae7be83fd25fe74bc34&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The flaky check runs a copy of the changed test on every worker. In the `amd_binary`, `amd_debug`, `amd_tsan` and `amd_asan_ubsan` flaky checks, both tests then take about three minutes, and the check fails a test that takes more than 180 seconds.

Alone, each test takes about three seconds. The targeted checks, which run one copy at a time, pass. The flaky check does not apply the 180 seconds limit to a test with the tag `long`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129328&sha=0d59c0ac264fa546cb080100d2da60eb9d6322eb&name_0=PR&name_1=Stateless%20tests%20%28amd_binary%2C%20flaky%20check%29

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 7b748c76a with master 1dc326280 (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

37 object files changed (+1.64 MiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/InnerHashJoinAny.cpp.o 1.56 MiB 1.62 MiB +52.96 KiB (+3.31%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/InnerHashJoinAsof.cpp.o 1.62 MiB 1.67 MiB +52.70 KiB (+3.17%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/RightHashJoinAsof.cpp.o 1.62 MiB 1.67 MiB +52.68 KiB (+3.17%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/LeftHashJoinSemi.cpp.o 1.53 MiB 1.58 MiB +52.28 KiB (+3.34%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/InnerHashJoinRightAny.cpp.o 1.53 MiB 1.58 MiB +52.27 KiB (+3.34%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/InnerHashJoinAnyMapsAll.cpp.o 2.02 MiB 2.07 MiB +51.85 KiB (+2.51%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/InnerHashJoinAnti.cpp.o 1.44 MiB 1.49 MiB +51.62 KiB (+3.50%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/InnerHashJoinSemi.cpp.o 1.51 MiB 1.56 MiB +51.52 KiB (+3.33%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/FullHashJoinRightAny.cpp.o 2.24 MiB 2.29 MiB +51.28 KiB (+2.23%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/LeftHashJoinSemiMapsAll.cpp.o 1.98 MiB 2.03 MiB +51.25 KiB (+2.53%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/InnerHashJoinRightAnyMapsAll.cpp.o 1.98 MiB 2.03 MiB +51.23 KiB (+2.53%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/RightHashJoinRightAny.cpp.o 2.03 MiB 2.08 MiB +51.22 KiB (+2.46%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/RightHashJoinAnti.cpp.o 1.95 MiB 2.00 MiB +51.15 KiB (+2.56%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/LeftHashJoinAnti.cpp.o 1.53 MiB 1.58 MiB +51.09 KiB (+3.26%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/FullHashJoinAll.cpp.o 2.43 MiB 2.48 MiB +50.48 KiB (+2.03%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/LeftHashJoinAnyMapsAll.cpp.o 2.19 MiB 2.24 MiB +50.40 KiB (+2.25%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/LeftHashJoinRightAnyMapsAll.cpp.o 2.19 MiB 2.24 MiB +50.35 KiB (+2.24%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/FullHashJoinAsof.cpp.o 1.86 MiB 1.91 MiB +50.30 KiB (+2.64%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/LeftHashJoinAsof.cpp.o 1.86 MiB 1.91 MiB +50.30 KiB (+2.64%)
src/CMakeFiles/dbms.dir/Interpreters/HashJoin/FullHashJoinAny.cpp.o 2.15 MiB 2.20 MiB +50.12 KiB (+2.28%)

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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.89, programs/clickhouse-keeper ×1.11 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 7.6 s 17.2 s +10.4 s (+153%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 4.0 s 8.6 s +5.0 s (+142%)
Compile time of recompiled translation units

820 translation units recompiled, 7264 s compile time in total, 819 of them have a recent master baseline.

Job report

@m-selmi m-selmi self-assigned this Nov 5, 2026
@ClickHouse ClickHouse deleted a comment from CLAassistant Nov 5, 2026
…rallel replicas

A query with parallel replicas reads the right table to send it to the replicas,
and a `Join` table with `hashed` keys cannot be read: its keys are not stored
in the map. `master` fails the same way. The `ParallelReplicas` job of the
`05494_join_hashed_keys` test reported this as `UNSUPPORTED_JOIN_KEYS`.

Disable parallel replicas for that one query, as other tests of `Join` tables
do. The rest of the test still runs with them.

Report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/129328/05d06e97a3d41986e3bf129bf06eba38400bd65a/pr/result_stateless_tests_arm_binary_parallelreplicas_s3_storage_parallel.json
Related: ClickHouse#129328

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

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

Should we add an xml performance test? the google benchmark does not run in CI so it can't catch future regressions.

@harikrishnan94

harikrishnan94 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Should we add an xml performance test? the google benchmark does not run in CI so it can't catch future regressions.

Added hashed_join_keys.xml. right_full_parallel_join already hits the hashed map (String + UInt64), and it shows 1.58x on amd and 1.62x on arm in this PR’s perf run.

harikrishnan94 and others added 3 commits November 10, 2026 08:55
Each new case is one `String` column of about 16 MiB, with keys of 192 B up to 160 KiB. The longer the keys are, the fewer rows fit in a chunk of the key builder.

Batched keys beat `hash128` per row up to keys of about 8 KiB. Above that, they trail it by up to 11 %. A key over 64 KiB is already hashed per row.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The `hashed` map holds keys of several columns that do not fit in 32 bytes, a `String` with other columns, and null-safe keys on `Nullable` columns. The test joins on each of them, on an `OR` of two of them, and on `String` keys of about 2 KiB and 12 KiB.

The Google benchmark of `HashedJoinKey` does not run in CI, so it cannot catch a regression. Requested in ClickHouse#129328 (review)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…llel replicas

With `max_threads = 2` in the ParallelReplicas job, `joinGetOrNull('j_s_u64', ...)` failed with `UNKNOWN_TABLE`: `Table default.j_s_u64 does not exist`. The table is in the database of the test, so the queries that call `joinGet` now run without parallel replicas, as the join with the `Join` table already does.

Failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129328&sha=3319ba3a571cf6cce910532cc4d9b350991ce893&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

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

Nice optimization, thanks!

@harikrishnan94
harikrishnan94 added this pull request to the merge queue Nov 11, 2026
Merged via the queue into ClickHouse:master with commit db1dfc2 Nov 11, 2026
188 checks passed
@harikrishnan94
harikrishnan94 deleted the siphash128-join-keys branch November 11, 2026 03:46
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 11, 2026
@Algunenano

Copy link
Copy Markdown
Member

@harikrishnan94

Copy link
Copy Markdown
Contributor Author

@groeneai The DEADLOCK_AVOIDED one is separate from the timeouts. With parallel replicas, INSERT INTO j_s_u64 SELECT ... FROM r goes to the replicas as ~8 sub-inserts with the same initial query id, and StorageJoin::insertBlock takes its lock by initial query id, so when two of them overlap the second is rejected. The Table ... does not exist errors after it come from the client stopping at that insert, so j_tn is never created. 3 unrelated PRs so far, none on master. The result differs failures of this test are only on #130054, which changes how the -0. keys this test checks are handled.

Please raise a PR: in 05494_join_hashed_keys.sh, add SETTINGS enable_parallel_replicas = 0 to the two inserts into the Join tables (j_s_u64 and j_tn), same as the test already does for the joinGet queries.

lazerg pushed a commit to lazerg/ClickHouse that referenced this pull request Nov 12, 2026
The test (added by ClickHouse#129328) sweeps key shapes, join algorithms, join kinds,
key widths and block sizes: about 190 joins of a 3,300-row table with a
3,200-row one. On master its six `Stateless tests (amd_msan, parallel, 3/3)`
runs so far average 288.6 s (max 401.7 s, against the 600 s per-test
timeout), while release takes 6.9 s, debug 5.0 s, asan_ubsan 41.8 s and
tsan 87.6 s (p50). That is far over ClickHouse#115050's bar (mean OK duration above
60 s under MSan), which merged before this test existed.

The cost is the sanitizer's, not a random setting: every query pins its
join algorithm, and the duration follows the test's position in the job
(127 s early in a job, 230-402 s late).

ASan, UBSan, TSan, debug and release keep running it, and in every
debug/sanitizer build `HashedJoinKey::buildRange` still asserts each
batched key against the row-by-row one. MSan stress jobs ignore `no-msan`,
and `05508_join_hashed_keys_prefetch` (mean 61.9 s) stays under MSan.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@harikrishnan94

Copy link
Copy Markdown
Contributor Author

@groeneai No need, raised it here: #130995

Blargian pushed a commit to deeox/ClickHouse that referenced this pull request Nov 12, 2026
…allel replicas

With parallel replicas, an `INSERT ... SELECT` into a `Join` table runs on every replica, and the inserts share the
initial query id. `StorageJoin` takes its write lock by that id, so when two replicas insert at the same time, the second
one fails with `DEADLOCK_AVOIDED`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129209&sha=013785db07d54a273f8795ffd2b6a00f4cb1345f&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29
Related: ClickHouse#129209
Related: ClickHouse#129328

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator

I checked CIDB. Every failure mode of 05494_join_hashed_keys has a merged fix, so I don't see a need to revert #129328:

The other five rows in the report you linked are NOT_FAILED blacklist notices. They have been on master since 2026-09-29 and do not fail the job.

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 15, 2026
Master gained two key encoders that read a `Nullable` null-map byte as a
value, and both must agree with the rest of this PR:

- `HashedJoinKey::buildRows` (ClickHouse#129328) copies the bytes that `hash128`
  hashes, and its own contract is that every way of building a key gives
  exactly `hash128`. This PR makes `ColumnNullable::updateHashWithValue`
  hash `byte != 0`, so after the merge the copied raw byte broke that
  contract: on the merged tree `SELECT count() FROM t l JOIN t r ON l.s <=> r.s`
  over a Native null map with bytes 0, 1 and 2 aborts on the debug check
  in `buildRange` (AVX2 and NEON builds). It now copies `byte != 0`: 500
  rows, where master gives 300.
- `encodeFixedSizeKeys` (ClickHouse#124907) packs NULL into a one-bit field, so a
  byte 2 set the lowest bit of the column before it. With
  `transform_null_in = 1` and a set spilled to disk, `(0, NULL)` was found
  in `{(1, 0)}`: master 10 rows, 0 in memory. The right side is read back
  from the canonical in-memory keys, so only the probe side carried the
  raw byte.

Both are bit-identical on 0/1 maps. 05210 covers both cases, and gains
a `groupUniqArray(tuple(s))` case for the arena key encoder
(`serializeValueIntoArena`), which no case reached: reverting it left
05210 green, now it gives 3 keys where 2 are correct.

05210 also pins `optimize_if_transform_const_strings_to_lowcardinality`
to 0: the runner randomizes it since ClickHouse#80263, and with it `if` returns
`LowCardinality(Nullable(String))`, which has no `.null` subcolumn, so
the `if` case failed with UNKNOWN_IDENTIFIER on half the runs.

05211 is removed: ClickHouse#129812 made the Iceberg null count use
`countBytesInFilter`, so that reader is master's now and the merge drops
it from this PR (05211 passes on master).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
mosya415 pushed a commit to mosya415/ClickHouse that referenced this pull request Nov 22, 2026
The check of the tests a PR adds or changes (ClickHouse#129330) failed a PR only when
a query's time grows run over run on the tested server. A test whose runs
are noisy without a trend passed its own PR, and in master_head PR mode the
report's own unstable/changed verdict never fails a PR. That is how
system_clusters_replicated_databases (ClickHouse#122223) got in: tested-server
spread (stddevPop / median of its runs) 0.41-2.1 in its PR, now > 0.5 on
both master servers in about 99% of runs and the noisiest test on master.

The check now also fails on an unstable query of such a test:

- PR changes only files under tests/ and the reference is the performance
  reference build of the tested master commit's sources (find_prev_build's
  new third value; a reference of an older commit, as in about a quarter
  of PR jobs, does not count): both servers run the same code built the
  same way, so the report's verdict judges the test; fail on changed_fail
  or unstable_fail of report/all-queries.tsv. A query that failed on the
  reference server and ran only on the tested one is not in that file; it
  is judged by the rule below.
- Any other PR or reference (code changes, the official-build fallback, or
  an older reference): the report measures the PR's change, not the test
  (the floors flag 79% of the heads of the 214 code PRs that changed a
  perf test in 2026-11-12..21, their own speedups). Fail when stddevPop /
  median of the tested server's runs is above 0.5 (at least 5 runs). A
  spread the change causes also fails: after the merge both master servers
  run that code.

The bar 0.5 flags 0.5% of those code-PR heads and 0.2% of quiet tests'
master heads (CIDB backtest), and all 4 jobs of ClickHouse#122223. A query the trend
check already reports gets only its trend row. The reading loop of
find_run_trends moves to read_query_runs, shared by both checks;
run_trend_gate becomes changed_tests_gate.

Validated locally on downloaded job logs (no test of the test
infrastructure): ClickHouse#122223's 4 jobs fail (the old check passes them); the
new tests of ClickHouse#129328, ClickHouse#124553, ClickHouse#131203 (code PRs) and the tests-only
ClickHouse#130763, ClickHouse#129627 pass; the run-trend output is unchanged on all 1754 tests
of 14 jobs.

Related: ClickHouse#100759

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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... 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.

6 participants