Skip to content

Cover the zero-column right side of a cross join in 03827_cross_join_no_right_columns - #107974

Merged
alexey-milovidov merged 13 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-hashjoin-cross-zero-column-rows-assert
Aug 17, 2026
Merged

alexey-milovidov merged 13 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-hashjoin-cross-zero-column-rows-assert

Conversation

@groeneai

@groeneai groeneai commented Jun 19, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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 in HashJoin::addBlockToJoin, hit
by 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::trySpillRightBlock returns early for block_to_save.columns() == 0, and neither
chassert exists any more. The conflict with master was resolved in favour of master, so only the
regression 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 an
always-true comparison on an unsigned column is constant folded away: the right side then keeps the
b.size subcolumn and is not zero-column at all. With max_bytes_in_join = 1000 and everything else
equal, a >= 0 reports ExternalJoinWritePart = 1 while a > 0 reports 0, which is the
zero-column block being kept in memory. The queries now use a > 0, and an EXPLAIN assertion pins
the 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_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.

A row limit that is reached exactly between two right blocks is added, 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.

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

  • Merged into: 26.8.1.1542 (included in 26.8 and later)

…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]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. CREATE TABLE t1 (x UInt64) ENGINE=MergeTree ORDER BY x; CREATE TABLE t2 (a UInt64, b String) ENGINE=MergeTree ORDER BY a; INSERT INTO t1 VALUES (1),(2),(3); INSERT INTO t2 SELECT number, toString(number) FROM numbers(100000); SELECT count() FROM t1, t2 PREWHERE a >= 0 AND b != '' SETTINGS enable_analyzer=1, cross_join_min_rows_to_compress=1, max_block_size=1000, max_threads=1; aborts the server every run with Logical error: 'rows == block.rows()' (compress branch, same assertion as the CI stress hit at the spill branch).
b Root cause explained? Yes. PREWHERE consuming all right columns of a cross join makes the right side emit zero-column blocks; Block::rows() is 0 for those, so commit 545f75c passes the real count via the Chunk's num_rows into the selector (rows = selector.size() = num_rows > 0). The two cross-join guards chassert(rows == block.rows()) (compress + spill paths) were not updated by that commit, so once getTotalRowCount() crosses the compress/spill threshold (from the 2nd right block on) the guard fires chassert(num_rows == 0) and aborts.
c Fix matches root cause? Yes. The guards exist to detect parallel-hash scattering (selector not covering the whole block). The fix relaxes them to `chassert(rows == block.rows()
d Test intent preserved / new tests added? Yes. Extended 03827_cross_join_no_right_columns (the test added by 545f75c) with two multi-block queries that hit the compress-by-rows and compress-by-bytes paths. The original zero-row-result assertion is untouched.
e Both directions demonstrated? Yes. Without the fix the repro aborts at HashJoin.cpp (compress branch); with the fix it returns the correct 300000, and clickhouse-test --test-runs 50 03827_cross_join_no_right_columns passes 50/50 with full randomization (cross_join_min_rows_to_compress is randomized to {0,1,1e8}). Binary identity verified (Build ID changed 873edc17 -> fc8618ed, matches the running test server).
f Fix is general, not a narrow patch? Yes. Both sibling cross-join guards in addBlockToJoin (the in-memory compress path and the spill-to-disk path, the latter being the exact line CI aborted on) get the identical fix. These are the only two chassert(rows == block.rows()) sites in the function. The fix targets the shared invariant, not one call site.

Session id: cron:clickhouse-worker-slot-1:20260619-131800

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @KochetovNicolai @vdimir — could you review? This relaxes the two cross-join chassert(rows == block.rows()) guards in HashJoin::addBlockToJoin (compress + spill paths) to also accept a zero-column right block. When PREWHERE consumes all right columns, the right side emits zero-column blocks whose row count lives in the selector (per 545f75c), so block.rows() is 0 while rows is the real count, which aborted the server in the cross-join compress/spill paths.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e287431]

Summary: ✅


AI Review

Summary

This PR is now a test-only regression update for zero-column right-side CROSS JOINs. In the current diff, the test pins the randomized join-order settings, proves that the right input really collapses to an empty header via EXPLAIN input_headers = 1, and adds a row-limit case that would flip from SET_SIZE_LIMIT_EXCEEDED to a wrong result if zero-column blocks started spilling again. I did not find a remaining correctness or determinism gap in the present change.

Final Verdict

✅ No blocking findings.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 19, 2026
Comment thread src/Interpreters/HashJoin/HashJoin.cpp Resolved
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]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate (HEAD c260686, spill-path fix)

# Question Answer
a Deterministic repro? Yes. CREATE TABLE t1_big (x UInt64) ENGINE=MergeTree ORDER BY x; CREATE TABLE t2_big (a UInt64, b String) ENGINE=MergeTree ORDER BY a; INSERT INTO t1_big VALUES (1),(2),(3); INSERT INTO t2_big SELECT number, toString(number) FROM numbers(100000); SELECT count() FROM t1_big, t2_big PREWHERE a >= 0 AND b != '' SETTINGS max_rows_in_join=5000, max_block_size=1000, max_threads=1, cross_join_min_rows_to_compress=0, cross_join_min_bytes_to_compress=0; returns 24576 instead of 300000 every run on the pre-fix binary (ExternalJoinWritePart=1 confirms the spill branch was taken).
b Root cause explained? Yes. A zero-column right block (PREWHERE consumed all right columns) carries its row count only in the selector. The spill branch wrote block_to_save to tmp_stream, which serializes Block::rows() == 0 for a columnless block; the read side reconstitutes the count from block_right.rows(), and Block::empty() (== !columns()) is true, so the read loop also treated the first spilled zero-column block as end-of-stream. Every spilled zero-column right block thus contributed 0 rows and the cross product was silently undercounted.
c Fix matches root cause? Yes. The block's real count cannot survive the Block-serializing temporary stream, and the block has no column data to spill anyway (only a fixed-size selector). So the spill branch now excludes zero-column blocks (block_to_save.columns() != 0) and routes them to the in-memory path, where the selector preserves the count. Targets the mechanism, not the symptom.
d Test intent preserved / new tests added? Yes. Extended 03827_cross_join_no_right_columns with a spill-forcing case (small max_rows_in_join + max_block_size, compression disabled). The earlier zero-row and compress-path assertions are untouched.
e Both directions demonstrated? Yes. Pre-fix binary (Build ID 1798aa21) returns 24576; fixed binary (994bd7ed) returns 300000. Fast loop: 50/50 runs return 300000. Robustness: 15 combinations of max_rows_in_join x max_block_size, plus spill+compress combined and max_threads=4, all return 300000. Normal-column cross join that spills still returns the correct count.
f Fix is general, not a narrow patch? Yes. The cross-join in-memory path already handled zero-column blocks via the selector; the only remaining place the count could be lost was the spill branch, which this change closes. With zero-column blocks kept in memory, the spill guard returns to the strict chassert(rows == block.rows()). These are the only two cross-join row-count sites in addBlockToJoin.

Session id: cron:clickhouse-worker-slot-2:20260619-145100

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI summary (HEAD c260686cd8a1)

CI fully finished (Finish Workflow SUCCESS). Two non-PR-caused failures, both pre-existing and tracked elsewhere; neither touches this PR's diff (src/Interpreters/HashJoin/HashJoin.cpp + 03827_cross_join_no_right_columns):

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.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107974&sha=c260686cd8a1c2d48fe5ccc6f065f050e7a728de&name_0=PR

@rschu1ze

Copy link
Copy Markdown
Member

@groeneai The test 03827_cross_join_no_right_columns.sql does not trigger a LOGICAL_ERROR. What are we trying to solve here? Wrong results?

@groeneai

Copy link
Copy Markdown
Collaborator Author

@rschu1ze The PR fixes two things, both for CROSS JOIN when PREWHERE consumes all right-table columns (the right side then emits zero-column blocks, whose row count lives only in the selector, not in Block::rows()):

  1. Server abort LOGICAL_ERROR: 'rows == block.rows()' from the two cross-join chassert guards in HashJoin::addBlockToJoin (in-memory compress + spill-to-disk paths). chassert only fires in debug/sanitizer builds (base/base/defines.h; it is compiled out otherwise), so you will not see the abort on a release/RelWithDebInfo build, only on debug/asan/tsan. The stress fuzzer hit it on Stress test (arm_tsan) (STID 2508-362f).

  2. Wrong results (undercount), in all builds. This is the part clickhouse-gh[bot] surfaced in review. On the spill-to-disk path the temp stream serializes Block::rows() == 0, and the read side reconstitutes the count from block_right.rows() == 0, so every spilled zero-column right block contributes 0 rows (and Block::empty() stops the read at the first such block). Commit c260686 fixes it by not spilling zero-column blocks: they go to the in-memory path where the selector carries the count.

So 03827_cross_join_no_right_columns is primarily a wrong-results regression test:

  • query 1 (6): the original std::out_of_range in getTotalRowCount() from 545f75c (independent of the assert/spill issue).
  • queries 2-3 (300000): in-memory compress path. On the strict-assert code (master) a debug/sanitizer build aborts here (the LOGICAL_ERROR); a release build already returned the correct count, since the selector carries it.
  • query 4 (300000): spill path. Both symptoms there: a debug/sanitizer build aborts on the strict assert, and a release build silently undercounts (measured 24576 on the intermediate relaxed-assert build, with ExternalJoinWritePart=1). Post-fix it is 300000.

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.

@vdimir vdimir left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107974&sha=c260686cd8a1c2d48fe5ccc6f065f050e7a728de&name_0=PR&name_1=Bugfix+validation+%28functional+tests%29

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

@groeneai

Copy link
Copy Markdown
Collaborator Author

@vdimir The 0/0/0 is not a check defect: the test is selected and it does reproduce the bug, but as a server abort, and a crash emits no per-test row, so the counter stays at zero. The job is still green because the harness records the crash via the inverted "Server died" row, i.e. "reproduced".

From the job.log of that exact run:

  • Test selected: Test list: [['03827_cross_join_no_right_columns.']].
  • It ran against the master baseline (amd_asan_ubsan, commit 994f9d3, abort_on_logical_error active). The server aborted mid-test ("Unable to locate any ClickHouse server process. It must have crashed or exited prematurely!"), then StopTesting. No OK/FAIL test rows were emitted, hence Failed: 0, Passed: 0, Skipped: 0.

Reproduced locally with an A/B on the same debug source (only HashJoin.cpp differs):

  • Master baseline binary (both guards strict): the first query aborts with Logical error: 'rows == block.rows()' at HashJoin::addBlockToJoin (HashJoin.cpp:764). Server dies.
  • This PR's binary: the three queries return 300000, server stays up.

Why you and @ rschu1ze do not see a LOGICAL_ERROR: chassert is compiled out on release/RelWithDebInfo, so the abort only fires on debug/asan/tsan/msan, which is exactly what bugfix-validation runs and where the stress fuzzer found it (STID 2508-362f). All four bugfix-validation build types are sanitizer/debug, so on them the bug can only surface as the crash, never as a countable result mismatch: any triggering query aborts the server before a row is recorded. So 0/0/0 plus green is the expected "reproduced via crash" signature here, not a non-reproduction. The spill-path wrong-results undercount (24576 vs 300000) is the all-builds symptom, but it is only countable on a release build, which this check does not run.

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 Passed: 1 under the current sanitizer-only validation matrix. If you want a more legible signal, I can split the crash repro into its own test file so the validation log clearly attributes the "Server died" to it; or leave it as is. Let me know what you prefer.

@rschu1ze

Copy link
Copy Markdown
Member

@vdimir Can we merge this one?

@vdimir

vdimir commented Jul 23, 2026

Copy link
Copy Markdown
Member

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
vdimir enabled auto-merge July 23, 2026 11:16
@groeneai

Copy link
Copy Markdown
Collaborator Author

@vdimir The regression test is already included. 03827_cross_join_no_right_columns covers both zero-column cross-join paths: the in-memory compress path (aborts on debug/sanitizer without the fix) and the spill-to-disk path (q4 asserts the full product 300000 vs the pre-fix undercount 24576, ExternalJoinWritePart=1). It checks results at the SQL level, so it stays valid regardless of how #108289 reworks the HashJoin internals.

@clickhouse-gh

clickhouse-gh Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 78.30% 78.30% +0.00%

Changed lines: Changed C/C++ lines covered: 15/15 (100.00%) · Uncovered code

Full report · Diff report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 0a606da

CI fully finished on this head (@vdimir's master-merge to prep the merge). Every failure below has an owner.

Check / test Reason Owner
Finish Workflow / Post Hooks (new_tests_check.py: "No per-arch Bugfix Validation job validated the bug") bugfix-validation harness limitation (all 3 Bugfix-validation jobs concluded SUCCESS; the debug/sanitizer chassert abort reproduces the bug via server crash, which records no per-test OK/FAIL row so the arch jobs report 0/0/0). Discussed and accepted with @vdimir (2026-06-23 approval) and @rschu1ze; systemic across 30+ unrelated Bug Fix PRs. Accepted-by-reviewer; PR being merged as-is. Regression 03827_cross_join_no_right_columns covers both the compress path (debug abort) and the spill path (release undercount 300000 vs 24576).
Integration tests (amd_tsan, 3/6) / test_replicated_database test_replicated_table_structure_alter flaky (chronic trunk: 1524 FAIL across 20+ unrelated PRs + master, 30d; retry_ok this run) - unrelated to this PR (HashJoin cross-join fix) fixing PR #109245 (@alexey-milovidov new-approach fix, open)
Mergeable Check / PR rollup of the above owned via the two lines above
CH Inc sync - CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260723-170000

groeneai added 2 commits July 26, 2026 11:41
…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.
auto-merge was automatically disabled July 26, 2026 15:02

Head branch was pushed to by a user without write access

@groeneai

Copy link
Copy Markdown
Collaborator Author

Resolved the conflict with master and reduced this PR to the test.

#108289 moved the cross join into src/Interpreters/ConstantJoin.cpp, and both fixes of this PR are
already there: ConstantJoin::trySpillRightBlock returns early for block_to_save.columns() == 0,
and neither chassert(rows == block.rows()) exists any more. The conflict was exactly that hunk
against its removal, so I resolved it in favour of master. Changelog category is now CI Fix or Improvement.

Two things I found while checking the test still covers anything:

  1. It did not. The multi-block queries used PREWHERE a >= 0 AND b != '', and an always-true
    comparison on an unsigned column is constant folded away, so the right side kept the b.size
    subcolumn and was never zero-column. With max_bytes_in_join = 1000 and everything else equal,
    a >= 0 reports ExternalJoinWritePart = 1 while a > 0 reports 0, which is the zero-column
    block being kept in memory. Fixed by using a > 0, plus an EXPLAIN assertion on the plan shape
    so it cannot silently drift again.

  2. The join order and the block boundaries have to be pinned. Unpinned, the runner's join-order
    randomization swapped the sides in 20 of 20 runs, making the build side the single-block t1_big
    while every assertion still passed. And the row limit only discriminates when the accounting lands
    exactly between two right blocks: with index_granularity = 1000, dropping the columns() == 0
    early return returns 15000 instead of reporting the limit, whereas with the default granularity
    the first block overshoots and both variants report it.

Dropped the compression and byte-threshold settings the old version passed: a zero-column block
allocates nothing so no byte threshold can fire, and compressing one loops over zero columns.

50 randomized runs pass on a binary whose source is identical to master.

@clickhouse-gh clickhouse-gh Bot added pr-ci and removed pr-bugfix Pull request with bugfix, not backported by default labels Jul 26, 2026
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].
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - fbe4bc2

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
Stateless tests (arm_binary, parallel) / 02015_async_inserts_2 flaky async-insert flush hang: curl: (28) Operation timed out after 120001 milliseconds, only 2 of 4 rows land and one insert never acks. Confirmed on master (2026-07-21 amd_tsan, 2026-05-04 amd_tsan) and on unrelated PRs, so not caused by this PR. Runner re-ran it 22/22 green with the same randomized settings. a fix task is created (investigating at full effort - fixing PR link to follow on this PR)
Mergeable Check / PR derivative rollups of the line above resolved by the owner above

This PR is test-only now (both source fixes landed upstream via #108289), and it touches only 03827_cross_join_no_right_columns, so it cannot affect async inserts.

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

Session id: cron:our-pr-ci-monitor:20260726-200000

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the Stateless tests (arm_binary, parallel) / 02015_async_inserts_2 line of the CI
finish ledger above: #112214

Root cause is in the test itself, not in this PR and not in the engine. The test fires three
concurrent wait_for_async_insert=1 HTTP inserts and then issues an explicit
SYSTEM FLUSH ASYNC INSERT QUEUE. That flush only snapshots the queue and, unlike flushAll, does
not stop concurrent pushes, so when the third insert has not registered yet the flush drains a
partial batch of two and the late insert is left waiting on its 600 s
async_insert_busy_timeout_ms, which the 120 s curl timeout kills first. Removing the flush
restores async_insert_max_query_number = 3 as the sole, order-independent trigger.

Session id: cron:clickhouse-review-slot-54:20260728-023400

vikashkumar2020 pushed a commit to vikashkumar2020/ClickHouse that referenced this pull request Jul 30, 2026
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]>
@alexey-milovidov alexey-milovidov self-assigned this Aug 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e2874318f with master 41453250d (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
Binary Master PR Δ
programs/clickhouse-stripped 694.55 MiB 691.54 MiB -3.01 MiB (-0.43%)

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 units

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

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 4259d73

CI is fully finished on this head. The single failure below has an owner.

Gates: no check queued/in_progress/pending; Config Workflow = success, Finish Workflow = success; >20 min elapsed for CIDB ingestion. Coverage verified from the praktika report rather than the skip ratio: result_pr.json 177 leaves, 59 OK / 117 SKIPPED / 0 DROPPED, so the run is genuinely finished with real coverage (the high skip count is expected for a test-only diff, and every skip carries a reason).

Check / test Reason Owner / fixing PR
Stress test (arm_msan) / Logical error: 'cols.size() == required_columns.size()' (STID 2508-458e) lazy-materialization required_columns desync from an orphaned text-index virtual column; not caused by this diff #111467 (ours, open)

Attribution and causal link, since the assertion site alone would not settle it. The abort is at optimizeLazyMaterialization.cpp:620 chassert(cols.size() == required_columns.size()) in optimizeLazyMaterialization2, reached through InterpreterExplainQuery::executeImpl() under the client AST fuzzer. This PR's diff is two files, both test-only (03827_cross_join_no_right_columns.sql/.reference), so it cannot reach that path.

fatal.log gives the fuzzed query and, decisively, log_comment = '04039_text_index_map_values_subcolumn.sql-test_2':

EXPLAIN ANALYZE compact = 0 SELECT id FROM tab
PREWHERE ('frontendfrontendfrontendfrontend') IN (map['service'])
WHERE (map['service']) IN toNullable(('frontend'))
ORDER BY id DESC NULLS LAST LIMIT 934

That test creates a table carrying exactly two text indexes over the same Map column - idx_mv mapValues(map) and idx_mk mapKeys(map) - and queries it via the map['service'] subscript with a LIMIT. That is the shape #111467 fixes: TextIndexDAGReplacer::replace leaves a virtual recorded for a rewritten predicate in result.added_columns after removeUnusedActions() drops its input, the orphan reaches the read header, and lazy materialization then indexes required_columns positionally past its end. So this is the same defect, not merely the same assertion.

Fix-presence probed per build rather than inferred from commit distance: used_virtual_columns in src/Processors/QueryPlan/Optimizations/optimizeDirectReadFromTextIndex.cpp = 0 at this head and 0 at master, 4 at #111467's head 2e4ba088ede7. This build predates the fix, and #111467 is still open, so no master merge is owed here.

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

@alexey-milovidov

alexey-milovidov commented Aug 15, 2026 •

Copy link
Copy Markdown
Member

🕵 @groeneai, the remaining CI failure is unrelated to this test-only PR: Stress test (arm_msan) hit the existing lazy-materialization assertion cols.size() == required_columns.size() in optimizeLazyMaterialization2. It is tracked by #111422, with a fix in progress at #111467. Please investigate the linked fix and provide any needed follow-up in that separate PR.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Investigated #111467. The arm_msan abort here is the same defect it fixes, not a second one.

fatal.log for query_id 5791fe47 carries log_comment = '04039_text_index_map_values_subcolumn.sql-test_2', and that test creates two text indexes over one Map column (mapValues(map) plus mapKeys(map)) queried through the map['service'] subscript with a LIMIT. That is the precondition in #111422. The desync is created in the optimizer pass, so InterpreterExplainQuery is a second way to reach the same corrupted plan rather than a distinct bug.

Fix presence measured per build rather than by commit distance: used_virtual_columns in optimizeDirectReadFromTextIndex.cpp is 0 at this PR's head and 0 at master, and 4 at #111467's head 2e4ba088ede7. The failing build predates the fix, so the recurrence is expected.

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 fatal.log against the pre-fix and fix binaries, and if it confirms, add an EXPLAIN-shaped arm to 02346_text_index_bug111422 in #111467. That is the only follow-up I see needed there; I will report the result in #111467.

#111467 is green on 2e4ba088ede7 and mergeable, with no review yet since Aug 8.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - b9ec5fc

Every failure below has an owner: a fixing PR (ours 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
(none) CI is fully green on this head no failures to own
CH Inc sync - CH Inc sync (private, not actionable)

62 checks report to the CI database with 0 FAIL/ERROR rows across 114227 rows, the praktika
report is PR = OK with 0 non-OK children of 177 and no failing leaf at any depth, and both
Config Workflow and Finish Workflow are success. Coverage is real: 12 builds, Fast test,
about 30 stateless suites (including the s3-storage, distributed-plan, WasmEdge and flaky-check
variants) and Stress test (amd_asan_ubsan) all ran and passed.

Session id: cron:our-pr-ci-monitor:20260816-030000

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 17, 2026
Merged via the queue into ClickHouse:master with commit 01575fe Aug 17, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 17, 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 pr-ci 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