Repository navigation
Fix Invalid number of rows in Chunk in JoiningTransform with additional join filter - #106928
Conversation
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-7:20260610-072600 |
|
cc @vdimir could you review this? It is a test-only PR adding a stateless regression test for a rare BuzzHouse-found |
|
Workflow [PR], commit [b9318a1] Summary: ✅
AI ReviewSummaryThe fix in src/Interpreters/HashJoin/HashJoinMethodsImpl.h closes the row-count invariant that was still broken in the non-replication additional-filter path: once the probe loop stops early at Final Verdict
|
|
Update: I found a deterministic single-threaded reproducer, so this is a real master-HEAD bug, not a non-reproducing artifact. The flaky-check on this PR confirmed it (the added test crashed the server under msan/tsan), and I then reduced it to: SELECT t1.generate_series
FROM numbers(41712) AS t0
LEFT JOIN generateSeries(5297, 67368) AS t1
ON (t0.number <= t1.generate_series) AND (t1.generate_series = t0.number)
FORMAT Null
SETTINGS max_joined_block_size_rows = 1000;About 100% abort on a debug build, with Mechanism: in Because the test reliably crashes the server, it should not be merged as a passing stateless test until the code is fixed. I am working on the fix to the accounting in that path, after which the test will pass and serve as the regression guard. Full details are in the updated PR description. |
…al filter and small max_joined_block_size_rows
A LEFT JOIN whose right keys are unique gets promoted to RIGHT ANY
(MapsAll, need_replication = false). When such a join also has a mixed
ON condition referencing both tables (equality plus an inequality), the
probe goes through HashJoinMethods::joinRightColumnsWithAdditionalFilter.
In that path added_columns.filter is allocated for the full selector size
(selector.size()) whenever need_filter is set, which happens when a right
key column is selected (has_required_right_keys). The probe loop can break
early at max_joined_block_size_rows, so it processes only a prefix of the
left rows and returns that smaller left_block_rows. The trailing resize of
added_columns.filter was done only under "if constexpr (need_replication)".
For the RIGHT ANY case need_replication is false, so the filter kept the
full selector size while the left block was cut to left_block_rows
downstream. The required right key column is rebuilt from this oversized
filter via filterWithBlanks, producing a column larger than its siblings,
which trips Chunk::checkNumRowsIsConsistent (LOGICAL_ERROR
"Invalid number of rows in Chunk ... in JoiningTransform").
Trim added_columns.filter to left_block_rows in the non-replication case as
well, so the required right key column matches the left block size.
Reproduces deterministically on a debug build with
max_joined_block_size_rows = 1000:
SELECT t1.generate_series
FROM numbers(41712) t0
LEFT JOIN generateSeries(5297, 67368) t1
ON (t0.number <= t1.generate_series) AND (t1.generate_series = t0.number)
Found by the server-side BuzzHouse fuzzer (STID 3366-2d1d) on master,
amd_msan. The error sizes observed in CI (matched count vs full left size:
e.g. 6297 vs 41712, 19265 vs 24515, 27810 vs 41712) match this root cause.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
a4d2594 to
fba8b16
Compare
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-1:20260610-113200 |
|
cc @vdimir @KochetovNicolai — could you review this? It fixes a |
The regression test uses a mixed JOIN ON condition (equality plus an inequality: t0.number <= t1.generate_series). That shape is only supported by the new analyzer; the old analyzer rejects it in CollectJoinOnKeysMatcher with INVALID_JOIN_ON_EXPRESSION (code 403). The CI old-analyzer variant therefore failed on this test (return code 147). Tag the test no-old-analyzer so it only runs under the new analyzer, which is the path the fixed bug lives on. Code unchanged; this only adjusts the test's run tags. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pushed a follow-up commit (7b91eab) adding The CI old-analyzer variant ( Code is unchanged from the approved commit (fba8b16) — this only adjusts the test's run tags. Verified locally: under |
|
Dear @vdimir, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
Backport #106928 to 26.7: Fix Invalid number of rows in Chunk in JoiningTransform with additional join filter
…ingTransform with additional join filter
Backport #106928 to 26.6: Fix Invalid number of rows in Chunk in JoiningTransform with additional join filter
|
@vdimir wdyt about backporting it to earlier versions? |
|
Let's try, added |
Backport #106928 to 25.8: Fix Invalid number of rows in Chunk in JoiningTransform with additional join filter
Backport #106928 to 26.3: Fix Invalid number of rows in Chunk in JoiningTransform with additional join filter
Backport #106928 to 26.5: Fix Invalid number of rows in Chunk in JoiningTransform with additional join filter
…nk in JoiningTransform with additional join filter
…nk in JoiningTransform with additional join filter
…nk in JoiningTransform with additional join filter
A
LEFT JOINwith unique right keys is promoted toRIGHT ANY(need_replication = false). When such a join also has a mixedONcondition (equality plus inequality), the probe goes throughjoinRightColumnsWithAdditionalFilter. Thereadded_columns.filteris sized for the full selector when a right key column is selected, but the probe loop can break early atmax_joined_block_size_rowsand return a smallerleft_block_rows. The trailingfilter.resize(left_block_rows)was only done underneed_replication, so for theRIGHT ANYcase the filter kept the full size while the left block was cut downstream. The required right key column rebuilt from the oversized filter then mismatched its siblings, trippingChunk::checkNumRowsIsConsistent(LOGICAL_ERRORinJoiningTransform).Fix: trim the filter to
left_block_rowsin the non-replication case too.Deterministic repro on debug with
max_joined_block_size_rows = 1000:Found by the server-side BuzzHouse fuzzer on master, amd_msan (STID 3366-2d1d).
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix a
LOGICAL_ERROR(Invalid number of rows in Chunk) inJoiningTransformfor aLEFT JOINwith unique right keys, a mixedONcondition, and a smallmax_joined_block_size_rows.Version info
26.8.1.461(included in26.8and later)26.7.2.46,26.6.2.141,26.5.7.7,26.3.17.110,25.8.29.51