Skip to content

Saturate an Enum8 or Enum16 converted to DateTime or Date - #118039

Merged
alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-todatetime-static-cast-monotonicity
Oct 1, 2026
Merged

alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-todatetime-static-cast-monotonicity

Conversation

@groeneai

@groeneai groeneai commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #113515
Related: #116946
Related: #117394
Related: #118717

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed wrong results when an Enum8 or Enum16 value is converted to DateTime or Date. A negative member wrapped instead of saturating like the Int8/Int16 it is stored as, so toDateTime of an enum returned a far-future timestamp and primary-key analysis discarded granules that did contain matching rows.

Description

On 26.8.11.7 (LTS), over a MergeTree table keyed by Enum16('neg' = -1, 'zero' = 0) holding both
members, SELECT count() FROM t WHERE toDateTime(x) = toDateTime(0) returns 0, while the same predicate
counted without the index returns 1. Measured there, each enum member beside the integer it is stored as:

expression enum its integer
toDateTime(-1) 2106-02-07 06:28:15 1970-01-01 00:00:00
toDate(-1) 2149-06-06 1970-01-01

ConvertImpl's branch lists for those two targets name the concrete integer and float types but not the
Enums, so an enum fell through to the generic numeric path, where a negative value wraps rather than
saturates, while index analysis was still told it is monotonic. This adds Enum8/Enum16 to both lists,
so an enum takes the same saturating transform its Int8/Int16 already uses. No monotonicity struct is
touched: once the conversion saturates, the non-strict monotonicity it claims holds again. That is the
design merged #118717 used for (U)Int128/(U)Int256 against the same defect. The wrong value above
needs no index at all, so it is a defect separate from the monotonicity declaration itself (#117394).

The inverted range also aborts a debug build in MergeTreeSetIndex::checkInRange, which is how CI found
it: this AST fuzzer (amd_debug) job,
over a fuzzer-mutated Enum16 key. The new test reproduces it with
WHERE toDateTime(x) IN (toDateTime(0), toDateTime(1)). Date32, Time, toUnixTimestamp and in-range
enum values are unaffected.

One thing I left out, yours to call: accurateCast(Enum8('neg' = -1), 'DateTime') returns a value instead
of throwing Code: 70 as it does for toInt8(-1), because can_apply_accurate_cast excludes Enum. That
predicate is target-agnostic, so changing it alters accurateCast of an enum to every numeric target.
Happy to do it here or separately.


Workflow [PR]
Sync PR [sync-upstream/pr/118039]

Version info

  • Merged into: 26.10.1.1127-master (included in 26.10 and later)

… plain cast

ConvertImpl pairs a DateTime target with an order-preserving transform for
Date, Date32, Int8, Int16, Int32, Int64, UInt64, Float32, Float64, BFloat16,
DateTime and DateTime64 only. Every other source type falls through to the
generic `vec_to[i] = static_cast<ToFieldType>(vec_from[i])`, which does not
preserve order: an Enum16 member of -1 becomes 4294967295 while 0 stays 0,
and a wide integer above the 32-bit range wraps to a smaller value.

ToDateTimeMonotonicity claimed monotonicity for all of them anyway, because
its DateTime arm falls back to an unconditional claim for every source whose
isValueRepresentedByNumber is true. applyMonotonicFunctionsChainToRange then
converts both ends of a granule's key range and never re-checks the ordering,
so it returns an inverted range. MergeTreeSetIndex::checkInRange computes
begin > end on it and throws "Invalid binary search result in
MergeTreeSetIndex"; the AST fuzzer hit exactly this on an Enum16 sorting key.

Release builds return {true, true} from that branch instead of throwing, but
the same inverted range reaches comparison atoms, where it silently drops
granules that do contain matching rows. The wrong results therefore occur in
every build, which is why this is a bug fix rather than a CI fix.

Replace the unconditional claim with the allow-list of source types that
actually convert in order, and strip LowCardinality first because several
getMonotonicityForRange callers pass the key column's raw type rather than a
stripped one. Index analysis can only become more conservative as a result.

This mirrors the Time/Time64 target guard in the same struct, which fixed the
same class of defect for a different carrier.

Sources whose monotonicity claim was inert because the conversion itself
throws (Decimal, IPv4, IPv6, Time64) now return no claim as well, which is
strictly safer and changes no observable behaviour.
…order

The previous commit's message said `ConvertImpl` pairs a `DateTime` target with
an order-preserving transform for `Date`, `Date32`, the native integers and
floats, `BFloat16`, `DateTime` and `DateTime64`, and the in-diff comment said
the allow-listed types saturate or fit `UInt32` exactly. That is wrong for
`Date`, `Date32` and `DateTime64`. At the default
`date_time_overflow_behavior = 'ignore'` `ToDateTimeImpl` takes neither its
`Throw` nor its `Saturate` branch and casts a `time_t` above the `UInt32` range
straight through, so `toDateTime(toDate('2149-06-06'))` is
`2013-04-29 17:31:44`, as `02900_date_time_check_overflow.reference` already
records. Those three sources are non-monotonic as well; that is a separate
defect, addressed by ClickHouse#117394 and ClickHouse#117031, and this change leaves them alone.

The allow-list itself is unchanged and remains correct. It declines the source
types that have no dedicated `DateTime` branch at all and are narrowed by a
plain `static_cast`, which is the defect the fuzzer hit. Only the justification
was overstated, and the comment now states what the allow-list is instead.
`index_granularity = 1` with `index_granularity_bytes = 0` is what makes the
granule count equal the row count whatever the runner randomizes, so the
assertions read the monotonicity decision rather than a granule layout.

`min_bytes_for_wide_part = 0` is load-bearing for a less obvious reason, so it
now says so. `index_granularity_bytes = 0` turns off adaptive granularity, and
`MergeTreeData::canUsePolymorphicParts` then reports a reason whenever
`min_rows_for_wide_part` or `min_bytes_for_wide_part` is not zero, because parts
with non-adaptive granularity can be stored only in Wide format. The test runner
randomizes `min_bytes_for_wide_part` over `[0, 1 GiB]`, and it fails a run on any
server warning, so without the pin 37 of 50 runs failed on that warning with
correct query results; with it, 50 of 50 pass.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Sep 4, 2026
@groeneai

groeneai commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex), two rounds.

