Repository navigation
Description
Company or project name
No response
Describe what's wrong
A TTL ... GROUP BY ... SET assignment whose aggregate function takes an expression as an argument, such as sum(value * 2), sumIf(value, value > 15) or sum(if(value > 15, value, 0)), is accepted by CREATE TABLE and ALTER TABLE ... MODIFY TTL, but the merge that applies the rule fails with NOT_FOUND_COLUMN_IN_BLOCK for the argument expression. An aggregate over a plain column, such as sum(value), works.
TTLDescription::getTTLFromAST (src/Storages/TTLDescription.cpp) analyzes each assignment with ExpressionAnalyzer and keeps getActions(false) as TTLAggregateDescription::expression (the actions after the aggregation) together with the aggregate_descriptions, whose argument_names are the names of the argument expressions, such as multiply(value, 2). TTLAggregationAlgorithm feeds the aggregator the columns of the block by those names, but nothing computes the argument expressions before the aggregation, so the block has only the physical columns.
Consequences:
OPTIMIZE TABLE ... FINALreturns the exception;- with
materialize_ttl_after_modify = 1(the default), the mutation thatALTER TABLE ... MODIFY TTLstarts fails with the same exception (Exception happened during execution of mutation 'mutation_2.txt' ...); - the expired rows are never aggregated.
The test 05293_ttl_expression_uses_server_settings defines such a rule (SET v = max(tumbleStart(toStartOfHour(ts), toIntervalHour(1)))) but does not merge the table.
Does it reproduce on the most recent release?
Yes. It reproduces with the same exception on 25.1.3.23, 25.8.33.6, 26.3.48.2, 26.10.2.103 and master 26.11.1.880.
How to reproduce
CREATE TABLE t (k UInt8, event DateTime, value UInt64) ENGINE = MergeTree ORDER BY k
TTL event + INTERVAL 1 SECOND GROUP BY k SET value = sum(value * 2);
INSERT INTO t VALUES (1, '2020-01-01 00:00:00', 10), (1, '2020-01-01 09:00:00', 20);
OPTIMIZE TABLE t FINAL;The same with SET value = sumIf(value, value > 15), SET value = sum(if(value > 15, value, 0)) or SET value = sumIf(value, event > toDateTime('2020-01-01 00:00:00')), and with the rule set by ALTER TABLE t MODIFY TTL ... on a table with rows.
Expected behavior
The merge computes the argument expressions and aggregates them: SELECT value FROM t returns 60 for sum(value * 2). If such assignments are not meant to be supported, CREATE TABLE and ALTER TABLE ... MODIFY TTL should reject them instead of accepting a rule that no merge can apply.
Error message and/or stacktrace
Code: 10. DB::Exception: Not found column multiply(value, 2) in block. There are only columns: k, event, value. (NOT_FOUND_COLUMN_IN_BLOCK)
Related issues and pull requests
Related: #121168
Related: #127982
Additional context
#121168 is a different defect of the same rules: an IN subquery in an assignment builds a set that no TTL merge fills. This one was found while working on #127982, which rewrites DateTime literals in such assignments: its test checks the stored definition because the merge fails before the literal matters.
Activity
PedroTadim commentedon Nov 2, 2026
@groeneai is the fix for this small? If so, you can do it
groeneai commentedon Nov 2, 2026
Yes, it looks small.
TTLDescription::getTTLFromASTkeeps only the actions after the aggregation, so nothing computes the aggregate arguments beforeAggregator::executeOnBlockinTTLAggregationAlgorithm. The fix keeps the actions that compute the arguments from the stored columns and runs them on the expired rows before aggregating; it should stay withinTTLDescriptionandTTLAggregationAlgorithm.A subcolumn argument fails the same way on master (
SET tup = tuple(max(tup.ts), 0)givesNot found column tup.ts in block), so the PR will cover it too. I'll follow up here with the PR.groeneai commentedon Nov 2, 2026
The PR is #128758. It covers expression and subcolumn arguments, including the shapes of #63800 and #53230. A subquery, or an
INwith a table, inside an aggregate argument is now rejected byCREATE TABLEandMODIFY TTL, because a TTL merge cannot evaluate it.