Repository navigation
Conversation
…ce flag DataTypeUInt64 carries a per-instance canUnsignedBeSigned flag, set by FieldToDataType for a UInt64 literal that also fits Int64 and consumed by convertUInt64toInt64IfPossible so that getLeastSupertype can produce a plain Int64 instead of a Variant. IDataType::equals compares only typeid, so a flagged and an unflagged UInt64 are indistinguishable to every equals()-based check. addConvertingToCommonHeaderActionsIfNeeded therefore skipped such a branch twice over: blocksHaveEqualStructure reported equality, and even when the converting DAG was built makeConvertingActions omitted the CAST. The branch then published its own flagged type as the union output type. An enclosing union folded that flagged UInt64 with an Int64 branch, convertUInt64toInt64IfPossible fired, and the plan header collapsed to Int64 while the analyzer, whose nested fold went through a freshly constructed unflagged instance, had already declared Variant(Int64, UInt64) for the same node. Every consumer built off the declared type then disagreed with the column in the plan. IFunctionOverloadResolver::build installs FunctionBaseVariantAdaptor whenever a declared argument type is Variant, so ExecutableFunctionVariantAdaptor cast a ColumnVector or ColumnNullable to ColumnVariant and threw: Logical error: 'Bad cast from type DB::ColumnVector<long> to DB::ColumnVariant' Force the conversion when a branch column and its common-header target compare equal() but the branch carries the flag and the target does not, and force the CAST that makeConvertingActions skips. The predicate is one directional: a flagged common target is constructible through the all_equal shortcut in getLeastSupertype, so mixed unions are order dependent and correct today, and adding a flag is never necessary. It also refuses a container that would strip one leaf's flag and add another's, because a CAST converts a whole column. The same class is worked around at the consumption site twice in src/Functions/if.cpp (issues ClickHouse#105649 and ClickHouse#70017); this fixes it one layer up so every consumer above a union sees a consistent type. Found by the AST fuzzer, but reachable from an ordinary SELECT at default settings. Co-Authored-By: Claude Fable 5 <[email protected]>
It drives remote('127.0.0.1', ...) for the distributed / WithMergeableState
control, which the runner only selects when the server has a second listen host.
Co-Authored-By: Claude Fable 5 <[email protected]>
…test Two review findings, both about the test asserting values that cannot observe the property the fix claims. The aggregate state control drives two remote() queries, but the runner randomizes prefer_localhost_replica, and with the value 1 a plain MergeTree shard is planned entirely locally, so no secondary query plan is built while the asserted 15 and UInt64 still match. Measured 0 secondary queries without the pin against 4 with it, and the test passes either way, which is the vacuity. The two queries now pin prefer_localhost_replica = 0. The one directional restriction of the flag predicate, strips and not adds, was pinned by nothing: a flagged and an unflagged UInt64 print the same type name and the flag changes no value, so mutating the predicate to strips or adds, or deleting only the mixed direction refusal, left every asserted byte identical. The test now counts Conversion before UNION plan steps, which is the only plan level effect the conversion has. Two of the added shapes keep every branch non constant, because a const branch already fails blocksHaveEqualStructure and gets a conversion step whether or not the predicate fires, which makes the count blind to the mutation. Every expected count was derived by measurement and then checked against a prediction written before building the mutations: strips or adds moves three counts, strips alone moves one, and neither moves any other line. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Internal second-model review (click to expand)Two review rounds. Round 0 found two majors and bounced the PR; round 1 is clean. In both rounds Round 0: two majors, both fixedBoth were raised INDEPENDENTLY by the reviewer's own cold read and by the second-model gate, so ❌ The only coverage of the distributed / ❌ The one-directional restriction of the predicate was pinned by nothing.
Round 1: cleanReviewer's own cold read: no findings. Second-model gate: 0 findings, over a diff whose Re-derived independently rather than inherited from round 0: the invariant-carrier list; the Noted, not blocking💡 The added C++ comments do not backtick symbol names. The repository instruction file asks for 💡 Session id: cron:clickhouse-review-slot-49:20260727-063700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20260727-055100 (authored), cron:clickhouse-review-slot-49:20260727-063700 (reviewed and published) |
|
cc @vdimir @yakov-olkhovskiy - could you review this? It makes |
|
Workflow [PR], commit [3b7ca40] Summary: ✅
AI ReviewSummaryThis PR fixes the planner/analyzer mismatch in nested set operations where a branch that differs from the common header only by PR Metadata
### Changelog category (leave one):
- Critical Bug Fix (crash, data loss, RBAC)
### Changelog entry (a [user-readable short description](https://github.com/ClickHouse/ClickHouse/blob/master/docs/changelog_entry_guidelines.md) of the changes that goes into CHANGELOG.md):
Fixes a crash in nested `EXCEPT`, `INTERSECT`, or `UNION` queries over large integer literals, where the query plan could produce an `Int64` column that the analyzer had typed as `Variant(Int64, UInt64)`. In release builds this could end in a segmentation fault, and aggregate-function consumers such as `groupConcat` were affected too.
Related: https://github.com/ClickHouse/ClickHouse/issues/107951
Related: https://github.com/ClickHouse/ClickHouse/pull/110745Final Verdict
LLVM Coverage ReportMeasured on commit 3b7ca40.
Changed lines: Changed C/C++ lines covered: 42/43 (97.67%) · Uncovered code |
The Style check rejects the phrase "new analyzer": the analyzer has been the default since 24.3, so the wording rule in various_checks.sh asks for "the analyzer" or "Analyzer". Only the comment text changes; the executable content of the test is byte identical. CI report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/112043/44bc98dfcfaff1bdc2558e913f99c4249c3fea9a/style_check/job.log Related: ClickHouse#112043 Co-Authored-By: Claude Opus 5 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 42/43 (97.67%) · Uncovered code |
CI finish ledger — 47b14e9Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CI is otherwise green on this head: 174 checks, 153 success / 18 skipped / 1 failure, Attribution for the one failure, so it is checkable rather than asserted:
Session id: cron:our-pr-ci-monitor:20260727-160000 |
|
@groeneai update this PR |
|
@qoega Updated: merged current master in (a merge commit rather than a rebase, since the branch is already published). New head The branch was 20319 commits behind, so I re-verified on the new base before pushing: unpatched master |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger -
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
Bugfix validation (functional tests, amd64) |
ERRORs at ci/jobs/functional_tests.py:734 with AssertionError: Could not find master builds in S3 before any server starts, so the job validated nothing and no test is attributed |
#117433 (mine, open) |
Bugfix validation (functional tests, aarch64) |
same Could not find master builds in S3 abort as the row above |
#117433 (mine, open) |
Finish Workflow / Post Hooks |
cascade of the two rows above: ci/jobs/scripts/workflow_hooks/new_tests_check.py reds when no per-arch bugfix job reports OK or XFAIL |
#117433 (mine, open) |
Docs examples / Documentation examples / Function/toYYYYMM#0 |
the toYYYYMM documentation example pinned its output to a value derived from the current date, so it started failing at the month rollover on every pull request and on master |
#117459 (mine, merged 2026-09-01), absent from this tree |
Stress test (arm_debug) / Logical error: Not-ready Set is passed as the second argument for function 'globalIn' (STID 0250-4e52) |
pre-existing trunk defect on the object-storage _path / _file prefilter, not reachable from this diff: the abort runs ReadFromObjectStorageStep::createIterator into StorageObjectStorageSource::createFileIterator, VirtualColumnUtils::getFilterByPathAndFileIndexes and FunctionIn::executeImpl (src/Functions/in.cpp:128), and carries no FutureSetFromSubquery frame |
#112968 (external, open) |
Stress test (arm_tsan) / Logical error: Shard number is greater than shard count: shard_num=2 shard_count=1 cluster=test_cluster_one_shard_three_replicas_localhost (STID 5066-457d) |
pre-existing master defect: prepareClusterForParallelReplicas indexes the initiator's _shard_num into cluster_for_parallel_replicas as if both numbered the same cluster |
#113589 (mine, open) |
Stress test (arm_tsan) / Test script failed |
not a separate defect: script exit code: 1 is the stress runner exiting after the server abort in the row above |
#113589 (mine, open) |
CH Inc sync |
- | CH Inc sync (private, not actionable by me) |
None of the rows above is caused by this pull request.
I am not merging master here purely to re-run CI. #117459 is the only merged owner, so a merge
would clear the Docs examples row and leave the Bugfix validation, Finish Workflow and two
Stress test rows red, at the cost of a full workflow cycle and a maintainer approval. One merge
once #117433 lands clears more of them at once.
Session id: cron:our-pr-ci-monitor:20260901-190000
|
Another AST fuzzer report of the same divergence, this time through an aggregate function, where a release build crashes instead of throwing: SELECT groupConcat(x) FROM ((SELECT 9223372036854775806 AS x) EXCEPT DISTINCT (SELECT 0) EXCEPT DISTINCT (SELECT -9223372036854775808 AS x));
The aggregate is created for the declared So the terminology note in the description holds only for the function adaptor path: the aggregate path crashes release builds. |
The same analyzer/plan type divergence is reachable through aggregate functions created for the declared Variant type (groupConcat, any, groupArray), through variantType, and through UNION ALL / UNION DISTINCT nested inside another set operation. On unpatched master these fail with `Bad cast ... to DB::ColumnVariant`, a column type assertion, `Invalid discriminator value 254`, or ILLEGAL_TYPE_OF_ARGUMENT for variantType; on official 26.3 and 26.8 release builds the groupConcat form and the original repro end in SIGSEGV. All of them return the expected result with this fix. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=93833&sha=1861d9a31415622f9f5b772f915bc90558515d98&name_0=PR&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29 Related: ClickHouse#112043 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep only the invariants a reader needs at each spot: equals(), blocksHaveEqualStructure() and makeConvertingActions() do not see the canUnsignedBeSigned flag, and a whole-column CAST cannot drop the flag on one nested type while adding it on another. The rest (the one-directional predicate, how the divergence reaches the analyzer-declared Variant) is in the PR description and the earlier commit messages. Comment-only change: the comment-stripped file is identical. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Correction to my previous comment: the function adaptor path crashes release builds too. The query in the description ends in a segmentation fault in Also merged master and added the |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a crash on nested
EXCEPT,INTERSECTorUNIONqueries over large integer literals, where the query plan produced anInt64column that the analyzer had typed asVariant(Int64, UInt64). Release builds could end in a segmentation fault and debug builds threwBad cast from type DB::ColumnVector<long> to DB::ColumnVariant; aggregate functions such asgroupConcatover such a column were affected too.Description
Related: #107951, #110745
On the official 26.3.33.24 and 26.8.10.6 builds this ends in a segmentation fault at default settings:
AST fuzzer reports: debug, release.
Root cause.
DataTypeUInt64carries a per-instancecanUnsignedBeSignedflag that letsgetLeastSupertypefoldUInt64andInt64intoInt64, butIDataType::equalsignores it.addConvertingToCommonHeaderActionsIfNeededtherefore skipped a branch that differed from the common header only by that flag, so the inner union published the flagged type and the outer one folded it toInt64, while the analyzer declaredVariant(Int64, UInt64)for the same column. Every consumer built from the declared type (theVariantfunction adaptor, aggregate functions,variantType) then got a plain column.Fix. When a branch column differs from its common-header type only by dropping that flag, force the conversion and the CAST that
makeConvertingActionsomits. The predicate never adds a flag and leaves alone a container that would need both directions; both cases are pinned byConversion before UNIONstep counts in the test.Validation.
04647_union_common_header_supertype_flagcovers the query above withNullable,LowCardinality,Array,TupleandMapwrappers,groupConcat,any,variantType, andUNION ALL/UNION DISTINCTnested in another set operation. Each of these fails on unpatched master and returns the expected value with the fix; 67 randomized runs passed.#110745 changes the same function for a different trigger and cannot see this flag, since type names do not encode it.
Workflow [PR]
Sync PR [sync-upstream/pr/112043]