Skip to content

Fix TTL expressions with subcolumns causing exception on INSERT and merge - #105578

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-ttl-subcolumn-expression
May 31, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-ttl-subcolumn-expression

Conversation

@Avogar

@Avogar Avogar commented May 21, 2026 •

Copy link
Copy Markdown
Member

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):

Fix NOT_FOUND_COLUMN_IN_BLOCK exception when TTL expression references a subcolumn.

Version info

  • Merged into: 26.6.1.281-master (included in 26.6 and later)
  • Backported to: 26.3.61.11

Avogar and others added 2 commits May 21, 2026 18:54
…erge

`executeExpressionAndGetColumn` used `block.getByName` to collect required
columns before evaluating the TTL expression. This fails when the required
column is a subcolumn (e.g. `t.d` from a Tuple column `t`) because
`getByName` only finds top-level columns in the block.

Replace with `getColumnOrSubcolumnByName` which tries `getByName` first
and falls back to extracting the subcolumn from its parent column.

This fixes both the insert path (`updateTTL` in MergeTreeDataWriter) and
all merge-time TTL paths (TTLDeleteAlgorithm, TTLDeleteFilterTransform,
TTLUpdateInfoAlgorithm, TTLAggregationAlgorithm, TTLColumnAlgorithm)
since they all go through `executeExpressionAndGetColumn`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Remove unnecessary `no-random-merge-tree-settings` tag. Use separate
INSERTs to create multiple parts and `OPTIMIZE TABLE ... FINAL` with
`mutations_sync = 1` to force a merge that exercises the TTL evaluation
during merge, not just during insert.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [601bcdc]

Summary: ✅


AI Review

Summary

This PR fixes TTL evaluation for subcolumns by switching ITTLAlgorithm::executeExpressionAndGetColumn from Block::getByName to Block::getColumnOrSubcolumnByName, and adds focused stateless coverage for tuple and JSON subcolumns through insert and merge (OPTIMIZE ... FINAL) paths. I reviewed the current diff and surrounding code paths and did not find unresolved correctness, safety, or compatibility issues.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 21, 2026
@Ergus Ergus self-assigned this May 22, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 100.00% (4/4) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 31, 2026
Merged via the queue into master with commit 974290b May 31, 2026
166 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-ttl-subcolumn-expression branch May 31, 2026 08:30
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 31, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 23, 2026
alexey-milovidov added a commit that referenced this pull request Oct 24, 2026
Resolve the conflict in `src/Processors/TTL/ITTLAlgorithm.cpp` by taking
the 26.3 side: it already reads TTL inputs with
`getColumnOrSubcolumnByName` (adapted in the backport of #101793), and
additionally casts them to the types the expression expects. The code fix
of #105578 is therefore already present on 26.3; this backport only adds
the test `04266_ttl_with_subcolumn_expression`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-ch-test-poll2 added a commit that referenced this pull request Oct 24, 2026
Cherry pick #105578 to 26.3: Fix TTL expressions with subcolumns causing exception on INSERT and merge
robot-clickhouse added a commit that referenced this pull request Oct 24, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 24, 2026
alexey-milovidov added a commit that referenced this pull request Oct 25, 2026
Backport #105578 to 26.3: Fix TTL expressions with subcolumns causing exception on INSERT and merge
leshikus pushed a commit that referenced this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport v26.4-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants