Repository navigation
Do not copy a source table's column TTL into a table whose engine does not support TTL - #121335
Conversation
…s not support TTL
Merge, Buffer, Distributed and Remote/RemoteSecure support schema inference but not
TTL. For a column-less definition the interpreter leaves properties.columns empty, so
StorageFactory::get evaluates its engine-feature guard
storage_def->ttl_table || !columns.getColumnTTLs().empty()
against an empty ColumnsDescription and the TTL check is vacuous. The creator or the
constructor then resolves the real structure by copying a whole ColumnsDescription out
of another table (res.add(column, prev_column_name) in StorageMerge, the destination's
metadata in StorageBuffer, getStructureOfRemoteTable for the other two), so the live
metadata now holds the source's per-column ttl.
CREATE alone does not persist it, because getCreateQueryFromStorage emits only name,
type and default. The TTL reaches disk on the next permitted ALTER (ADD/MODIFY/DROP/
COMMENT COLUMN, COMMENT TABLE): applyMetadataChangesToCreateQuery regenerates the
column list with formatColumns, which does emit the per-column TTL, and
validateCreateQuery never consults StorageFactory or StorageFeatures. On the next load
createTableFromAST calls StorageFactory::get with a now non-empty ColumnsDescription,
the same guard fires, and the table can no longer be loaded:
Code: 36. DB::Exception: Engine Merge doesn't support TTL clause.
With the default async_load_databases = 1 every query on that table rethrows; with
async_load_databases = 0 the synchronous loader propagates the exception and the
server refuses to start, which is how this was found.
Strip the column TTL at the four points where a foreign ColumnsDescription enters one
of these engines. ColumnsDescription::resetColumnTTLs() already exists, and its only
previous call site is InterpreterCreateQuery's CREATE TABLE b AS a path for a
non-MergeTree engine, so this makes the inference path agree with the AS <table> path
that was already correct. These engines can never legitimately hold a column TTL (the
explicit spelling is rejected by the very guard that fires on load) and never evaluate
one, since they store no data of their own.
The static getColumnsDescriptionFromSourceTables overload used by TableFunctionMerge
and the shared getStructureOfRemoteTable are deliberately left alone, so merge(),
remote() and cluster() keep their current structure. Only ttl is cleared: default_desc
in particular has to survive, because StorageMerge uses it for addMissingDefaults, for
supportsPrewhere's per-column default-kind comparison and for ALIAS resolution on the
read path.
This prevents the state from being written; it does not repair a definition that is
already on disk.
Failure this fixes, Stress test (amd_tsan):
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121282&sha=ce277eefe2b909c275519efcb8f11e072344a981&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29
Co-Authored-By: Claude Opus 5 <[email protected]>
The copied phrasing claimed only MergeTree supports TTL, but EmbeddedRocksDB registers supports_ttl and StorageAlias delegates supportsTTL. State the property of the engine at hand instead. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review before this PR was opened: one cold pass of my own over the resulting code,
Severity: ❌ blocker / Also checked in my own pass, each of which could have been a finding: of the 15 engines registered Session id: cron:clickhouse-review-slot-10:20260921-110400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260921-092600 |
|
Workflow [PR], commit [e12cde4] Summary: ❌
AI ReviewSummaryThis PR strips inherited column Findings❌ Blockers
Tests
Final VerdictStatus:
LLVM Coverage ReportMeasured on commit e12cde4.
Changed lines: Changed C/C++ lines covered: 26/26 (100.00%) · Uncovered code |
|
@groeneai check for other table definitions not supported by these engines. |
Where exactly does it happen (with the callstack)? Should we handle it there? |
|
@PedroTadim Checked every other per-column property a column-less definition can inherit, on all four engines (
TTL is the only one that can make such a table unloadable, and that is structural rather than lucky. The check did find a bug in my patch.
One adjacent thing I measured and did not touch: on master, a codec the inferred common type does not accept is already rejected at |
The four sites that take a `ColumnsDescription` from another table cleared the inherited column TTL with `ColumnsDescription::resetColumnTTLs()`, which empties the container and `add()`s every column back. `add()` re-runs the per-column checks, so a column that the source table stores happily is checked again in a context the inference has changed. `StorageMerge` widens a column whose source tables disagree on its type to their common type and keeps the codec those tables declared, so re-checking rejects a codec the wider type does not accept: Code: 44. Column vec has a Quantized codec, which is only supported for Array(Float32), Array(Float64) or Array(BFloat16) columns, but its type is Variant(Array(Float32), String). (ILLEGAL_COLUMN) `Fast test` caught it on 02354_vector_search_quantize_codec_merge_variant, and it is not specific to `Merge`: the same structure reaches `Buffer` through its destination table and `Distributed`/`Remote` through a local shard, where `getStructureOfRemoteTable` returns the local table's own description. All three refused to be created over such a table as well. `clearColumnTTLs()` clears the TTLs in place instead, so nothing else about a column is looked at. `resetColumnTTLs()` keeps its one remaining caller, `InterpreterCreateQuery` for `CREATE TABLE ... AS <table>`, which serializes an explicit column list: there the check has to run, or an unloadable definition is written to disk, which is what this PR is about. It does not clear through `ColumnsDescription::modify` either, because that rebuilds the column's subcolumns, which `add` does not register for an `ALIAS` column: a `Buffer` inferred from a table whose alias carries a TTL then answered `SELECT al.size0` with `NO_SUCH_COLUMN_IN_TABLE`. 02184 pins all three halves. Failure this fixes, Stress test (amd_tsan): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121282&sha=ce277eefe2b909c275519efcb8f11e072344a981&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29 Co-Authored-By: Claude Opus 5 <[email protected]>
|
Pushed |
|
@tavplubix Four places, one per engine, each inside that engine's own
For the last two the TTL only rides in from a local shard: Callstacks, taken on this branch by making each site throw (a
|
| return ret; | ||
| } | ||
|
|
||
| void ColumnsDescription::clearColumnTTLs() |
There was a problem hiding this comment.
This only fixes future schema inference. Once an earlier ALTER has already persisted the inherited column TTL, database loading parses that column list back from metadata in DatabaseOnDisk.cpp and StorageFactory::get rejects it on !columns.getColumnTTLs().empty() before any of these new clearColumnTTLs() call sites run. That means upgrading still leaves already-poisoned Merge/Buffer/Distributed/Remote tables unloadable, and with async_load_databases = 0 the server still refuses to start for the installations that already hit the bug. Please add a load-time repair path for existing metadata, or some explicit migration, rather than only preventing future writes.
There was a problem hiding this comment.
Confirmed, and the residue is worse than that. Measured here on a single data directory across two server generations (pre-fix master writes the table, this head loads it):
async_load_databases = 1(the default): the server boots, but every statement touching the table rethrows the load failure asCode: 722, includingALTER ... MODIFY COLUMN c REMOVE TTL,DETACH TABLE ... PERMANENTLY,DROP TABLE ... SYNCandDROP DATABASE.SHOW TABLES FROM <db>and a globalSELECT count() FROM system.tablesthrow as well.async_load_databases = 0: the server does not start, andflags/force_restore_datadoes not change that, because this guard is not gated on the loading level at all.- The only escape I found is stopping the server and deleting the
TTLfrom every affected.sqlby hand, after which it boots and the tables work.
A repair would be one gate rather than a migration path. Startup loads tables at LoadingStrictnessLevel::FORCE_ATTACH (loadMetadata.cpp:312), the guards next to this one are already gated on the level (StorageFactory.cpp:65 returns early for a definition that is not fresh, registerStorageMergeTree.cpp:1182 gates its own TTL check to <= CREATE), and #113042 put stored TTLs on exactly that footing (TTLDescription.cpp:1018: "Loading already stored metadata is the one place that has to accept it, because a rejection there fails the whole load rather than the one table"). check_feature("TTL clause", ...) at StorageFactory.cpp:236 is the one that is ungated.
I am not adding it in this PR. It would serve a population this PR closes (in 90 days of CI this rejection has hit one of these four engines exactly once, the Stress run this PR came from) at the price of the only detector for the next carrier: for a column-less definition the CREATE-time guard is vacuous, so the failure at reload is the only thing that surfaces the defect. And once the persist is prevented, no SQL path can produce the residue, so the repair's regression test has to fabricate metadata on disk, which belongs in an integration test rather than in the stateless test here.
If a maintainer wants the leniency anyway, I will open it separately with that integration test.
…-ttl-for-ttl-less-engines
CI finish ledger - 5571097Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260922-000113 |
CI finish ledger - e10c7f7Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260922-063421 |
|
@tavplubix this PR looks good to me. For the column description improvement, we can leave it for another PR? |
|
@PedroTadim, I don't like the fact that we need to fix the same bug in 4 different places. It indicates that something is wrong. But the code is already messed up so much that we can merge whatever AI generates, I don't care. You have assigned yourself to this PR, so it's your responsibility now. |
I kind of agree, we could make this a more general solution (maybe with subclassing depending on the engine), but I hope we won't be adding more engines like these anytime soon. The PR is still small. |
|
On the four places, one measured point, then the shape is yours to pick. There is no shared frame today: The four are also the complete set, by a property that is cheap to re-check: they are the engines that copy another table's A single site is feasible: one check right after |
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger - e12cde4Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260923-140413 |
| for (auto it = columns.begin(); it != columns.end(); ++it) | ||
| if (it->ttl) | ||
| columns.modify(it, [](ColumnDescription & column) { column.ttl.reset(); }); | ||
| invalidateGetCache(); |
There was a problem hiding this comment.
@groeneai why do you have to call invalidateGetCache() here?
There was a problem hiding this comment.
clearColumnTTLs deliberately does not go through ColumnsDescription::modify (the comment above the loop says why: modify rebuilds the column's subcolumns, and add registers none for an ALIAS column). But modify is also what normally discharges the cache invalidation: it calls removeSubcolumns and then addSubcolumns (ColumnsDescription.h:215-219), and addSubcolumns ends in invalidateGetCache (ColumnsDescription.cpp:1149). Bypassing modify means doing that part by hand. The contract is stated twice, at ColumnsDescription.h:312-313 and ColumnsDescription.cpp:720-721: "the cache is invalidated by every method that touches columns or subcolumns".
To be straight about how load-bearing it is: this is conformance, not a fix for anything observable. get(const GetColumnsOptions &) caches a NamesAndTypesList, so names and types only, and ttl is neither in that list nor one of the container's keys (sequenced<> plus ordered_unique on name, ColumnsDescription.h:275-279). An entry that survived this mutation would still be correct, so no query result can differ with the call removed. The cost of keeping it is one get_cache.clear() on a schema inference path.
I kept it so this is not the single mutator in the class that skips the invalidation. If you prefer the smaller diff, say so and I will drop it.
3a33c47
One conflict, in `registerStorageRemote`: this branch deletes the block whose logic moved into `parseAndValidateRemoteEngineTarget`, master keeps it. Took this branch's side by editing the marked region only, so master's auto-merged hunks in the same file stay. Master changed that block once since the previous merge. ClickHouse#121335 clears the column TTLs of a structure inferred from another table (`columns.clearColumnTTLs()`): `Remote` stores no data, and a copied TTL makes the table unloadable once an `ALTER` persists it. The block now exists only on master's side, so git reported nothing about that line. Ported to where this branch adopts the inferred columns, the only place they become the storage's structure; the preflight discards them and needs no change. Diffing master's block at the old and new merge bases shows that call as its only change. The `ErrorCodes` list conflicted too: kept master's new `ILLEGAL_COLUMN`, and `ACCESS_DENIED`, which has no use left in the file, stays removed. ClickHouse#117791's new `is_fresh_definition` constructor argument merged cleanly into this branch's `registerStorageRemote` call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`StorageFactory::get` refused a column `TTL` on an engine that does not support one wherever the definition came from. A definition written without a column list takes the source table's columns whole, and a server that still copied the source column's `TTL` wrote it back out on the next `ALTER`, so such definitions are on disk now. Reading one back fails the load of everything stored beside it rather than that one table, and with `async_load_databases = 0` the server does not start, leaving hand-editing the metadata file as the only way out. The column-`TTL` arm of the check is now skipped for a definition that is replayed rather than stated - the carve-out `checkStorageSettingNames` already makes, extracted into `isReplayedTableDefinition` and shared by both. `Merge`, `Buffer`, `Distributed` and `Remote` hold the `TTL` without acting on it, so the definition loads and the `TTL` is ignored. A table `TTL` is never inherited, so it stays refused wherever it appears, and a `CREATE` or a full-definition `ATTACH` is still checked as before. Closes: ClickHouse#122031 Related: ClickHouse#121335
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A table created without a column list over a source that carries a per-column
TTLno longer inherits thatTTLwhen its own engine does not support one (Merge,Buffer,Distributed,Remote). Previously a laterALTERpersisted the inheritedTTL, after which the table could no longer be loaded, and withasync_load_databases = 0the server refused to start.Description
Merge,Buffer,DistributedandRemote/RemoteSecuresupport schema inference but notTTL. For a column-less definitionStorageFactory::getevaluates its TTL guard (storage_def->ttl_table || !columns.getColumnTTLs().empty()) against an emptyColumnsDescription, so the guard is vacuous. The creator then copies a wholeColumnsDescriptionout of another table, importing its per-columnttl.CREATEstill writes a clean.sql, but the next permittedALTERregenerates the column list withformatColumns, which does emit the per-columnTTL, andvalidateCreateQuerynever consultsStorageFeatures. On the next load the same guard fires:Code: 36 ... Engine Merge doesn't support TTL clause. By default every query on that table then rethrows; withasync_load_databases = 0the server will not start.The fix drops the column
TTLat the four points where a foreignColumnsDescriptionenters one of these engines, with a newColumnsDescription::clearColumnTTLs()that clears the TTLs in place. The existingresetColumnTTLs()rebuilds the description, so it re-validates every column: that rejected a codec that only fits a source column's own type onceMergehad widened it, and it registers subcolumns anALIAScolumn must not have. It matchesCREATE TABLE b AS a, which drops the columnTTLfor a non-MergeTree engine (InterpreterCreateQuery.cpp:1031-1035) and keepsresetColumnTTLs(), since it serializes an explicit column list and must validate it.DESCRIBEofmerge(),remote()andcluster()is unchanged, no column set or type changes, and an explicit columnTTLis still rejected.Validated per engine:
ATTACHfails on master and succeeds with the fix, a fresh server refuses to start before and boots after, and removing any one of the fourclearColumnTTLs()calls reddens exactly one engine.It prevents the state; it does not repair a definition already on disk.
Provenance (no matching open issue):
Stress test (amd_tsan)on #121282, https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121282&sha=ce277eefe2b909c275519efcb8f11e072344a981&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29Workflow [PR]
Sync PR [sync-upstream/pr/121335]
Version info
26.10.1.600-master(included in26.10and later)