Repository navigation
Conversation
`convertFieldToTypeImpl` lumped `DateTime` and `Time` together in a single branch: when an `OPTIMIZE TABLE ... PARTITION X` query landed there with `Field::Types::UInt64`, the `Field` was returned unchanged. That is correct for `DateTime` (backed by `UInt32`, canonical `Field` is `UInt64`), but wrong for `Time` (backed by `Int32`, canonical `Field` is `Int64`). When the existing parts on disk were read back, `SerializationNumber<Int32>::deserializeBinary` produced `Field(Int64)` for the partition value, so the strict `Field`-type comparison inside `MergeTreeData::getPartitionIDFromQuery` threw Logical error: Parsed partition value: 00:00:00 doesn't match partition value for an existing part with the same partition ID: 0_1_1_0 and aborted the server in the debug build. Split the branch: keep `DateTime + UInt64` as a no-op `return src`, but route `Time + UInt64` through `convertNumericType<Int32>` so the result is a canonical `Field(Int64)` that matches what the part loader produces (and so out-of-range input is range-checked). Also fix a misleading comment on the existing `Time + Int64` branch (it referenced `Date32` instead of `Time`). Adds a regression test that reproduces the exception deterministically on master. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=51acd871d02e007d9562b028cbf64a3f84b524e4&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29
|
Pre-PR validation gate (session (a) Deterministic repro? Yes. Single-shot: CREATE TABLE t (id UInt64, p Time) ENGINE = MergeTree PARTITION BY p ORDER BY id;
INSERT INTO t SELECT number, 0 FROM numbers(10);
OPTIMIZE TABLE t PARTITION 0 FINAL;On master (b) Root cause explained? Yes. (c) Fix matches root cause? Yes. Split the branch. (d) Tests added? Yes. (e) Both directions demonstrated? Yes, locally:
(f) Fix is general? The change is in the type-coercion layer. Same call site is reached by anything that resolves a |
|
cc @yariks5s @KochetovNicolai could you review? Small fix in |
|
Workflow [PR], commit [f0e4294] Summary: ✅
AI ReviewSummaryThis PR fixes Final VerdictStatus: ✅ Approve |
Bot review on PR ClickHouse#106202 pointed out that the previous fix routed only the `Time + UInt64` branch of `convertFieldToTypeImpl` through `convertNumericType<Int32>`, leaving the existing `Time + Int64` branch returning `src` unchanged. That branch is reachable from `OPTIMIZE TABLE ... PARTITION <negative literal> ...` and from explicit `Int64` partition expressions, and skipping the conversion allowed an out-of-range `Int64` value (e.g. `-2147483649`) to be silently truncated by the downstream `SerializationNumber<Int32>` / `ColumnVector<Int32>::insert` static_cast inside `MergeTreePartition::getID`, so the resulting partition id did not correspond to the value the user wrote. Combine the two `Time` branches into one that routes both `UInt64` and `Int64` `Field`s through `convertNumericType<Int32>`. In-range values still come back as the canonical `Field(Int64)` (no behavior change for valid input). Out-of-range values become `Field()` and are turned into a clean `ARGUMENT_OUT_OF_BOUND` exception by the `convertFieldToTypeOrThrow` non-null-to-null check, instead of being silently truncated. Extends the regression test for STID 3993-36c1 to cover the `Int64` path: an in-range negative literal succeeds, and an out-of-range `Int64` literal raises `ARGUMENT_OUT_OF_BOUND`. Verified locally that the new test case fails without this change (the `OPTIMIZE ... PARTITION -2147483649 FINAL` query succeeds silently) and passes with it (the query is rejected with code 69).
|
@groeneai please merge with master to pick up latest version |
…-3993-36c1-time-partition
|
@yariks5s merged master in Session: cron:clickhouse-ci-task-worker:20260604-144000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 6/6 (100.00%) | Lost baseline coverage: none · Uncovered code |
|
@yariks5s CI is now fully finished on CI ledger for
PR is APPROVED by you, master is merged, CI clean of any PR-caused failure. Ready for merge whenever convenient. |
…utdown noise The upgrade-check post-restart `<Error>` scrub catches a transient lock-timeout emitted by `SystemLog<MetricLogElement>::flushImpl` when the background `MetricLog` flush loop races with shutdown work on `system.metric_log` during the upgrade restart sequence: ``` <Error> void DB::SystemLog<DB::MetricLogElement>::flushImpl(...) [LogElement = DB::MetricLogElement]: Failed to flush system log system.metric_log with N entries up to offset M: Code: 473. DB::Exception: WRITE locking attempt on "system.metric_log" has timed out! (60000ms) Possible deadlock avoided. Client should retry. Owner query ids: . (DEADLOCK_AVOIDED), Stack trace ... ``` Another worker (DROP/RENAME/DETACH on `system.metric_log`, or a parallel mutation/merge) holds the table-level write lock, the flush blocks for the 60s timeout, and then aborts with code 473 (`DEADLOCK_AVOIDED`). The 473 code is the engine's own "gave up to avoid a deadlock, not a crash" signal — losing a few `MetricLogElement` samples during shutdown is harmless; the upgrade-check stage is not asserting on metric continuity. CIDB confirms this is chronic CI noise, not a code regression: 4 hits across 4 distinct PRs in the last 30 days, 0 master, 100% on `Upgrade check (amd_release)`. Reported by @ alexey-milovidov on PR ClickHouse#102017 (cited ClickHouse#106425, ClickHouse#104561, ClickHouse#106202). The added regex requires BOTH the `SystemLog` flush wrapper for `metric_log` AND the `DEADLOCK_AVOIDED` error code together, mirroring the narrowing approach of the existing `rdk:FAIL.*Connect to.*failed: Connection refused` and `StorageKafka2.*Broker transport failure` filters. Real `metric_log` regressions (other flush errors) and unrelated `DEADLOCK_AVOIDED` hits on other system_log tables (`query_log`, `text_log`, etc.) still surface. Related: ClickHouse#102017 Related: ClickHouse#106563 Related: ClickHouse#101576 Co-Authored-By: Claude Opus 4.8 <[email protected]>
09786b2
…conversion Master commit 3701b73 (PR #106202) combined the `Time` branches in `convertFieldToTypeImpl` so both `UInt64` and `Int64` partition values are routed through `convertNumericType<Int32>(src, type)`. This PR changed `convertNumericType` to take a `strict` argument with no default value, so after merging `master` that call site no longer compiled (2 arguments passed to a 3-argument function). Pass `strict` through. `Int32` is an integer type, so the conversion stays exact regardless of the flag (`exact = strict || !is_floating_point<Int32>` is always `true`), making this change behavior-neutral for the `Time` partition path while restoring a clean build.
|
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment. TL;DRFix Logical error on OPTIMIZE PARTITION for Time-typed partition key ClickGap verified: reproduced it with the script below on ReproductionBisect
Affects
Suggested next stepThe fix has landed on master; the affected release branches above still need the backport. Component: cc fix PR author: @groeneai ClickGap · Finding: Triage metadata
|
|
Hi — this looks like a backport candidate for |
Bot review on PR ClickHouse#106202 pointed out that the previous fix routed only the `Time + UInt64` branch of `convertFieldToTypeImpl` through `convertNumericType<Int32>`, leaving the existing `Time + Int64` branch returning `src` unchanged. That branch is reachable from `OPTIMIZE TABLE ... PARTITION <negative literal> ...` and from explicit `Int64` partition expressions, and skipping the conversion allowed an out-of-range `Int64` value (e.g. `-2147483649`) to be silently truncated by the downstream `SerializationNumber<Int32>` / `ColumnVector<Int32>::insert` static_cast inside `MergeTreePartition::getID`, so the resulting partition id did not correspond to the value the user wrote. Combine the two `Time` branches into one that routes both `UInt64` and `Int64` `Field`s through `convertNumericType<Int32>`. In-range values still come back as the canonical `Field(Int64)` (no behavior change for valid input). Out-of-range values become `Field()` and are turned into a clean `ARGUMENT_OUT_OF_BOUND` exception by the `convertFieldToTypeOrThrow` non-null-to-null check, instead of being silently truncated. Extends the regression test for STID 3993-36c1 to cover the `Int64` path: an in-range negative literal succeeds, and an out-of-range `Int64` literal raises `ARGUMENT_OUT_OF_BOUND`. Verified locally that the new test case fails without this change (the `OPTIMIZE ... PARTITION -2147483649 FINAL` query succeeds silently) and passes with it (the query is rejected with code 69).
…3993-36c1-time-partition Fix Logical error on OPTIMIZE PARTITION for Time-typed partition key
…conversion Master commit 3701b73 (PR ClickHouse#106202) combined the `Time` branches in `convertFieldToTypeImpl` so both `UInt64` and `Int64` partition values are routed through `convertNumericType<Int32>(src, type)`. This PR changed `convertNumericType` to take a `strict` argument with no default value, so after merging `master` that call site no longer compiled (2 arguments passed to a 3-argument function). Pass `strict` through. `Int32` is an integer type, so the conversion stays exact regardless of the flag (`exact = strict || !is_floating_point<Int32>` is always `true`), making this change behavior-neutral for the `Time` partition path while restoring a clean build.
OPTIMIZE TABLE ... PARTITION X ...on a table with aTime-typed partition key threw(STID
3993-36c1, AST fuzzer, master, amd_debug) and aborted the server in debug builds.convertFieldToTypeImplhad a single branch handling(DateTime || Time) + UInt64that returned theFieldunchanged. That is correct forDateTime(UInt32under the hood, canonicalFieldisUInt64), but wrong forTime(Int32under the hood, canonicalFieldisInt64). The on-disk partition value is read back viaSerializationNumber<Int32>::deserializeBinaryas aField(Int64), so the strictField-type comparison inMergeTreeData::getPartitionIDFromQueryfired.Split the branch: keep
DateTime + UInt64as a no-opreturn src, and routeTime + UInt64throughconvertNumericType<Int32>so the result is a canonicalField(Int64)that matches the part loader and gets range-checked. Also corrected a misleading comment on the existingTime + Int64branch (it referencedDate32).Adds a regression test that reproduces the exception deterministically on master.
CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=51acd871d02e007d9562b028cbf64a3f84b524e4&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
Logical error: Parsed partition value: ... doesn't match partition value for an existing part with the same partition ID: ...thrown byOPTIMIZE TABLE ... PARTITION ...(and other queries that resolve a partition value throughconvertFieldToTypeImpl) on tables with aTime-typed partition key.Documentation entry for user-facing changes
Version info
26.7.1.35