Skip to content

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

Merged
clickhouse-gh[bot] merged 3 commits into
26.6from
backport/26.6/101793
Sep 13, 2026
Merged

clickhouse-gh[bot] merged 3 commits into
26.6from
backport/26.6/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 #117985

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.6.6.8

@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 [55f820c]

Summary: ✅

The backport dropped the master-only `required_source_columns` out-parameter of
`buildExpressionAndSets`, but this call site passed it positionally as `nullptr`,
so it was left with one argument too many.

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

`04077_datetime32_overflow` fails on this backport in case 12
(`MODIFY TTL ts + INTERVAL 1 DAY DELETE WHERE toTypeName(ts) =
'DateTime'`) with:

    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, and the pair
is rebuilt on every `INSERT`, every merge and every table load. On
this branch that list is taken from the *built* expression via
`ExpressionActions::getRequiredColumnsWithTypes`, so constant folding
drops columns the AST still refers to: `toTypeName(ts)` folds to a
literal, the stored column list comes out empty, and the next rebuild
of the same AST cannot resolve `ts` any more.

`master` and `26.8` do not have this problem because they take the
list from the syntax analysis, which sees the AST before folding. That
change landed on `master` in `f0bf4fce55ed` ("Keep a TTL expression
rebuildable and loadable"), which is not in this branch, so the
backported test exercises a code path the backport had no fix for.

This is the same adaptation already merged into `26.7` as
`96b9965489c4`, applied verbatim. Only the `required_source_columns`
part of the `master` commit is taken - the part this backport depends
on; its unrelated half (pinning `Variant` / `Dynamic` type-mismatch
strictness through `TypeMismatchStrictness`) is deliberately left out
of a bug-fix backport.

Because the timestamp expression is analyzed against widened
(`Date32` / `DateTime64`) columns, the reported list is mapped back to
the table's original narrow types, so it stays a subset of the columns
the caller passed and every later rebuild widens them again from the
real table types. Subcolumn names reported by the analysis (e.g.
`j.ts` of a `JSON` column) are kept as reported;
`04847_ttl_where_json_subcolumn` covers that path and is added along
with the mechanism it needs.
@clickhouse-gh
clickhouse-gh Bot merged commit fd33487 into 26.6 Sep 13, 2026
38 of 39 checks passed
@clickhouse-gh
clickhouse-gh Bot deleted the backport/26.6/101793 branch September 13, 2026 21:16
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.

4 participants