# Sev Finding Verdict Evidence / action
1 ❌ The comment justifying the allow-list said the admitted sources saturate or fit UInt32; Date, Date32 and DateTime64 wrap instead at the default date_time_overflow_behavior = 'ignore' AGREE, fixed Reworded to state what the allow-list is, which holds for all fifteen admitted types; 02900_date_time_check_overflow.reference records the wrap, and the residual is in the description
2 ⚠️ toDateTime(x, <scale>) returns DateTime64 but borrows the DateTime monotonicity trait, so this guard also drops its pruning (4/4 granules, against 0/4 for toDateTime64(x, <scale>)) AGREE, disclosed Pre-existing as a trait binding: FunctionConvert::getMonotonicityForRange never receives the resolved result type. Stated in the description with the measurement, since the fix belongs with the binding rather than here
3 💡 Two pinned table settings in the new test carried no stated reason AGREE, fixed Measured: min_bytes_for_wide_part = 0 is load-bearing (13 of 50 runs pass without it) and now says why

Round 2 re-review of the resulting tree: no findings.

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-9:20260904-093500

@clickhouse-gh clickhouse-gh Bot closed this Sep 4, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1dc0b83]

Summary: ✅


AI Review

Summary

This PR correctly reroutes ordinary Enum8/Enum16 to Date/DateTime conversions through the same saturating transforms used for Int8/Int16, and the added stateless coverage exercises the value-level fix and the original primary-key misbehavior. The remaining problem is that the same conversion family is still wrong for accurateCast and accurateCastOrNull, which continue to bypass the accurate temporal path for enum inputs and silently return a value where their documented contract says they must throw or return NULL.

