Repository navigation
Cover the zero-column right side of a cross join in 03827_cross_join_no_right_columns - #107974
Conversation
…zero-column right block When PREWHERE consumes all columns from the right table of a cross join, the right side produces zero-column blocks. Block::rows() returns 0 for such a block, while the real row count is carried by the selector. Commit 545f75c taught addBlockToJoin to use the Chunk's num_rows for the selector size in this case, but the two cross-join guards chassert(rows == block.rows()) (the block compression and spill-to-disk paths) were not updated and aborted the server. The guards exist to assert that no parallel-hash scattering happened for a cross join, i.e. the selector covers the whole block. Allow the legitimate zero-column right block by treating block.columns() == 0 as an accepted case. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-1:20260619-131800 |
|
cc @KochetovNicolai @vdimir — could you review? This relaxes the two cross-join |
|
Workflow [PR], commit [e287431] Summary: ✅ AI ReviewSummaryThis PR is now a test-only regression update for zero-column right-side Final Verdict✅ No blocking findings. |
A follow-up to the previous chassert relaxation in this PR. Relaxing the guards stopped the server abort, but the spill-to-disk path was still wrong for a zero-column right block: tmp_stream serializes block_to_save.rows(), which is 0 when the block has no columns, and the read side reconstitutes the count from block_right.rows(). Block::empty() (== !columns()) is also true for such a block, so the read loop treated the first spilled zero-column block as end-of-stream. Every spilled zero-column right block therefore contributed 0 rows and the cross product was silently undercounted (e.g. 24576 instead of 300000 with a small max_rows_in_join). The real row count of a zero-column block lives only in the selector, which cannot survive the Block-serializing temporary stream. Such a block has no column data to spill anyway (its only in-memory cost is a fixed-size selector, independent of the row count), so route it to the in-memory path where the selector carries the count. The spill path then never sees a zero-column block, so its guard returns to the strict chassert(rows == block.rows()). Extends 03827_cross_join_no_right_columns with a spill-forcing case (small max_rows_in_join + max_block_size, compression disabled) that fails before this change and passes after. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (HEAD c260686, spill-path fix)
Session id: cron:clickhouse-worker-slot-2:20260619-145100 |
CI summary (HEAD
|
| Check | Failure | Classification |
|---|---|---|
Stateless tests (arm_binary, parallel) |
03518_alter_logical_race |
Flaky. 30d: 13 FAIL across 11 unrelated PRs, 0 master. Timing artifact (slow MODIFY mutation under max parallel contention crosses the test's 120s per-query cap); the test author is actively tuning it. Unrelated to this change. |
Stress test (amd_debug) |
Hung check failed, possible deadlock found | Chronic-trunk Hung-check deadlock (30d: 279 master hits across many builds). Pre-existing, tracked separately. Unrelated to this change. |
CH Inc sync / Mergeable Check are downstream aggregators of the above, not independent failures.
|
@groeneai The test |
|
@rschu1ze The PR fixes two things, both for
So
So yes: primarily wrong results, plus a debug/sanitizer abort. The title names only the LOGICAL_ERROR. Happy to (a) widen the title/changelog to state both symptoms, and/or (b) add a comment in the test noting queries 2-4 also cover the formerly-aborting path. Let me know which you prefer. |
There was a problem hiding this comment.
Bugfix validation passed, but shows Failed: 0, Passed: 0, Skipped: 0, @groeneai please check if there any issue with the check. And test should reproduce issue we trying to solve as mentioned above
|
@vdimir The From the job.log of that exact run:
Reproduced locally with an A/B on the same debug source (only HashJoin.cpp differs):
Why you and @ rschu1ze do not see a LOGICAL_ERROR: The PR fixes both symptoms of the same zero-column-right-block cause: the abort (debug/sanitizer) and the silent CROSS JOIN undercount on the spill path (all builds). I updated the PR description to state both. Given the above, I do not think there is a way to turn this into |
|
@vdimir Can we merge this one? |
|
It will likely also be fixed by #108289, but we need to add a test anyway, so let's merge the PR, hopefully no major conflicts with that one |
|
@vdimir The regression test is already included. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 15/15 (100.00%) · Uncovered code |
CI finish ledger - 0a606daCI fully finished on this head (@vdimir's master-merge to prep the merge). Every failure below has an owner.
Session id: cron:our-pr-ci-monitor:20260723-170000 |
…ws-assert Resolve the conflict in src/Interpreters/HashJoin/HashJoin.cpp in favour of master. PR ClickHouse#108289 extracted the cross join into src/Interpreters/ConstantJoin.cpp and the code this PR changed no longer exists in HashJoin::addBlockToJoin: the spill branch became ConstantJoin::trySpillRightBlock, which already bails out on block_to_save.columns() == 0, and the two chassert(rows == block.rows()) guards are gone. Both fixes of this PR are therefore already upstream, so only the regression test remains.
The query added for the multi-block right side used `PREWHERE a >= 0 AND b != ''`. An always-true comparison on an unsigned column is constant folded away, so the right side kept the `b.size` subcolumn and never became zero-column: it covered the ordinary spill path instead of the representation under test. With identical settings and max_bytes_in_join = 1000, `a >= 0` reports ExternalJoinWritePart = 1 while `a > 0` reports 0, which is the zero-column block being kept in memory. Use `a > 0` (and shift the data so every row qualifies), and assert the plan shape with EXPLAIN so the query cannot silently stop covering the zero-column right side again. Pin the join order, because the test runner randomizes it and with t2_big on the left the build side becomes the single block t1_big; unpinned, the order swapped in 20 of 20 runs while every assertion still passed. Add a row limit reached exactly between two right blocks, with `index_granularity` pinned so the accounting lands on a block boundary. That is the point where a zero-column block would be spilled and its rows lost: dropping the `columns() == 0` early return from the spill decision makes the query return 15000 instead of reporting the limit. With the default granularity the first block already overshoots the limit and both variants report it, so the boundary has to be pinned for the assertion to discriminate. Drop the compression settings the previous version passed, along with the byte thresholds. A zero-column block allocates nothing, so no byte threshold can fire, and compressing one loops over zero columns, so neither had an observable effect to assert.
Head branch was pushed to by a user without write access
|
Resolved the conflict with master and reduced this PR to the test. #108289 moved the cross join into Two things I found while checking the test still covers anything:
Dropped the compression and byte-threshold settings the old version passed: a zero-column block 50 randomized runs pass on a binary whose source is identical to master. |
The assertion added in the previous commit checked the join output header for __join_result_dummy. That column is synthesized by JoinStepLogical whenever the join has no required output columns (JoinStepLogical.cpp addToNullableIfNeeded, the `if (outputs.empty())` branch), which is a property of the SELECT list, not of the right side. It happened to discriminate the constant-folded `a >= 0` shape only because that shape leaves `b.size` as the single surviving output column, so the join output header names it instead of the dummy. That is an incidental property of this query, not a robust one: any shape where the surviving column comes from the left side would keep the dummy in the output header while the right side still fed a non-empty block into the join. Assert on the right pre-join input header instead, via EXPLAIN input_headers = 1. `ClickHouse#1 Empty header` is printed exactly when the right input header has no columns (QueryPlan.cpp explainStep, the `input_header->empty()` branch), which is the representation under test. The new form discriminates four mutations where the old one discriminated two: the constant-folded `a >= 0` shape, a swapped join order, selecting a right column so PREWHERE no longer consumes all of them, and dropping PREWHERE entirely. Reported by clickhouse-gh[bot].
CI finish ledger - fbe4bc2Every 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
This PR is test-only now (both source fixes landed upstream via #108289), and it touches only Session id: cron:our-pr-ci-monitor:20260726-200000 |
|
Fixing PR for the Root cause is in the test itself, not in this PR and not in the engine. The test fires three Session id: cron:clickhouse-review-slot-54:20260728-023400 |
The test fires three concurrent wait_for_async_insert=1 HTTP inserts, then issues an explicit SYSTEM FLUSH ASYNC INSERT QUEUE after sleep 2. flush(tables) is a snapshot which, unlike flushAll, deliberately does not set flush_stopped, so a concurrent push can create a new queue entry immediately after it. When the third insert has not yet been appended at that moment, the flush drains a partial batch of two and the late insert lands in a fresh entry whose only remaining trigger is its 600s async_insert_busy_timeout_ms, so its waiting client parks until curl gives up after 120s. That is the observed failure: Code: 27 plus 2 of 4 rows, all_1_1_0 with 2 rows, and curl: (28) Operation timed out with 0 bytes received. sleep 2 does not prevent it, since bash forks the three background children and reaches it immediately. Deleting both lines restores async_insert_max_query_number = 3 as the sole trigger, which is order-independent: entries are appended unconditionally at push time (the malformed one counts too), so whichever request arrives third completes the batch and flushes all three atomically. Both lines were added by PR ClickHouse#89140; the failure first appears in CI after that merge, so this is a revert of that PR's test-side half. No assertion is weakened - the settings, the three inserts, the Code: 27 check and the reference file are unchanged, and the single-part assertion gets stronger. The test also stops paying an unconditional 2 second sleep. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107974&sha=fbe4bc270336b23fbb9759890a617bd1519ec25f&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 Related PR: ClickHouse#107974 Co-Authored-By: Claude Opus 5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
CI finish ledger - 4259d73CI is fully finished on this head. The single failure below has an owner. Gates: no check queued/in_progress/pending;
Attribution and causal link, since the assertion site alone would not settle it. The abort is at
That test creates a table carrying exactly two text indexes over the same Map column - Fix-presence probed per build rather than inferred from commit distance: Breadth (90d, base_repo pinned): 3 rows total across this and the older STID 2508-50dc bucket, 0 master rows, all carriers bystanders. Below the flaky threshold, and the defect class is already owned at P0 by the #111422 work that #111467 closes. Session id: cron:our-pr-ci-monitor:20260815-070000 |
|
🕵 @groeneai, the remaining CI failure is unrelated to this test-only PR: |
|
Investigated #111467. The
Fix presence measured per build rather than by commit distance: One gap I have not closed: that probe shows the fix is absent from the failing build, not that it handles this exact fuzzed EXPLAIN. I will run the query from #111467 is green on |
…in-cross-zero-column-rows-assert
CI finish ledger - b9ec5fcEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
62 checks report to the CI database with 0 FAIL/ERROR rows across 114227 rows, the praktika Session id: cron:our-pr-ci-monitor:20260816-030000 |
…in-cross-zero-column-rows-assert
…in-cross-zero-column-rows-assert
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Related: #108289
This PR is now test only.
It started as a fix for a
chassert(rows == block.rows())abort inHashJoin::addBlockToJoin, hitby a cross join whose right side has zero columns because PREWHERE consumed all of them, plus a
silent undercount of the cross product when such a block was spilled to disk. #108289 extracted the
cross join into
src/Interpreters/ConstantJoin.cpp, and both fixes are already there:ConstantJoin::trySpillRightBlockreturns early forblock_to_save.columns() == 0, and neitherchassertexists any more. The conflict with master was resolved in favour of master, so only theregression test remains, which is the part that was asked for anyway.
The test needed a fix of its own. Its multi-block queries used
PREWHERE a >= 0 AND b != '', and analways-true comparison on an unsigned column is constant folded away: the right side then keeps the
b.sizesubcolumn and is not zero-column at all. Withmax_bytes_in_join = 1000and everything elseequal,
a >= 0reportsExternalJoinWritePart = 1whilea > 0reports0, which is thezero-column block being kept in memory. The queries now use
a > 0, and anEXPLAINassertion pinsthe plan shape so they cannot silently stop covering the zero-column right side again.
The join order is pinned as well, because the test runner randomizes it and with
t2_bigon the leftthe build side becomes the single block
t1_big: unpinned, the order swapped in 20 of 20 runs whileevery assertion still passed.
A row limit that is reached exactly between two right blocks is added, with
index_granularitypinnedso the accounting lands on a block boundary. That is the point where a zero-column block would be
spilled and its rows lost: dropping the
columns() == 0early return from the spill decision makesthe query return
15000instead of reporting the limit. With the default granularity the first blockalready overshoots the limit and both variants report it, so the boundary has to be pinned for the
assertion to discriminate.
The compression and byte-threshold settings the test used to pass are gone. A zero-column block
allocates nothing, so no byte threshold can fire, and compressing one loops over zero columns, so
neither had an observable effect to assert.
Verified with 50 randomized runs on a binary whose source is identical to master.
Version info
26.8.1.1542(included in26.8and later)