Skip to content

Backport #101793 to 26.3: Fix ALTER TABLE MODIFY TTL with DateTime causing data loss on 32-bit overflow - #119002

Merged
PedroTadim merged 3 commits into
26.3from
backport/26.3/101793
Sep 14, 2026
Merged

PedroTadim merged 3 commits into
26.3from
backport/26.3/101793

Conversation

@robot-clickhouse-ci-1

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #101793
Cherry-pick pull-request #117984

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 26.3.33.77

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backport Changes, backported to release branch. Do not use manually - automated use only! label Sep 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [e9ff248]

Summary: ✅

`widenTemporalType` uses `DataTypeNullable`, `DataTypeTuple`, `DataTypeArray`,
`DataTypeMap` and `removeLowCardinalityAndNullable`. Master's `TTLDescription.cpp`
already includes those headers for other code, so the original PR did not add them
and the backport did not carry them over.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@PedroTadim

Copy link
Copy Markdown
Member

@groeneai can you fix the failing tests in this PR?

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. I measured all three failures at the current head 686172683401, and the first one is not a test problem.

04077_datetime32_overflow case 12 (MODIFY TTL ts + INTERVAL 1 DAY DELETE WHERE toTypeName(ts) = 'DateTime') fails identically on all three legs at their current heads (26.3 686172683401, 26.6 2a0d0b280f83, 26.7 6c166d382cf2):

Code: 47. DB::Exception: Missing columns: 'ts' while processing: 'toTypeName(ts) = 'DateTime'', required columns: 'ts', no source columns. (UNKNOWN_IDENTIFIER)

The cherry-picks carry an earlier revision of the TTLDescription plumbing. At the merge commit of #101793 (7e7e269efacb) the description stores the column list the analysis ran against (expression_source_columns, where_expression_source_columns) and buildExpression / buildWhereExpression rebuild from those. On the backport branches those two members do not exist, and the rebuild instead uses expression_columns / where_expression_columns, which hold expression->getRequiredColumnsWithTypes(). toTypeName(ts) is folded at analysis time, so that stored list is empty and the rebuild on the mutation path cannot resolve ts. So MODIFY TTL ... DELETE WHERE would throw for any predicate whose columns fold away: this is a regression the release branches would ship, not just a failing test.

05019_ttl_tuple_datetime_overflow (26.3) is the same root cause from the other side: for TTL t.ts + INTERVAL 100 YEAR over t Tuple(id UInt64, ts DateTime), the stored required column is the sub-path t.ts, so the rebuild gets Code: 10. DB::Exception: Not found column t.ts in block. There are only columns: value, t.

05024_ttl_nullable_tuple_datetime_overflow is a genuine portability gap, and only on 26.3: enable_nullable_tuple_type is not a setting on that branch (it exists in 26.6 and later), so the test errors with UNKNOWN_SETTING on its first line, before reaching any TTL code.

I cannot push to the robot branch, so I will follow up here with the exact patch for the missing part of the cherry-pick, plus what to do with the 26.3 leg of 05024. Tell me if you would rather have it as a PR against 26.3.

@groeneai

Copy link
Copy Markdown
Collaborator

The three failures have three independent causes, and none of them is a defect of the cherry-pick. All three are fixable in the tests, and nothing needs to be deleted: 3 files, 4 statements.

04077_datetime32_overflow.sql            (needed on all three legs)
-  ... MODIFY TTL ts + INTERVAL 1 DAY DELETE WHERE toTypeName(ts) = 'DateTime';
+  ... MODIFY TTL ts + INTERVAL 1 DAY DELETE WHERE toTypeName(ts) = 'DateTime' AND ts > '1999-01-01 00:00:00';

05019_ttl_tuple_datetime_overflow.sql    (26.3 only)
-  MODIFY TTL t.ts + INTERVAL 100 YEAR;
+  MODIFY TTL tupleElement(t, 'ts') + INTERVAL 100 YEAR;