Findings

⚠️ Majors

  • [src/Functions/FunctionsConversion.h:2209-2213, 2258-2266; src/Functions/FunctionsConversion.cpp:428-434, 479-509] [dismissed by author -- https://github.com/Saturate an Enum8 or Enum16 converted to DateTime or Date #118039#issuecomment-5779194014] These new enum temporal branches still feed accurateCast/accurateCastOrNull only through the ordinary-cast fallback, because enums are excluded both from can_apply_accurate_cast and from the numeric accurate-cast dispatcher. That leaves accurateCast(Enum8('neg' = -1), 'DateTime') and accurateCastOrNull(..., 'Date') silently succeeding via the new saturating path instead of rejecting the lossy conversion, which still violates the documented accurateCast* contract in [src/Functions/CastOverloadResolver.cpp:385-387, 425-428].
    Suggested fix: route enum sources through the accurate temporal path as well (or reject them explicitly) and add a focused regression case for accurateCast / accurateCastOrNull on negative Enum8/Enum16 to Date / DateTime.
Tests
  • ⚠️ 05238_enum_to_datetime_overflow.sql covers CAST, Nullable, materialize, and key-condition behavior, but it does not exercise the separate accurateCast* wrapper-selection path in [src/Functions/FunctionsConversion.cpp:428-434], so the remaining inaccurate enum surface stays invisible.
Final Verdict

⚠️ Changes still needed. The ordinary toDate* / CAST fix looks correct, but the accurateCast* surface remains incorrect for the same enum-to-temporal conversions.

LLVM Coverage Report

Measured on commit 1dc0b83.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 2/2 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 4, 2026
@groeneai

groeneai commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @nihalzp @hanfei1991, could you review this? ConvertImpl narrows Enum8, Enum16, the wide integers and Time to DateTime with a plain static_cast<UInt32> that wraps, but ToDateTimeMonotonicity claimed monotonicity for them anyway, so applyMonotonicFunctionsChainToRange returned an inverted granule range. A comparison atom then silently drops matching granules in every build, and a set atom raises Invalid binary search result in MergeTreeSetIndex in debug builds.

@yariks5s yariks5s self-assigned this Sep 4, 2026
Comment thread src/Functions/FunctionsConversion.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 1dc0b83f0 with master 026dca38e (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 7264abe5d; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

61 translation units recompiled, 464 s compile time in total, 61 of them have a recent master baseline.

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... label Sep 4, 2026
@yariks5s

yariks5s commented Sep 7, 2026

Copy link
Copy Markdown
Member

@groeneai please update your branch with master

@groeneai

groeneai commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

Updated: merged master at 16723d7e43a27fb1925d29f8f11c3a46e51b045a into the branch, new head 3976352cf92fdabe41e8ab56f5d836953fa1313d. Clean merge, no conflicts, and the PR diff is unchanged (same 4 files, +88/-0). CI is running on the new head.

@groeneai

groeneai commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 3976352

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build profile diff CI-infra: the has_pr_data probe raises CI logs cluster query failed on the binary_sizes read (ci/jobs/build_profile_diff_job.py:721) #118685 (mine, open)
Sync - CH Inc sync (private, not actionable by me)

Session id: cron:our-pr-ci-monitor:20260908-013052

@groeneai

Copy link
Copy Markdown
Collaborator Author

Master has fixed most of what this PR guards, so I am reducing the diff rather than just resolving the conflict.

#118717 (merged 2026-09-13) makes (U)Int128/(U)Int256 saturate when converted to DateTime, and ToDateTimeMonotonicity now returns a non-monotonic verdict for Time/Time64 sources on its own. Measured on master 688ee332, as the UInt32 image of toDateTime32:

source, low / high image of low image of high order
Int256 -1 / 4294967296 0 4294967295 preserved
UInt128 0 / 4294967296 0 4294967295 preserved
Enum16 -1 / 0 4294967295 0 inverted

Of the 7 source types this PR rejects, 4 (the wide integers) are now order-preserving, so the guard would remove their primary-key pruning: WhichDataType::isNativeNumber() covers only the native 8- to 64-bit integers and floats, so the 128- and 256-bit ones fall into the return {} arm. Time is now redundant. Landing this diff as written would regress what #118717 fixed, so I am not pushing it.

Enum8/Enum16 still narrow with a wrapping static_cast<UInt32> and still give wrong results. Over a MergeTree key of Enum16('neg' = -1, 'zero' = 0) holding both members, SELECT count() FROM t WHERE toDateTime32(x) = toDateTime(0) returns 0, where the same predicate evaluated without the index returns 1.

The PR's own test agrees: run against plain master, both enum arms return 0 against a reference of 1, while both wide arms now return 2 in the indexed and the non-indexed case, so their expected values encode the old wrapping behaviour.

I will reduce this to the Enum case with the test re-baselined, and push that.

groeneai and others added 2 commits September 22, 2026 13:10
…time-static-cast-monotonicity

# Conflicts:
#	src/Functions/FunctionsConversion.h
ConvertImpl's if-constexpr chain reaches Enum8/Enum16 as genuine FromDataTypes
(callOnTypeIndex.h maps TypeIndex::Enum8 to DataTypeEnum<Int8>), but the two
special-case branch lists for a date/time target enumerate the concrete integer
and float types and never name the Enums, and IsDataTypeNumber<DataTypeEnum<T>>
is unspecialised, so the IsDataTypeNumber-gated branches miss them too. An enum
source therefore fell through to the generic numeric path and was converted by
a plain static_cast, which is modular rather than saturating:
static_cast<UInt32>(Int8(-1)) is 4294967295.

ToDateTimeMonotonicity meanwhile accepts any source for which
isValueRepresentedByNumber() holds, true for Enum, and returns always-monotonic,
so KeyCondition::applyMonotonicFunctionsChainToRange mapped the key range
through the wrapping conversion with no guard against left > right. A range
spanning zero came out inverted: granules holding matching rows were discarded,
and MergeTreeSetIndex::checkInRange tripped its own begin > end consistency
check, which throws LOGICAL_ERROR under ifndef NDEBUG and returns {true, true}
in release. So the debug abort is the CI signature and the wrong query results
are the release-visible face of one defect.

Adding the two types to the two branch lists makes an enum equivalent to the
integer it is stored as at this seam: same FieldType, same ColumnVector, same
transform instantiation, and the same non-strict Monotonicity the struct already
returns for Int8/Int16, which is right for a saturating many-to-one map. No
monotonicity struct is touched and no new monotonicity semantics are introduced.
This is the design ClickHouse#118717 used for (U)Int128/(U)Int256 against the same defect,
and it restores the invariant ClickHouse#117394 states for numeric arguments.

Measured on 26.8.11.7 (LTS), each enum beside the integer it is stored as:

    toDateTime(Enum8('neg' = -1))       2106-02-07 06:28:15   vs 1970-01-01 00:00:00
    toDate(Enum8('neg' = -1))           2149-06-06            vs 1970-01-01
    toDateTime(Enum16('lo' = -32768))   2106-02-06 21:22:08   vs 1970-01-01 00:00:00
    toDate(Enum16('lo' = -32768))       2059-09-19            vs 1970-01-01

Over a MergeTree table keyed by Enum16('neg' = -1, 'zero' = 0) holding both
members, SELECT count() FROM t WHERE toDateTime(x) = toDateTime(0) returned 0
where the same predicate counted without the index returned 1, and the IN form
aborted a debug build in checkInRange. In-range enum values are unaffected: every
positive member is inside both result ranges.

Four other branch lists name Int8/Int16 and still omit the Enums, and are
deliberately not mirrored here because no carrier was measured behind them:
to Date32 (static_cast<Int32> of Int8/Int16 is exact over the whole enum range),
to Time (Time caps at plus or minus 3599999 seconds, so the whole enum range is
inside it), and to DateTime64 and Time64 (an enum source is rejected with
Code: 70, so the conversion is unreachable).

date_time_overflow_behavior has no effect for an enum source before or after
this change: the GENERATE_OVERFLOW_MODE_CASE switch sits inside a predicate that
is false for Enum, so ConvertImpl is always instantiated with the default Ignore.
Measured under ignore, saturate and throw, an enum agrees with Int8 in all three.
That is the pre-existing family-wide gap ClickHouse#118717's own merged test records, and
it is out of scope here.

05076_datetime_conversion_monotonicity_static_cast is deleted rather than
rebaselined: its wide-integer arms encode the pre-ClickHouse#118717 wrapping semantics, so
four of its reference values now pin behaviour master deliberately changed. The
new 05238_enum_to_datetime_overflow covers the conversion image beside the
integer, in-range controls, the CAST and wrapper forms, the overflow modes, and
the primary-key arms including the one that reproduces the assertion.

Related: ClickHouse#113515
Related: ClickHouse#116946
Related: ClickHouse#118717

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai changed the title Do not claim toDateTime is monotonic for source types it narrows by a plain cast Saturate an Enum8 or Enum16 converted to DateTime or Date Sep 22, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review of the reduced diff (3 files, src/ +6/-1) by an independent model
(engine: codex; 3 findings) plus a cold read of my own. Base pinned at 7b3eac99f3280, the merge base.

# Sev Finding Verdict Evidence / action
1 ⚠️ accurateCast reaches these new branches through its ordinary-cast fallback, so a lossy negative enum to DateTime still succeeds instead of being rejected (FunctionsConversion.cpp:428-430) DISAGREE on where the fix lands; the defect itself is conceded The enum form returns a value both before this change (2106-02-07 06:28:15) and after (1970-01-01 00:00:00), where toInt8(-1) throws Code: 70, so this PR neither creates nor widens the gap. can_apply_accurate_cast is target-agnostic, so the remedy alters accurateCast of an enum to every numeric target: accurateCast(Enum8(-1), 'UInt8') would begin throwing where it now returns 255. That compatibility surface is its own change, so I put it to you in the description rather than folding it in
2 ⚠️ The primary-key arms assert counts only, so they would still pass if the monotonic-function chain were disabled or bypassed DISAGREE Disabling that chain full-scans and returns the same correct counts, so the oracle asked for pins a performance property, not a correctness one. The arms are live for the defect they guard, measured whole-file: the shipped .reference was generated on the fixed build and replayed against the unfixed one, where 8 of 12 lines differ and the run aborts before the last three. Analysis provably ran unfixed (a skipped analysis returns 1 1, and EXPLAIN indexes = 1 printed Granules: 0/1). The merged precedent for this defect class, 05156_big_integer_to_datetime_overflow, has no EXPLAIN and asserts its key arm with counts
3 💡 The comment introducing the Date branch enumerates its source types and omits the two enums now added to it, while the sibling DateTime branch documents them AGREE, not changed Correct, and noted rather than silently left: that comment is pre-existing and outside this diff. The commit message carries the reasoning, including the four sibling branch lists (Date32, Time, DateTime64, Time64) deliberately not mirrored and why each is safe. Say the word and I will add the line

Two checks produced no finding, recorded so they are not re-derived. Merged #118717 also edited
FunctionsConversion_reg.cpp, but only to correct text claiming wide integers wrap instead of saturating,
and no in-tree documentation mentions an enum source, so nothing here is falsified. The 2026-09-04 thread
about toDateTime(x, scale) sharing ToDateTimeMonotonicity<DataTypeDateTime> is moot under this design,
since no monotonicity struct is touched.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal
per finding.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, two, both without any pinned setting on a two-row Enum16 key. Wrong results: SELECT (SELECT count() FROM t WHERE toDateTime(x) = toDateTime(0)), (SELECT countIf(toDateTime(x) = toDateTime(0)) FROM t) gives 0 1. Assertion: SELECT count() FROM t WHERE toDateTime(x) IN (toDateTime(0), toDateTime(1)) aborts a debug build with Logical error: 'Invalid binary search result in MergeTreeSetIndex'. Zero flake, 5/5 and 4/4.
b Root cause explained? ConvertImpl's branch lists for DateTime and Date enumerate the concrete integer and float types and never name Enum8/Enum16, and IsDataTypeNumber<DataTypeEnum<T>> is unspecialised, so an enum falls through to the generic numeric path and is converted by a plain static_cast: static_cast<UInt32>(Int8(-1)) is 4294967295. ToDateTimeMonotonicity meanwhile accepts any isValueRepresentedByNumber() source and returns always-monotonic, so KeyCondition maps the key range through the wrapping conversion, the range comes out inverted, matching granules are dropped, and MergeTreeSetIndex::checkInRange trips its own begin > end check (LOGICAL_ERROR under #ifndef NDEBUG, {true, true} in release).
c Fix matches root cause? Yes. The wrapping cast is the root cause and the fix is at that seam: four std::is_same_v clauses adding the two Enum types to the two branch lists, so they use the saturating transforms their underlying integers already use. No monotonicity claim withdrawn, no bound widened, no guard at the abort site, no no-random-* tag, no data reduction. It is also the layer the area owner chose for the identical defect in #118717.
d Test intent preserved / new tests added? 05238_enum_to_datetime_overflow added: conversion image beside the integer, in-range controls, CAST/Nullable/non-constant wrappers, overflow modes, and the primary-key arms including the one that reproduces the assertion. 05076_datetime_conversion_monotonicity_static_cast is deleted rather than weakened: its wide-integer arms encode the pre-#118717 wrapping semantics, so four of its reference values now pin behaviour master deliberately changed. The gtest is reverted to master's version, which asserted no Enum case, so no coverage is lost.
e Both directions demonstrated? Yes, on Build-ID-verified binaries (bd86b934... unfixed, 12c9a98d... fixed) from the same tree. Every enum arm is unequal to its integer before and equal after; the index arm moves 0 1 to 2 2; the set-index arm moves SIGABRT to 2. The shipped .reference was generated from the fixed binary and replayed against the unfixed one: 8 of 12 lines differ and the run then aborts.
f Fix is general across code paths? Yes, measured on both binaries rather than argued. Fixed: Enum to DateTime and to Date. Verified unchanged: Date32 (1880-04-14), Time (-09:06:08), toUnixTimestamp (4294967295), and the (U)Int128/(U)Int256 path #118717 fixed. DateTime64/Time64 reject an enum with Code: 70, before and after. The four sibling branch lists with no measured carrier are named in the commit message as deliberately not mirrored.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Six forms agree: plain, toNullable, materialize, array element, CAST AS DateTime, CAST AS Nullable(DateTime). LowCardinality(Enum8) is not a legal type (Code: 43), so it is not a case that can exist. Boundaries, each equal to its integer for both targets: Enum8 at -128, 0, 127; Enum16 at -32768, 32767. date_time_overflow_behavior ignore/saturate/throw all give enum equal to Int8; none consults the setting, which is the pre-existing family-wide gap #118717's own test records.
h Backward compatible? Yes. No setting, format or serialization change, so no SettingsChangesHistory.cpp entry and no versioning obligation. The only behaviour change is the conversion result for a negative enum value, which is the bug fix; #118717 set the precedent for making exactly this change with no compatibility gate for the types next door.
i Invariants and contracts preserved? Yes. The branch lists' contract is that a numeric-represented source narrower than the target goes through the saturating transform, and adding the two types that were its sole exception is what makes it hold. An enum presents the same FieldType and the same ColumnVector<Int8>/ColumnVector<Int16> its integer does, so the transform instantiation and DateTimeTransformImpl's column check are unchanged, and the Monotonicity value returned is the one already returned for Int8/Int16. The diff adds no statement, so no error or early-return path changes.

Session id: cron:clickhouse-impl-slot-7:20260922-130700

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118039&sha=377c4dfccf135d9c5f489fbe61f38725b1847d55&name_0=PR&name_1=Storage%20memory%20check and provide a fix in a separate PR. If the fix is already in progress, link it here.

The only red is Storage memory check / 03_add_secondary_indexes.sql (+1,056 bytes, 3.5%). It is unrelated to this PR, which only changes how Enum8/Enum16 convert to Date/DateTime. The same +1,056-byte delta shows up on at least 12 unrelated PRs between 2026-09-16 and 2026-09-22 (#121054, #119462, #112950, #120960, #118640, ...). The candidate fixes #121364 and #121545 are still open. The failure stopped the rest of the workflow (stress, fuzzers and performance jobs were skipped), so CI needs a rerun once one of those fixes lands on master.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Investigated. No new PR from me: #121364 is exactly this failure, already open and approved.

Per-stack, on the failing head 377c4dfccf13: the cross-version diff for 03_add_secondary_indexes.sql is 39 stacks summing to +1,056 B. The 7 stacks carrying a DB::ThreadStatus::attachToGroup / detachFromGroup / ThreadStatus frame sum to +1,056 B (+768, +128, +96, +64, +64, +64, -128), and the other 32 sum to 0 B. #121364 excludes exactly those three prefixes, so this report becomes 0 B, like the eight other scenarios in the same run.

Not attributable to any diff, at byte level: the pair master=30,248 / PR=31,304 is identical on this PR and five unrelated ones (#119462, #112950, #120960, #118640, #56335) over the last four days.

Fix presence:

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 377c4df

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Storage memory check / 03_add_secondary_indexes.sql not PR-caused, not attributable to this diff: eight of the nine scenarios move exactly 0 B; the +1,056 B of the ninth is carried entirely by the 7 stacks with a DB::ThreadStatus::{attachToGroup,detachFromGroup,ThreadStatus} frame, and the same 30,248 / 31,304 pair is character-identical on five unrelated pull requests in the last four days fixing PR #121364 (mine, open)

176 checks, all completed: 134 success, 39 skipped, 1 failing job (the two remaining reds are the
Mergeable Check and PR rollups of that job). CIDB holds 312,771 rows across 135 checks at this
commit with exactly one FAIL/ERROR row, the one above. Merged #120487 is present on this head
and does not cover this class. A rerun is due once #121364 lands.

Session id: cron:our-pr-ci-monitor:20260922-230208

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - a61d971

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Upgrade check (amd_release) / Error message in clickhouse-server.log pre-existing, not this diff: the PREVIOUS release creates a table the NEW server refuses to attach, Code: 69 ... The range given in function countResample is empty: Cannot attach table test_3.t6 in AsyncLoader::worker #121590 (external, merged into 26.9)
Upgrade check (amd_release) / The mutation submitted before the upgrade was not finished by the new server downstream of the row above, same job and same run: the table never attaches, so the mutation submitted before the restart can never complete #121590 (external, merged into 26.9)

One honest qualification on that owner, because it changes what to expect, and it is measured
rather than assumed: #121590 merged into the 26.9 release branch as 4d46c03d0066, and that
commit is NOT reachable from master (compare/master...4d46c03d0066 = diverged, 4125 behind;
compare/26.9...4d46c03d0066 = behind, 0 ahead, so it is an ancestor of 26.9 only). 26.9 is
the line this job DOWNLOADS as the "previous release", so the usual "merge master to pick the
fix up" step does not apply here and was deliberately not taken. The check turns green once a
26.9 patch release containing it is published. 134 checks succeeded, 39 were skipped, and
Mergeable Check / PR are the praktika aggregators, not separate failures.

Session id: cron:our-pr-ci-monitor:20260923-163416

@Algunenano
Algunenano removed their request for review September 24, 2026 09:58
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 1, 2026
Merged via the queue into ClickHouse:master with commit 78da18d Oct 1, 2026
149 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants