Repository navigation
Conversation
A `TTL <expr> GROUP BY <keys> SET <assignments>` merge failed for every table holding a column whose type carries LowCardinality below the top level, such as Tuple(a LowCardinality(String), b UInt32), Array(LowCardinality(String)) or Map(LowCardinality(String), UInt32), when that column is neither a GROUP BY key nor a SET target. On official 26.4.5.143, OPTIMIZE TABLE ... FINAL returned `Code: 44 ... Expected ColumnLowCardinality, got String: While executing TTL.` on every attempt, so the rollup never happened and background TTL merges of such a table failed permanently. In builds with assertions the same insert aborted on the chassert in IColumn::assertTypeEquality instead. No non-default setting is needed to reach it, and removing LowCardinality from an otherwise identical table makes the merge succeed. AggregateFunctionFactory::get resolves every aggregate on convertLowCardinalityTypesToNested(argument_types), i.e. recursiveRemoveLowCardinality per argument, so an aggregate's result type has LowCardinality stripped at every depth rather than only outermost. TTLAggregationAlgorithm gives each column that is neither a GROUP BY key nor a SET target an implicit any() whose set part is an identity expression over that stripped type, and finalizeAggregates appends the result into result_columns, which is header.cloneEmptyColumns() and therefore still carries the declared type. The restore step already in that loop tested only result_column_type->lowCardinality(), the outermost wrapper, so a column with LowCardinality nested inside Tuple, Array or Map was appended unconverted: the destination element column is a ColumnLowCardinality and the source element is the full column. Generalise that test to "the declared type carries LowCardinality anywhere" and convert from the produced type with recursiveLowCardinalityTypeConversion, which already recurses through Nullable, Const, Array, Tuple and Map. This is a strict generalisation, so the top-level case keeps taking the same call. Both guards are load-bearing. The first leaves explicitly-SET parts untouched, since TTLDescription wraps their expressions in _CAST and they already produce the declared type. The second converts only when removing LowCardinality from the declared type yields exactly the produced type, so every other type difference is left as it is today and the change cannot turn a working merge into a TYPE_MISMATCH; it also keeps the conversion within the shapes both helpers agree on, so it cannot throw. Explicitly-SET columns, GROUP BY key columns and the path that copies rows whose TTL has not expired were each checked to be unaffected, before and after the change.
Internal second-model review: adjudication log (click to expand)An independent model reviewed this before publication (engine: codex): 0 findings. My own cold
Sibling carriers checked and left unchanged: I did not modify the code during review. Session id: cron:clickhouse-review-slot-8:20260914-014700 |
|
Workflow [PR], commit [0199ffe] Summary: ❌
AI ReviewSummaryThis PR generalizes the existing Final Verdict✅ No review findings. LLVM Coverage ReportMeasured on commit 0199ffe.
Changed lines: Changed C/C++ lines covered: 8/8 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 0199ffeEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
How this head was measured:
Session id: cron:our-pr-ci-monitor:20260914-133210 |
|
Fixing PR for the BuzzHouse (amd_debug) |
On the right-hand side of a comparison the parser reads SOME as the array-quantifier keyword. That lookahead (ParserExpressionImpl::tryParseOperand) requires exactly one expression before the closing parenthesis, so SOME(a, b -> 1) fails it, rewinds, and the tokens are re-read as an ordinary function call named SOME whose argument list folds a, b -> body into a single lambda. ASTFunction::formatImpl printed that name through backQuoteIfNeed, which force-quotes a curated list of keyword-valued identifiers in writeProbablyQuotedStringImpl. The list existed for exactly this problem and already carried the quantifier twin ALL, but not SOME, so the name was emitted bare. Re-parsing the emitted text, the bare SOME matched the keyword again, and the content was now a single expression because the formatter had parenthesised the lambda parameter list, so the quantifier path fired and rewrote the node to arrayExists. The trees no longer matched, and on a build with assertions the format-and-re-parse consistency check in executeQuery.cpp raised LOGICAL_ERROR. Two more spellings reach the same abort. The parser drops the ALL aggregate qualifier, so SOME(ALL 2) also collapses to one expression on the way back. And the quantifier has a second branch: a subquery argument, which is rewritten to IN rather than to arrayExists, so `SOME`((SELECT 1)) breaks too. Quoting the name fixes all three at once, because it acts before the parser chooses a branch. ANY is deliberately left out of the list. A function named ANY with a non-subquery argument round-trips unchanged, but the back-quoted subquery spelling `ANY`((SELECT 1)) does not, on master as much as here: the name is emitted bare and read back as the quantifier, so the node becomes IN. Adding any to this list would fix that at the cost of back-quoting the any aggregate function in every EXPLAIN SYNTAX and SHOW CREATE output, which is a different change with a different blast radius, so this commit keeps to the name CI produced. Only formatter output changes. The parser has always accepted both spellings, so metadata written by a new server is readable by an old one and vice versa, and no setting or serialization surface is involved. Found by BuzzHouse (`amd_debug`) on an unrelated pull request: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119879&sha=0199ffe61fe62ba19ccb3c42c9335eab0a34b431&name_0=PR&name_1=BuzzHouse%20%28amd_debug%29 Related: ClickHouse#119879 Co-Authored-By: Claude Opus 5 <[email protected]>
Related: #54669
Related: #87336
Related: #92971
Related: #108550
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix an exception (
ILLEGAL_COLUMN: Expected ColumnLowCardinality) that made everyTTL ... GROUP BY ... SETmerge fail for a table with a column whose type hasLowCardinalitynested insideTuple,ArrayorMap. In builds with assertions the same merge aborted on an assertion instead.Description
TTL <expr> GROUP BY <keys> SET <assignments>fails on every merge of a table holding a column whosetype carries
LowCardinalitybelow the top level (Tuple(a LowCardinality(String), b UInt32),Array(LowCardinality(String)),Map(LowCardinality(String), UInt32)) and that is neither aGROUP BYkey nor aSETtarget. No non-default setting is needed.On official
26.4.5.143,OPTIMIZE TABLE ... FINALon such a table returnsCode: 44. DB::Exception: Expected ColumnLowCardinality, got String: While executing TTL.on everyattempt, so the rollup never happens and background TTL merges of that table fail permanently. In
builds with assertions the same insert aborts on the
chassertinIColumn::assertTypeEquality. Anotherwise identical table without
LowCardinalitymerges fine. Found by the AST fuzzer,STID: 2508-3698:https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110098&sha=b478bb4e25a432b6ad4385d4b057d1c783cf560a&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29
Root cause:
AggregateFunctionFactory::getresolves aggregates on argument types withLowCardinalityremoved recursively (convertLowCardinalityTypesToNested), and the implicitanythat
TTLAggregationAlgorithmgives every uncovered column has an identity expression that neverrestores the wrappers. The restore step already in
finalizeAggregates(added by #92971 for #87336)tested only
result_column_type->lowCardinality(), the outermost wrapper alone.This generalises that step to "the declared type carries
LowCardinalityanywhere", reusingrecursiveLowCardinalityTypeConversion. It is a strict generalisation: the top-level case #92971fixed takes the same call, and
03774_ttl_group_by_lowcardinalitystays green. The two guards leaveexplicitly-
SETparts and every non-LowCardinalitytype difference exactly as today. Independentof #108550 and #119863.
Validation: the new test aborts on master, passes with the fix, 50/50 under randomised settings; the
local stateless
ttlsweep is otherwise unchanged.Workflow [PR]
Sync PR [sync-upstream/pr/119879]