Repository navigation
Conversation
…htAny joinRightColumnsWithAdditionalFilter builds the per-left-row filter at the full input block size, then can shrink left_block_rows to the matched rows and returns that reduced count, which the caller uses to scatter the block. It only resized filter to left_block_rows under need_replication, so a LEFT RightAny join (need_replication=false) left filter at the full block size. Downstream copyLeftKeyColumnToRight then applied the oversized negated null map to the shrunk left key column, aborting with 'Null map of size N does not match ColumnNullable of size M'. Resize filter whenever it was built (need_filter), not only under need_replication, so it stays in the same row space as the scattered block. Author: Groene AI <[email protected]> Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-1:20260720-083700 |
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings across 1 full pass + 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-1:20260720-083700 |
|
cc @nickitat @rschu1ze — could you review this? |
|
Workflow [PR], commit [f95f794] Summary: ✅ AI ReviewSummaryThis PR is now a test-only regression case for the Findings
Final Verdict |
CI finish ledger — b682a82 (HashJoin additional-filter RightAny null-map fix)CI fully finished (Finish Workflow SUCCESS, 20-min ingest buffer met). Every failure below has an owner; none is PR-caused (this PR touches only
Session id: cron:our-pr-ci-monitor:20260720-150000 |
|
Fixing PR for the |
|
@m-selmi Like to check this one? |
|
|
||
| SET enable_analyzer = 1; | ||
|
|
||
| -- No matches: every left row gets defaulted right keys. Used to raise |
There was a problem hiding this comment.
Done, in 220f3d1.
The bug needs four things: a LEFT JOIN whose right table has unique keys, so the strictness is promoted to RightAny; a non-equi ON condition, so joinRightColumnsWithAdditionalFilter runs; a required right key in the output, so need_filter is true at runtime; and the left block to be processed as a prefix, so the scattered block is shorter than filter. Two rows on each side with max_joined_block_size_rows = 1 satisfy all four, so the test is now 2 rows instead of 100000, and it asserts the joined values instead of aggregates over them. The large max_block_size and the cityHash64/coalesce wrappers came from the CI query and were not needed.
Both queries were re-verified in both directions on a debug build: each one alone raises before the fix, the first with Null map of size 2 at offset 0 does not match ColumnNullable of size 1 and the second with the sibling Invalid number of rows in Chunk, and both return the asserted values with the fix, matching an unscattered hash join and grace_hash.
Minimizing did surface something the previous version was also missing. Two of those four conditions are invisible in the results, because with unique right keys the rows are the same whether or not they hold, and if either stops holding the queries quietly stop covering the fixed path: without the promotion the join stays Left ALL, which has need_replication and so was already resized by the guard this fixes. So the test now also asserts them, the promotion from the client log at debug level and the prefix split from JoinProbeTableRowCount, which is 3 for 2 left rows when the split happens. Both assertions were checked to be load-bearing: forcing query_plan_join_swap_table = true reports NOT PROMOTED and dropping max_joined_block_size_rows reports NOT SPLIT: 2. That needs the client log, hence the .sql became a .sh.
query_plan_join_swap_table and use_query_cache are pinned for the same reason: the stress runner randomizes both, swapping makes this a RIGHT join that is never promoted, and a cached result skips the join entirely, so either would make the test pass while testing nothing.
50 runs green, and also green with query_plan_join_swap_table=true, use_query_cache=1 and the block-size settings injected on the command line.
The bug needs only four things: a LEFT JOIN whose right table has unique keys (so the strictness is promoted to RightAny), a non-equi ON condition (so joinRightColumnsWithAdditionalFilter runs), a required right key in the output (so need_filter is true at runtime), and one unmatched left row ahead of a matched one so the additional filter shrinks the block below selector.size(). Two rows on each side with max_joined_block_size_rows = 1 satisfy all four, so the row counts drop from 100000 to 2 and the aggregate wrappers are gone in favour of the joined values themselves. The large max_block_size and the cityHash64/coalesce aggregates in the previous version were incidental to the CI query, not required by the bug. Both queries were re-verified in both directions on a debug build: each one alone aborts before the fix (the first with "Null map of size 2 does not match ColumnNullable of size 1", the second with the sibling "Invalid number of rows in Chunk") and both return the values asserted here with the fix, matching an unscattered hash join and grace_hash. Co-Authored-By: Claude Fable 5 <[email protected]>
The comments said the additional filter drops trailing left rows. It does not: the loop breaks once the pre-filter candidate count reaches max_joined_block_size_rows, before buildAdditionalFilter runs, and the caller splits the remaining left rows into a following block rather than discarding them. Say that instead, and shorter. Comments only, no behaviour change. Co-Authored-By: Claude Fable 5 <[email protected]>
The two result assertions are identical with and without the split, so on their own they would keep passing if the join stopped splitting the block and the queries silently stopped covering the fixed path. Add an oracle for it: the deferred left row is probed again in the following block, so JoinProbeTableRowCount is 3 for 2 left rows when the split happens and 2 when it does not. Verified load-bearing by dropping max_joined_block_size_rows from the first query, which turns it into "fail: 2". The RightAny promotion itself is decided after the build phase and is not exposed through EXPLAIN, a ProfileEvent or a system table, so it has no SQL oracle; the promotion is what makes need_replication false, which is the condition the resize guard turned on, so it stays covered only in the sense that the queries abort without the fix. Also quote the diagnostic in full, including "at offset 0". Co-Authored-By: Claude Fable 5 <[email protected]>
Swapping the tables makes this a RIGHT join. Promotion to RightAny only happens for inner and left joins, and RIGHT ALL has need_replication, which the guard already resized, so with the swap neither query reproduces: on a pre-fix build they return the expected rows instead of raising. The stress runner injects query_plan_join_swap_table=true, so without the pin the test would silently pass in that configuration while covering nothing. Verified in both directions on a pre-fix build: with the pin the test still raises even when query_plan_join_swap_table=true is passed on the command line, and with the pin removed the same run returns the expected rows. Co-Authored-By: Claude Fable 5 <[email protected]>
The bug needs two conditions that the results themselves cannot show, since they are the same either way: the strictness has to be promoted to RightAny, and the block has to be split. The previous version asserted only the split, so the test would still pass if promotion stopped happening, and then it would cover nothing: without promotion the join stays Left ALL, which has need_replication and so was already resized by the guard this fixes. Promotion is decided after the build phase and is not in EXPLAIN, a ProfileEvent or a system table, but it is logged, so assert it from the client log at debug level. That needs a shell test, hence the .sql becomes a .sh. Each assertion was checked to be load-bearing: forcing query_plan_join_swap_table = true reports "NOT PROMOTED", and dropping max_joined_block_size_rows reports "NOT SPLIT: 2". Co-Authored-By: Claude Fable 5 <[email protected]>
The probe-count assertion runs the first query a second time, and the query cache key does not include the query id, so with use_query_cache = 1 the second run is served from the cache, never reaches the join, and reports "NOT SPLIT: 0". The stress runner enables the cache, so pin it off. The assertion itself also needs the pin, because reading a system table with the cache on throws unless query_cache_system_table_handling is set. Verified by removing the pin with the cache enabled, which reports "NOT SPLIT: 0", and with it in place the test passes both with the cache enabled bare and with the settings the stress runner passes alongside it. Co-Authored-By: Claude Fable 5 <[email protected]>
shell_config.sh always puts --send_logs_level into $CLICKHOUSE_CLIENT, and the client rejects the option given twice, so appending a second one made the promotion query fail with "Bad arguments" and the pipeline read that as "NOT PROMOTED". It happened to pass locally only because the test runner adds --allow_repeated_settings, which it does not always do. Replace the existing option instead, as 00653_verification_monotonic_data_load.sh does. Checked at every log level the runner can pass (warning, error, fatal, information) with a client built by shell_config.sh and no --allow_repeated_settings: the previous form reports "NOT PROMOTED" and this one reports "promoted". Co-Authored-By: Claude Fable 5 <[email protected]>
The Style check requires every query to system.query_log to carry a current_database = currentDatabase() predicate, and the split assertion added in the previous commit read the log filtered only by query_id. The query_id already embeds $CLICKHOUSE_DATABASE, so the extra predicate cannot select a different row; it was verified to be a live predicate and not decoration by pointing it at a database that does not exist, which turns the assertion into NOT SPLIT: 0. Co-Authored-By: Claude Fable 5 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 0/0 (nothing coverable) · Uncovered code |
CI finish ledger - d7bae74CI is fully finished on this head: 174 check-runs, all completed, 1 red. Every failure below has an owner.
The aborting query is Session id: cron:our-pr-ci-monitor:20260730-030000 |
|
@groeneai Also simplify the comment in the code to and make it obvious truncation happens because of |
…onal-filter-rightany-null-map-3452-37cd # Conflicts: # src/Interpreters/HashJoin/HashJoinMethodsImpl.h
| # the need_replication path that always resized `filter`, so neither query below would reproduce. | ||
| # The query cache is off because the same query runs more than once here, and serving it from the | ||
| # cache skips the join, which the assertions at the end would read as the join having changed. | ||
| SETTINGS="SETTINGS enable_analyzer = 1, query_plan_join_swap_table = false, use_query_cache = 0, join_algorithm = 'hash', max_joined_block_size_rows = 1" |
There was a problem hiding this comment.
This split oracle still depends on an unpinned probe chunk shape. The JoinProbeTableRowCount == 3 check below only holds if numbers(2) reaches JoiningTransform as a single 2-row block; if a caller runs the shell test with max_block_size = 1 (or any future suite-level override below 2), the join stays correct but this query reports 2 and the test fails with NOT SPLIT.
Please pin max_block_size = 2 here (or opt the script out with no-random-settings) so the split assertion is guaranteed by the test itself rather than by current runner defaults.
There was a problem hiding this comment.
This is still block-shape dependent in the current .sql test.
JoinProbeTableRowCount is incremented once per incoming probe chunk in JoiningTransform::readExecute (src/Processors/Transforms/JoiningTransform.cpp:245), and joinRightColumnsWithAdditionalFilter only produces a follow-up next_block after one chunk contributes more than max_joined_block_size_rows candidates (src/Interpreters/HashJoin/HashJoinMethodsImpl.h:945-983).
At tests/queries/0_stateless/04612_left_join_additional_filter_right_any_scatter.sql:45, the reproducer uses unique right keys, so each left row contributes at most one candidate. If a suite-level max_block_size <= 256 reaches numbers(1000), the join sees probe chunks of at most 256 rows, never emits a next_block, and JoinProbeTableRowCount stays exactly 1000. The result rows and the RightAny log check on lines 60-71 still stay green, so the test stops covering the truncated-prefix path that triggered the original bug.
Please pin max_block_size > 256 here, or opt the test out of random max_block_size, so line 45 remains a real split oracle.
There was a problem hiding this comment.
I measured this rather than reason about it, and I disagree: line 45 holds its value across the whole max_block_size range, and the state that would move it is both unreachable and self-announcing.
The probe input is re-batched before the counter. EXPLAIN PIPELINE puts a SimpleSquashingTransform between the source and JoiningTransform, built at src/Processors/QueryPlan/JoinStepLogical.cpp:1072-1073 from min_joined_block_size_rows / min_joined_block_size_bytes (defaults 65409 / 524288), not from max_block_size. The source does honour max_block_size (blockSize() is 1 at max_block_size=1 versus 1000 at the default), but the blocks are coalesced again before JoiningTransform.cpp:245 increments the counter. Measured JoinBuildTableRowCount / JoinProbeTableRowCount at max_block_size = 1, 64, 128, 200, 255, 256, 257, 300, 512, 1000, 1001, 4096, 8000, 8192, 65409, 100000: 2 / 2464 in every arm, so split and promoted both read 1 throughout.
A suite-level value at or below 256 is not reachable. tests/clickhouse-test:1438 is "max_block_size": lambda: random.randint(8000, 100000); I extracted that generator and drove it 2,000,000 times, giving min=8000, max=100000, zero draws at or below 256. tests/integration/helpers/random_settings.py:7 has the same 8000 floor, and this is a 0_stateless test. min_joined_block_size_rows is set by no randomizer, no --client-option path and no file under tests/config/.
The value you predict is a failure, not a silent pass. probe_rows only drops to 1000 when min_joined_block_size_rows is lowered and max_block_size is small: min_joined_block_size_rows=1 with max_block_size=256 gives 2 / 1000 and split=0, likewise with max_block_size=1, while min_joined_block_size_rows=1 on its own stays at 2464. So 1000 > 1000 is false and the row fails loudly. That matches the comment above it, which already documents 1000 as the unsplit value.
I also checked the one channel that can reach min_joined_block_size_rows, since its entry sits in the 25.7 block of SettingsChangesHistory.cpp:605 and ci/jobs/scripts/stress/stress.py:240 randomizes compatibility at p=0.2. It reverts the setting to 0, and 0 means unlimited per the setting's own description, so the squash still happens: compatibility 25.6, 24.1 and 20.1 give 0 while 25.7, 25.8 and 26.6 give 65409. The full test still matches its reference under compatibility=25.6 combined with max_block_size=256 and with max_block_size=1, under compatibility=24.1 with max_block_size=200, and under compatibility=26.6 with max_block_size=256.
Given that, a pin would not change any outcome I can produce, so I am leaving the test as it is.
Per review feedback, replace the shell test with a plain .sql test built on the two simplified queries from the review, plus a third case where the ON condition holds so the assertions are not all-default. The `enable_analyzer = 1` and `query_plan_join_swap_table = false` pins are required: the old analyzer rejects the non-equi ON condition with INVALID_JOIN_ON_EXPRESSION, and swapping the tables makes this a RIGHT join, which is not promoted to RightAny and never reaches the truncated prefix, so without the pin the queries stop covering the fixed path on stress runs that inject the swap. Each of the three queries reproduces on a build without the `filter.resize(left_block_rows)` call: query 1 and 3 raise "Null map of size 1000 at offset 0 does not match ColumnNullable of size 256" and query 2 the sibling "Invalid number of rows in Chunk ... expected 256, got 1000".
Review of the SQL conversion found two ways the test could stop covering the fixed path without the reference changing. Stress runs inject join_use_nulls, which decides whether the right key becomes Nullable and therefore which of the two errors the queries raise, so each query now pins the value it needs. The aggregates are identical under both values, so the reference alone could not detect the flip. The aggregates are also identical whether or not the join is promoted to RightAny and whether or not the block is split, so the test now reads JoinBuildTableRowCount and JoinProbeTableRowCount for the first query from system.query_log. The right table is the build side with 2 rows only while the join is not swapped, and 1000 left rows are probed more than 1000 times only while the block is split. A swapped join reads 1000 build rows and 3 probes, and an unsplit one probes exactly 1000, so either loss fails the assertion.
|
Done in 08a47c9, all three points.
One residual worth your call. The aggregates are the same whether or not the promotion and the block split happen, so I assert both from Verified both directions on one tree: removing the |
The profile-event assertion covered only the block split. HashJoin::onBuildPhaseFinish decides the promotion to RightAny from the data alone, and it is reported by no setting, profile event or query result, so a plain LEFT ALL join on the same unique right keys reads the same 2 build rows and splits the same way. The test could therefore have kept passing while no longer exercising the need_replication = false path the regression needs. Assert the message the promotion logs instead, joined to the query through query_id, the pattern 04029_join_convert_to_fixed_hash_table.sql already uses. Verified that inverting the all_values_unique gate in onBuildPhaseFinish leaves every aggregate row and the split assertion green while turning only the new row from 1 to 0. Co-Authored-By: Claude Fable 5 <[email protected]>
A swapped RIGHT ALL join can still stop at the candidate limit. It is safe because that path replicates, and the replication branch has always resized the filter; the earlier wording said it never reaches the truncated prefix at all. Co-Authored-By: Claude Fable 5 <[email protected]>
Per the repository instructions, literal names from the ClickHouse SQL language, classes and functions, and literal excerpts from log messages go inside inline code blocks. Co-Authored-By: Claude Fable 5 <[email protected]>
|
@m-selmi can this be merged? |
|
@PedroTadim This PR has no approval yet. @m-selmi is out, he can check after return next week. The issue exists already in 26.5 and 26.4. Therefore, it is by definition not a "26.6 blocker". I think we should remove it from the corresponding board. |
I just lowered the status, and thinking about removing it. |
CI finish ledger - f95f794CI is fully finished on this head and there is nothing to own: 174/174 check-runs completed, 57 success, 117 skipped, 0 failures.
Verified from the paginated check-runs API rather than the status rollup, which truncates on this repo. I am not re-pinging reviewers. Session id: cron:our-pr-ci-monitor:20260803-163000 |
Related: #106928
Related: #110048
Related: #112153
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
This is now a test-only PR. The source fix it originally carried was superseded by #106928, which landed the equivalent
filterresize injoinRightColumnsWithAdditionalFilteron 2026-07-30. After merging master, this branch's copy ofsrc/Interpreters/HashJoin/HashJoinMethodsImpl.his byte-identical to master, so only the regression test remains.The test is still worth keeping because it covers a different assertion than #106928's. Both bugs come from the same missing resize, but they surface through different columns. On a build with the resize removed, #106928's
04330_join_global_left_semi_chunk_consistency.sqlraisesInvalid number of rows in Chunk, while this test raisesNull map of size 2 at offset 0 does not match ColumnNullable of size 1(STID 3452-37cd) throughColumnNullable::applyNullMapImplinHashJoinResult::generateBlock. That is the signature seen in CI on unrelated PRs #79393 and #110048, and no existing test reaches it: it needsjoin_use_nulls = 1and a nullable right key, which #106928's test does not use.The test asserts results, plus the two conditions the coverage depends on: that the strictness really was promoted to
RightAny, and that the block really was split. The promotion needs its own assertion becauseHashJoin::onBuildPhaseFinishdecides it from the data alone and reports it through no setting, profile event or result, so the profile counters cannot stand in for it: a plainLEFT ALLjoin on the same unique right keys reads the same build rows and splits the same way. It is asserted from thesystem.text_logmessage keyed byquery_id, the pattern04029_join_convert_to_fixed_hash_table.sqlalready uses. Both conditions were mutation-tested: inverting theall_values_uniquegate leaves every result row and the split assertion green while turning only the promotion row from 1 to 0.Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110048&sha=6f8f79fc6c7b7d0d43e2df0722a387d7d69755cc&name_0=PR&name_1=Stress%20test%20%28amd_debug%29
Version info
26.8.1.925(included in26.8and later)