Repository navigation
Conversation
…another type A part's statistics hold values of the column type the part was written with. After KILL MUTATION of an ALTER MODIFY COLUMN, or while it is pending with apply_mutations_on_fly = 0, the part keeps the old type and a read converts its values (UInt64 260 reads as UInt8 4). The min/max shortcut took the part's old min/max and inserted them as the new type, because its only per-part type check compares the Field type, which a narrowing inside one Field type passes. SELECT min(x), max(x) returned 250 4 instead of 4 250, and a Decimal64(3) -> Decimal64(1) change returned 123.4 567.8 instead of 1.2 5.6. Answer a part from statistics only when its type of the column reads back unchanged as the current type, using the predicate skip indexes use for the same state (isRepresentationPreservingConversion), so metadata-only changes such as an enum widening keep the shortcut. Other parts are read. Statistics part pruning for this state is handled by ClickHouse#119337. Related: ClickHouse#116627 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20261015-165500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261015-161900 |
|
Workflow [PR], commit [69d4926] Summary: ❌
AI ReviewSummaryThe PR prevents Final VerdictStatus: ✅ Approve |
|
cc @Michicosun @CurtizJ, could you review this, and add the |
CI finish ledger - 69d4926Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261015-213010 |
|
Fixing PR for the |
|
#119337 now contains the same fix (commit d7adf71). |
…istics of a part with a stale column type `05453_statistics_pruning_pending_rename` covers the repro of #117323: with a pending `DROP COLUMN x, RENAME COLUMN y TO x`, statistics-based part pruning and `min`/`max` from statistics must not use the estimate of the dropped column stored under `x`. `05454_statistics_min_max_stale_part_type` ports the cases of #126076 that the existing tests do not cover: `min`/`max` from statistics while a narrowing `MODIFY COLUMN` is pending with `apply_mutations_on_fly = 0` (so it is not in the mutations snapshot), after it is killed, and a `Decimal` scale change, which keeps the type of `Field`. Both tests pass with the CI build of 4f7649a and fail with a build without this PR.
|
Follow-up to my previous comment: please disregard my request. I ported the cases of |
Related: #116627
Related: #119337
Related: #117320
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed wrong
min/maxanswered from column statistics (use_statistics_for_min_max_aggregation) for a part that still stores the column with its type from before anALTER TABLE ... MODIFY COLUMN, for example after the mutation was killed. Such parts are now read instead.Description
On 26.9.16.11, after
KILL MUTATIONofALTER TABLE t MODIFY COLUMN x UInt8(xwasUInt64with values 250 and 260),SELECT min(x), max(x) FROM treturns250 4instead of4 250.A part's statistics hold values of the column type the part was written with. After a killed
MODIFY COLUMN, or while it is pending withapply_mutations_on_fly = 0, apply_patch_parts = 0, the part keeps the old type and a read converts its values (260 reads as 4).makeBlockWithMinMaxFromStatisticsstill took the part's old min/max and inserted them as the new type: its only per-part type check compares theFieldtype, which a narrowing inside oneFieldtype passes (UInt64 -> UInt8,UInt32 -> UInt16, or aDecimalscale change, whereDecimal64(3) -> Decimal64(1)returned123.4 567.8instead of1.2 5.6).Now a part is answered from statistics only when its type of the column reads back unchanged as the current type, using the predicate skip indexes already use for the same state (
isRepresentationPreservingConversion, #112484). Metadata-only changes such as an enum widening keep the shortcut; other parts are read.#119337 covers statistics part pruning for this state; this PR covers the min/max shortcut, which #119337 does not touch.
Test
05401_min_max_from_statistics_stale_part_type: pending with both settings off, killed, and an enum widening that keeps the shortcut. It fails on master and passes with the fix, including 50 randomized runs.Workflow [PR]
Sync PR [sync-upstream/pr/126076]