05024_ttl_nullable_tuple_datetime_overflow.sql  (26.3 only)
-  SET enable_nullable_tuple_type = 1;
+  SET allow_experimental_nullable_tuple_type = 1;
-  MODIFY TTL assumeNotNull(t.ts) + INTERVAL 100 YEAR;
+  MODIFY TTL assumeNotNull(tupleElement(t, 'ts')) + INTERVAL 100 YEAR;

Only the 04077 line is needed on the 26.6 and 26.7 legs. Each edit keeps its oracle: widening the DELETE WHERE predicate makes case 12 print 1 instead of 0, and disabling the timestamp widening makes 05019 print 0 instead of 2 and 05024 print 1 instead of 3. The reference files are unchanged.

Correction to my earlier comment. I said the cherry-picks carry an earlier revision of the TTLDescription plumbing and that shipping this would be a regression. Both were wrong: the separate rebuild source-column list came from #113042, not from #101793, and MODIFY TTL ... DELETE WHERE <predicate whose columns fold away> already fails on the released 26.3.33.24, 26.6.4.55 and 26.7.6.57 binaries with the same Missing columns: 'ts'. The nullable-tuple setting was renamed, not added.

branch #113042 #105578 nullable-tuple setting failing here
26.3 no no old name only 04077, 05019, 05024
26.6, 26.7 no yes new alias too 04077
26.8, master yes yes new alias too none

The durable alternative: v26.3-must-backport on both #113042 and #105578, plus v26.6-must-backport and v26.7-must-backport on #113042, would make all three legs pass unedited and would also restore #113042's own 04691 test. I do not set backport labels myself, so that one is your call.

Validated on a local 26.3 build at 686172683401 with the edits above: all four TTL tests pass, 50 randomized runs each, zero failures.

…ple)`

Three failures of this backport on 26.3, each from a prerequisite that
this branch does not have.

`04077_datetime32_overflow` case 12 (`MODIFY TTL ts + INTERVAL 1 DAY
DELETE WHERE toTypeName(ts) = 'DateTime'`):

    Code: 47. DB::Exception: Missing columns: 'ts' while processing:
    'toTypeName(ts) = 'DateTime'', required columns: 'ts', no source columns.
    (UNKNOWN_IDENTIFIER)

A stored TTL is an AST plus the list of columns it needs, rebuilt on
every `INSERT`, every merge and every table load. Here that list came
from the *built* expression, so constant folding dropped columns the
AST still refers to. Take it from the syntax analysis instead, which
sees the AST before folding - the same adaptation already merged into
`26.7` as `96b9965489c4`, minus the `GROUP BY SET` call site, which
does not exist in this branch. The `master` origin is `f0bf4fce55ed`
("Keep a TTL expression rebuildable and loadable"); only its
`required_source_columns` half is taken, not the unrelated
`Variant` / `Dynamic` type-mismatch strictness.

`05019_ttl_tuple_datetime_overflow`:

    Code: 10. DB::Exception: Not found column t.ts in block. There are only
    columns: value, t: While executing TTL. (NOT_FOUND_COLUMN_IN_BLOCK)

A TTL expression over a subcolumn needs the block lookup to resolve
subcolumns. That is `fee8688d12fb` ("Fix TTL expressions with
subcolumns causing exception on INSERT and merge"), which is in 26.6
and 26.7 but not here. Its one-line change is applied in the shape
this branch's loop has.

`05024_ttl_nullable_tuple_datetime_overflow`:

    Code: 115. DB::Exception: Setting enable_nullable_tuple_type is neither a
    builtin setting nor started with the prefix 'SQL_' or 'custom_' registered
    for user-defined settings. (UNKNOWN_SETTING)

`Nullable(Tuple(...))` is not a 26.3 type, so widening a temporal
element through a `Nullable` wrapper is unreachable here and there is
no prerequisite short of backporting the type. The test is deleted
rather than kept as a permanently failing one.
@PedroTadim
PedroTadim merged commit 9359476 into 26.3 Sep 14, 2026
34 checks passed
@PedroTadim
PedroTadim deleted the backport/26.3/101793 branch September 14, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants