Repository navigation
Conversation
Pre-PR Validation Gate (Session: cron:clickhouse-ci-task-worker:20260329-091500)a) Deterministic repro? Yes — the AST fuzzer queries from PR #100617's test (GLOBAL NOT IN with join side swap) trigger the LOGICAL_ERROR assertion deterministically in debug builds without the fix. b) Root cause explained? c) Fix matches root cause? Yes — the fix mirrors the exact d) Test intent preserved? Yes — the assertion still checks exact column count equality. No bounds widened, no tags added, no assertions removed. The only change is correct accounting for cross-side overlap. e) Both directions demonstrated? Test passes 20/20 with fix. All 6 locally-runnable join-duplicate tests (00577, 03707, 02497, 02267, 02381, 00370) that PR #100617 breaks pass 60/60 with this fix. |
|
cc @vdimir @KochetovNicolai — could you review this? It fixes the P0 recurring STID 2980-385f crash in |
|
Workflow [PR], commit [0ec03d1] Summary: ❌
AI ReviewSummaryThis PR fixes a ClickHouse Rules
Final Verdict
|
| <= toInt64(materialize(9223372036854775807)) | ||
| FORMAT Null | ||
| SETTINGS enable_analyzer = 1 | ||
| " 2>&1 | grep -v -c 'LOGICAL_ERROR' > /dev/null |
There was a problem hiding this comment.
This check is not reliable for detecting LOGICAL_ERROR.
grep -v -c 'LOGICAL_ERROR' > /dev/null succeeds whenever there is any non-matching line, so a real LOGICAL_ERROR can be masked by other stderr lines (for example Received exception from server/query context lines).
Please make this assertion explicit, e.g.:
... 2>&1 | grep -q 'LOGICAL_ERROR' && exit 1
# or
... 2>&1 | (! grep -q 'LOGICAL_ERROR')The same pattern appears again below in this file.
After join side swapping (e.g., LEFT ANTI → RIGHT ANTI via GLOBAL NOT IN), column names can appear in both the left block and sample_block_with_columns_to_add. AddedColumns correctly skips right-side columns whose renamed name already exists in the left block, but the assertion in getNonJoinedBlocks computed the expected column count as a naive sum (left + right_keys + columns_to_add) without accounting for this cross-side overlap. The fix counts right-side columns whose renamed name appears in the left block (matching the exact deduplication logic in AddedColumns) and subtracts this overlap from the expected count. Unlike the NameSet-based approach in PR ClickHouse#100617, this preserves within-left duplicate column names which are legitimate in queries with subqueries. Fixes STID 2980-385f — P0 recurring AST fuzzer crash hitting 20+ PRs and master over the last 12 days.
- Replace NameSet::count() with NameSet::contains() for membership checks
(clang-tidy readability-container-contains diagnostic)
- Fix test assertion: use `{ ! grep -q 'LOGICAL_ERROR'; }` instead of
`grep -v -c 'LOGICAL_ERROR' > /dev/null` which could mask LOGICAL_ERROR
presence when other stderr lines exist
5b6ba62 to
1160719
Compare
|
@groeneai create minimal repro |
|
@vdimir Minimal repro (crashes the server with LOGICAL_ERROR on current master): SELECT 1 FROM numbers(1)
WHERE number >= CAST((SELECT number), 'Int64')
AND number <= 0
SETTINGS enable_analyzer = 1;What happens: Variants also crash (from recent AST fuzzer findings in CIDB, simplified): -- Table with correlated subquery in WHERE (CIDB 2026-04-03, PR #99736)
CREATE TABLE t (a Int32, b String) ENGINE = MergeTree ORDER BY a;
INSERT INTO t VALUES (1, 'x'), (42, 'y');
SELECT * FROM t
WHERE b <= (SELECT if(a > 2, b, 'z'))
OR (a = 42)
SETTINGS enable_analyzer = 1;All share the same root cause: correlated subquery producing a |
|
Correction on the second variant — the CREATE TABLE t (a Int32, b String) ENGINE = MergeTree ORDER BY a;
INSERT INTO t VALUES (1, 'x'), (42, 'y');
SELECT 1 FROM t WHERE a >= CAST((SELECT a), 'Int64') AND a <= 42 SETTINGS enable_analyzer = 1;
-- crashes with: Unexpected number of columns in result sample block: 2 expected 3
-- ([__table2, __table1.a] = [__table2] + [__table1.a] + [__table2])The common trigger across all AST fuzzer findings: |
Update 2026-04-19 — bug status on master and PRsCIDB status (last 14 days)
Master has been clean for 20+ days (last hit 2026-03-30 on commit Merged upstream fixesTwo PRs fixed the bug at upstream call sites:
These two cover most patterns. However, two AST fuzzer failures on April 7-8 happened on branches that already contain BOTH merged fixes (PR #100276 commit Both show the same pattern my PR addresses: a name appears in BOTH Why my PR is still neededMy defensive fix at the assertion site would catch these uncovered cases. Its logic:
For the two uncovered cases:
Ask@vdimir @KochetovNicolai @alexey-milovidov — could you take another look? The PR is mergeable, 142/163 CI checks pass, 1 failure is a known flaky Minimal repro (provided on Apr 7) — now passes on current master due to PR #98286's upstream fix, but the fuzzer findings above show PR branches still hit the pattern: SELECT 1 FROM numbers(1)
WHERE number >= CAST((SELECT number), 'Int64')
AND number <= 0
SETTINGS enable_analyzer = 1;Session: cron:clickhouse-ci-task-worker:20260419-014500 |
LLVM Coverage Report
Changed lines: 85.71% (18/21) · Uncovered code |
|
Closing this PR — the original bug (STID 2980-385f) is no longer reproducible on master. Verification on current master (commit 9ed0cd6, 2026-05-09):
CIDB confirms: STID 2980-385f had 0 master hits and only 1 PR hit in the last 30 days. This matches @alexey-milovidov's reasoning when closing the parallel #100617 today ("As we can't reproduce it - closing"). Some upstream change in the analyzer/planner between April and now appears to have removed the column-duplication code path that reached the assertion. This PR's The targeted AST fuzzer failure on this PR (STID 2651-2cfd "Trying to extract chunk from ChunkBuffer") is unrelated and separately tracked under #103322. If anyone wants the two reproducers preserved as a non-crash regression defense, they can be lifted into a separate test without the assertion-side change — happy to follow up with that on request. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix
Logical error: Unexpected number of columns in result sample blockcrash inHashJoin::getNonJoinedBlockswhen column names overlap between left and right sides after join side swapping (e.g., withGLOBAL NOT IN).Description
After join side swapping (e.g., LEFT ANTI → RIGHT ANTI via
GLOBAL NOT IN), column names can appear in both the left block andsample_block_with_columns_to_add. DuringjoinBlock,AddedColumnscorrectly skips right-side columns whose renamed name already exists in the left block (seeAddedColumnsconstructor, line 154 ofAddedColumns.h). However, the assertion ingetNonJoinedBlockscomputed the expected column count as a naive sum (left + right_keys + columns_to_add) without accounting for this cross-side overlap, causing aLOGICAL_ERRORcrash.Root cause: The assertion at line 1711 of
HashJoin.cppassumedresult_sample_block.columns() == left_columns_count + required_right_keys.columns() + sample_block_with_columns_to_add.columns(), but when column names overlap across sides, the result block has fewer columns becauseAddedColumnsdeduplicates them.Fix: Count right-side columns (from both
sample_block_with_columns_to_addandrequired_right_keys) whose renamed name appears in the left block, matching the exact deduplication logic inAddedColumns, and subtract this overlap from the expected count.Why not PR #100617's approach: That PR uses
NameSetcomparison which also deduplicates within-left duplicates. Queries with subqueries can legitimately produce duplicate column names on the same side (e.g.,__table2appearing twice in the left block). TheNameSetapproach causesexpected_names.size() < result.columns()for such queries, breaking 7 existing join tests (00577, 03707, 02497, 02267, 00217, 02381, 00370). Our cross-side overlap approach preserves within-left duplicates while correctly handling cross-side overlap.Impact: STID 2980-385f — P0 recurring AST fuzzer crash hitting 20+ unrelated PRs and master over the last 12 days.
Verification:
04068_hashjoin_column_overlap_assertion— 20/20 passes with randomization🤖 Generated with Claude Code