Repository navigation
Conversation
…n build A MergeTree whose TTL `GROUP BY ... SET` assignment contains `IN <table>` or `IN (SELECT ...)` was accepted at CREATE, and then every TTL merge of a part with expired rows failed with "Not-ready Set is passed as the second argument for function 'in'". The expired rows were never aggregated, OPTIMIZE TABLE FINAL returned the error, and the background merge retried indefinitely, so the affected parts could never merge. In an assertions-enabled build the merge thread aborts instead of only failing the merge. `getTTLFromAST` builds each assignment into prebuilt ExpressionActions and discards the analyzer's PreparedSets. A set whose right-hand side is a subquery or a non-Set-engine table is registered as a FutureSetFromSubquery, which is complete only after its caller builds it, and no consumer of `set_parts` does: TTLTransform::getExpressions collects the subqueries of the timestamp and WHERE expressions only, and MergeTask, MutateTask and MergeTreeDataWriter::updateTTL build exactly that collected list. So FunctionIn met an unbuilt set every time TTLAggregationAlgorithm executed the assignment. Record on TTLAggregateDescription whether the assignment needs such a set, taken from the analyzer that registered it, and reject it at DDL under the existing !skip_validation, next to the two checks that already guard this class in the same loop. The sibling DDL surfaces already reject both spellings for sorting and primary keys, partition keys, skip indexes and the TTL timestamp expression (checkExpressionDoesntContainSubqueries), so this closes the one carrier that was left. TTLValidationMode::Attach stays permissive on purpose: a rejection while metadata is being read fails the whole load rather than the one table, so the server would not start after an upgrade and a replica could not read the metadata another replica wrote. A stored definition therefore still loads and still accepts INSERTs, which never evaluate an assignment, and the same recorded fact is re-checked in TTLAggregationAlgorithm::finalizeAggregates, inside the branch whose precondition is that rows were aggregated for this rule, two lines above the execute() that raises the logical error today. The recorded fact is the analyzer's register, which names every set the analyzer built for the assignment, including one the built actions then drop. So an assignment that registers a set and never reads it is rejected too, where it used to merge: an `IN` under `indexHint`, whose argument ActionsVisitor analyses into a separate DAG built from the same PreparedSets while the executable node drops its arguments and returns a constant 1, and an `IN` in a branch that constant folding removes, which addFunctionImpl turns into a constant and removeUnusedActions then erases together with its children. That is deliberate: checkExpressionDoesntContainSubqueries rejects the same spellings for sorting and primary keys, partition keys, skip indexes and the TTL timestamp expression, because it recurses over every AST child regardless of what the enclosing function evaluates, and such an `IN` in a TTL SET assignment is a constant, so nothing expressible is lost. Where the built actions do read the registered set, the new BAD_ARGUMENTS fires exactly where the old LOGICAL_ERROR did, names the ALTER TABLE ... MODIFY TTL repair, and leaves merges that process TTL without aggregating anything for that rule succeeding. The predicate is the analyzer's register rather than a walk over the AST or the DAG, because neither can answer the question: a DAG scan cannot see an IN inside a lambda body, and an AST screen cannot see the EXISTS rewrite, which TreeRewriter performs during normalization, while it would wrongly reject a scalar subquery that is folded to a literal before the actions are built. Filling the set instead was rejected: its contents can change between merges, so the aggregated value would not be well defined. TTLAggregateDescription's copy constructor and assignment operator are hand-written and enumerate their fields, and every metadata copy passes through them, including result.set_parts.emplace_back, so both carry the new field; omitting it from either silently disables the whole check. Closes: ClickHouse#121168 Co-Authored-By: Claude Opus 5 <[email protected]>
Drop the Attach-mode design note above checkSetPartsAreExecutable and reflow the remaining invariant to two lines.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 4 gate findings over a full pass and two
Open choices worth naming rather than leaving for a reviewer to find:
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260921-034200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260920-224400 |
|
Workflow [PR], commit [78b277c] Summary: ❌
AI ReviewSummaryThis PR records whether a TTL Findings
Final VerdictStatus: Minimum required actions:
LLVM Coverage ReportMeasured on commit 78b277c.
Changed lines: Changed C/C++ lines covered: 32/32 (100.00%) · Uncovered code |
…ses it checkSetPartsAreExecutable is reached from CREATE TABLE, from a rejected ALTER TABLE ... MODIFY TTL, and from a TTL merge or mutation of a table that already stores such a definition. The remediation named only the last of the three: on either DDL path, being told to run ALTER TABLE ... MODIFY TTL restates the statement that just failed. The message now asks for the expression to be rewritten, and keeps ALTER TABLE ... MODIFY TTL as what it is, the way out for a table that already stores the definition. Wording only, so the error code and the test's serverError expectations are unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units812 translation units recompiled, 5836 s compile time in total, 812 of them have a recent master baseline. |
CI finish ledger - 78b277cEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Gates (a) to (d): 0 of 176 check runs queued or running, Session id: cron:our-pr-ci-monitor:20260921-140539 |
Closes: #121168
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reject an
INoperator that reads a subquery or a table inside a TTLGROUP BY ... SETassignment, atCREATE TABLEand atALTER TABLE ... MODIFY TTL. Such an assignment was accepted and then failed every TTL merge of a part with expired rows withNot-ready Set is passed as the second argument for function 'in', so those rows were never aggregated and the affected parts could never merge.Description
A
MergeTreewhose TTLGROUP BY ... SETassignment containsIN <table>orIN (SELECT ...)is accepted atCREATE, and then every TTL merge of a part with expired rows fails withNot-ready Set is passed as the second argument for function 'in'.getTTLFromASTstores each assignment as prebuiltExpressionActionsand drops the analyzer'sPreparedSets. Such a set is complete only once its caller builds it, and no consumer ofset_partsdoes, soFunctionInmeets an unbuilt set on every aggregation. Filling it instead cannot be made well defined, since its contents change between merges.I take that need from the analyzer that registered the set and reject the assignment at
CREATE TABLEand atALTER TABLE ... MODIFY TTL, as the key, skip index and TTL timestamp guards already do;allow_suspicious_ttl_expressionsstill allows it. Loading stored metadata stays permissive, so an older table attaches and still acceptsINSERTs, and the same fact is re-checked where the assignment executes. No signal is lost: theLOGICAL_ERRORreported a state a user could create, and what remains after the DDL check comes from older metadata, better served by an error naming theMODIFY TTLrepair.Because the predicate is that register, an assignment whose actions never read the set they built is rejected too, an
INunderindexHintfor instance; the key guards reject that spelling already, andindexHintin a TTL assignment is a constant. A literal set, aSet-engine table, a folded scalar subquery andTTL ... DELETE WHERE ... INkeep working.Workflow [PR]
Sync PR [sync-upstream/pr/121268]