Repository navigation
Conversation
MutateSomePartColumnsTask loads statistics from the source part via loadStatistics(), keyed on the type stored at write time. When a MODIFY COLUMN changed a column's type but the mutation did not schedule a recalculation for that column (the column is not in stats_to_recalc), the stale-typed collector survived in all_statistics and buildIfExists fed it a new-type block during the part rebuild. The uniq collector for the old type (e.g. AggregateFunctionUniq<long> for Int64) then received a new-type column (Int128 / Decimal256 / UInt8 / ...), which tripped the statistics type-mismatch guard (LOGICAL_ERROR) and aborted debug and sanitizer builds. Reconcile the loaded statistics against the current metadata at the top of processStatisticsChanges: any collector whose type disagrees with the current column type is replaced by a fresh empty collector for the new type (or dropped if the column no longer declares statistics). This matches what MutateAllPartColumnsTask already does by building fresh statistics from the current metadata, so the collector reaching build / buildIfExists always matches the block type. Rebuilding from scratch is correct because the mutation writes a fresh part. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260704-211000 |
|
cc @CurtizJ @Avogar — could you review this? It fixes the upstream cause of the statistics type-mismatch LOGICAL_ERROR family (STID 0250-4148 / 2404-35eb) that the diagnostic guard in #106963 deferred: |
|
Workflow [PR], commit [ccf9e88] Summary: ❌
AI ReviewSummaryThis PR fixes the original stale-type statistics collector exception by reconciling loaded statistics after rename handling and by adding both a focused gtest and a SQL reproducer for the ALIAS/type-mismatch wedge. The remaining problem is that the new reconciliation still preserves stale collectors when the type stays the same but the current metadata no longer declares Findings❌ Blockers
Final VerdictStatus: Minimum required action:
|
|
@Avogar, can we merge this one? Seems there are a handful of other PRs waiting for this test fix to be merged before they can be closed. |
|
@groeneai I have reason to believe that the problem that you try to fix in this PR is hallucinated, see #109611 (comment). Please replace the C++ unit test in this PR by a SQL test that demonstrates a real problem. |
- Move reconcileWithColumns after the rename loop so a collector renamed to its current column name is reconciled under that name (a part storing stats under an old name no longer skips reconciliation). - Compare collector vs column by type name instead of equals(): the statistics file keys compatibility on the stored type name, so a UInt8->Bool change must drop the old collector rather than keep it and write stats that loadStatistics immediately discards as stale. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@rschu1ze The failure is real, not hallucinated, but you are right that the original-post fiddle is not a valid repro and I could not build a deterministic pure-SQL one either. Here is the actual evidence. CIDB (
Root cause: Why I have no deterministic SQL repro: a synchronous Given that, the C++ unit test is the deterministic vehicle: it constructs the exact stale-collector-vs-new-type state and asserts reconciliation rebuilds the collector, over the I also pushed two fixes for the bot review in the same PR:
|
The existing type-change matrix differs under both equals() and getName(), so reverting the production comparison to equals() kept every case green. Add a focused UInt8<->Bool case (same typeid, differs only by name) that asserts on the collector's stored type name, so an equals() regression fails. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Added a focused |
…y ones reconcileWithColumns materialized a fresh empty new-type collector for a type-changed stat-declaring column. A column the mutation actually rebuilds is re-added right after from stats_to_recalc, so that was redundant; but a column only carried forward via hardlinks (not read into cur_block, e.g. when splitAndModifyMutationCommands skips its READ_COLUMN and a later mutation renames a stale collector onto its current name) is never fed a block, so the empty collector survives and the new part serializes a zero-row statistic for a non-empty column. Drop the stale collector instead: a rebuilt column gets a matching-type collector from stats_to_recalc, a carried-forward column gets a missing (not wrong) statistic, matching the pre-existing behavior where a type-name mismatch made loadStatistics discard it. Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 73/75 (97.33%) · Uncovered code |
CI finish ledger — d02c07cEvery failure below has an owner: a fixing PR, or the private-sync exemption.
Report messages (warnings) and Finish Workflow "Post Hooks" are the non-blocking rollup reflection of the above. Session id: cron:our-pr-ci-monitor:20260715-033000 |
Reconstructs the wedged on-disk state reported on issue ClickHouse#109611: a stat-bearing column ends up as an ALIAS column of a different type while an old part still stores it physically with the original-type statistics file, and a MATERIALIZE COLUMN mutation then aborts the server. The fuzzer reaches the ALIAS state through a long MODIFY chain that is not directly issuable (a physical stat-bearing column cannot be turned into ALIAS synchronously), so the test rebuilds the state via metadata edit + attach. Also refresh the stale reconcileWithColumns call-site comment to the drop model (the collector is dropped, not replaced with an empty one). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@rschu1ze re the SQL test: added Without the fix that aborts the server with I kept the gtest case as well: it locks in the second commit's |
system.tables.metadata_path is relative to the database disk root. The test edited it with sed from the runner's cwd, so sed could not find the file, the column stayed physical, and MATERIALIZE COLUMN failed with BAD_ARGUMENTS. This failed deterministically in the flaky check (5/5 runs). Prepend the default disk path for the local case, with a clickhouse-disks fallback for the remote database disk parametrization, mirroring 03001_matview_columns_after_modify_query.sh. Co-Authored-By: Claude Opus 4.8 <[email protected]>
| /// mismatch). equals() treats a custom-named type as its base (Bool == UInt8), which would | ||
| /// keep a UInt8 collector for a Bool column and write statistics that the next loadStatistics | ||
| /// immediately discards as stale. | ||
| if (stat_type && current_type->getName() == stat_type->getName()) |
There was a problem hiding this comment.
reconcileWithColumns still bails out as soon as the stored type name matches, before checking whether the current metadata declares any statistics for this column. That leaves a same-type / no-STATISTICS(...) wedge unhandled.
A concrete trace is the same attach-edit pattern the new SQL test already uses, but keeping the type unchanged: if a part still carries mtrl statistics, the metadata is rewritten to something like `mtrl` Int64 ALIAS 1 (or any other same-type definition without STATISTICS), and a later MATERIALIZE COLUMN mtrl or unrelated mutation runs, loadStatistics() reloads the old collector, this continue keeps it, and finalizeMutatedPart writes it back out again even though column_desc->statistics.empty(). Because getEstimates() loads statistics files by column name/type, those resurrected stats can still participate in pruning after the user removed them.
I think the column_desc->statistics.empty() case needs to win before this type-name fast path, and a focused regression test next to ReconcileWithColumnsDropsTypeChangedCollectors should cover the same-type / statistics-removed case.
| @@ -0,0 +1,24 @@ | |||
| <clickhouse> | |||
| <storage_configuration> | |||
There was a problem hiding this comment.
@groeneai Try to remove as many configuration settings as possible from here.
There was a problem hiding this comment.
Done in ccf9e88. This config is used only by clickhouse-disks in the remote database-disk branch. Removed the zookeeper block (unused by the disks tool for a plain_rewritable read/write) and the macros block, inlining the endpoint as test-s1|r1 (the exact expansion the server config produces). Only the disk_db_remote definition remains. Verified clickhouse-disks still initializes the disk from the trimmed config, and the local-disk branch still reproduces/passes.
The per-test config is only used by clickhouse-disks in the remote database-disk branch. Drop the unused zookeeper block and inline the endpoint macros (shard=s1, replica=r1, matching the server config), so only the disk_db_remote definition remains. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
I will not keep re-arguing this. One fact stands regardless of any hand-written repro: the abort has fired twice on master itself, produced by the engine, not by me.
These are
If you are not convinced the fix is the right shape, that is your call as the statistics owner - decline the PR and I will close it. But the master aborts are on the record either way. |
|
@groeneai the test is bad, it corrupt files inside data part. It doesn't prove that this can happen in real scenarious |
|
I am not convinced that this can actually happen. There is still no comprehensive explanation or chain of events that can lead to it. |
|
@Avogar You are right about the test, and I want to answer both of your points honestly. On the test. Agreed: the 04501 test edits the part's on-disk On whether it can actually happen. It is engine-produced on master, with no test or file editing involved:
30-day CIDB: 22 aborts across 21 distinct PRs + those 2 master runs, still firing 2026-07-16. All land on The chain of events (concurrent, which is why a single script cannot show it). Given that, I do not want to leave a part-corrupting test in the PR. What would you prefer:
I will not push further changes until you say which you want. |
|
You should try to write a .sh test with concurrent operations that will reproduce the issue at least with some probability , but you must ensure it reproduces it at least once before committing the test, even if it reproduces in 1 out of 100 runs, but better to make it more frequent. |
|
@Avogar I did what you asked and could not meet the bar. Being straight about it. I built the concurrent
Zero reproductions. I also tried the deterministic real chains (metadata-only conversion DateTime->UInt32 / Enum8->Int8 / Date->UInt16, then So I cannot honestly commit a The one fact that does not depend on any repro: the abort fired twice on master itself, produced by the engine on the CI stress runners:
Both land on How would you like to proceed? Options I see:
I will not push anything further until you decide. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
LOGICAL_ERROR("Bad cast" / "Type mismatch when building statistics") that could be raised while rebuilding a column's statistics during a mutation after that column's type was changed byALTER TABLE ... MODIFY COLUMN. The statistics collector loaded from the source part was keyed on the old type and could be fed a block of the new type; it is now rebuilt for the current type before use.Description
Closes: #109611
MutateSomePartColumnsTaskloads a part's statistics vialoadStatistics(), which keys each collector on the column type stored when the statistics were written. When aMODIFY COLUMNchanged a column's type but the mutation did not schedule a recalculation for that column (it is not instats_to_recalc), the stale-typed collector survived inall_statisticsandbuildIfExistsfed it a new-type block during the part rebuild. For auniqstatistic this reachedAggregateFunctionUniq<T>::addBatchSinglePlaceNotNull, where the old-type specialization (for exampleAggregateFunctionUniq<long>forInt64, whose column type isColumnVector<long>) was handed a new-type column (Int128,Decimal256,UInt8, ...) and trippedassert_cast. The statistics type-mismatch guard added in #106963 now surfaces this as a diagnosticLOGICAL_ERROR, which still aborts debug, sanitizer and stress builds. This PR fixes the upstream cause that #106963 deliberately deferred.processStatisticsChangesnow reconciles the loaded statistics against the current metadata before the rebuild (ColumnsStatistics::reconcileWithColumns): any collector whose type disagrees with the current column type is replaced by a fresh empty collector for the new type, or dropped if the column no longer declares statistics. This mirrors whatMutateAllPartColumnsTaskalready does by constructing statistics from the current metadata, so the collector reachingbuild/buildIfExistsalways matches the block type. Rebuilding from scratch is correct because the mutation writes a fresh part, filling the collector from the new data anyway.A unit test (
Statistics.ReconcileWithColumnsRebuildsTypeChangedCollectors) covers the type-change matrix from the observed failures (Int64toInt128/Decimal256/UInt8/Float64and the nullability dimension): after reconciliation the collector is rebuilt to the new type and the subsequent build succeeds instead of aborting. It also checks that a de-statisticized column drops its collector, that a matching type is left untouched, and that a column absent from the current metadata is preserved.