Repository navigation
Conversation
…ments A table created as `AS timeSeriesSelector(...)`, `AS prometheusQuery(...)` or `AS prometheusQueryRange(...)` stores the call as its definition. Metadata loading replays that definition through `DatabaseOnDisk::createTableFromAST`, which runs `parseArguments()` before `ITableFunction::execute`. Both storages resolved the source table at the end of `getConfiguration()`, which their table function calls from `parseArguments()`, so a source table that had since been dropped or renamed threw `UNKNOWN_TABLE` from the load job. With `async_load_databases = 0` that takes the whole server down; at the default the table, its database's row in `system.tables`, and `DROP TABLE` on it all raise `Code: 722` for good, so the only repair is editing the metadata file by hand. `ITableFunction.h` documents the seam that should have absorbed this: the structure is written to the metadata file "to avoid failures on server startup", and `ITableFunction::execute` hands back a lazy `StorageTableFunctionProxy` when `cached_columns` is non-empty and `hasStaticStructure()` is false, which neither of these table functions overrides. The eager lookup one call earlier was the only thing defeating it. Split `getConfiguration()` into `parseArgumentsOnly()`, which reads only what the arguments determine, and `resolveConfiguration()`, which does the catalog work, and call the second from `getActualTableStructure()` and `executeImpl()`. Replay now resolves nothing, and resolution still happens once per materialization. Both `Configuration` structs, both storage constructors and both `readImpl()` are untouched, so the post-resolve validations still run on a fully resolved configuration. Qualify the source name in the creating context and write `database.table` back into the argument, so a definition naming a dropped database attaches instead of throwing `UNKNOWN_DATABASE` during the load. The qualification fills in the database name only and deliberately does not look the table up, because the loader would wait for that table's startup job. The write-back matters because `TablesLoader` replays under a copy of the global context, whose current database is `default`, not the creating session's: without it an unqualified name binds to the wrong database at every restart. The node written is a compound `ASTIdentifier`, the node the parser itself produces for `database.table`; an `ASTTableIdentifier` there is resolved as an expression by the analyzer and rejected, and its `StorageID` constructor would also copy the UUID and pin the definition to it. Definitions already on disk keep their unqualified text and are not rescued by the write-back; they attach and report the missing source when read, which is the point.
Replays stored `AS timeSeriesSelector(...)` / `AS prometheusQuery(...)` definitions with `DETACH TABLE` + `ATTACH TABLE`, which is the same `parseArguments()` path metadata loading takes, and asserts that the objects a definition names do not have to exist for it to attach: source table dropped, source table renamed, tags target dropped, source database dropped, and a full definition naming a table that never existed. Reading such a table must then report the missing object rather than hide it, and a control arm keeps a definition whose source is intact reading its row. Two arms guard the other direction, so the deferral cannot silently grow: a `CREATE` whose structure is inferred from the function must still reject a missing source, while the explicit-column-list form, which never infers the structure, succeeds and reports the source on first read. A last arm keeps the time bounds converted, which is what re-arms the constructor's instant-selector and inverted-range checks. Three arms cover what the other paths only reach at runtime. One replays a definition while a different database is current, with a same-named decoy in it, so the stored name has to carry the database it was created in or the read returns the decoy's rows instead of an error. One persists and replays `prometheusQueryRange()` as well, whose `over_range` branch is converted separately, with a control that counts evaluation timestamps so a wrong step changes it. The last creates a definition naming the table being created, which an explicit column list makes possible, and asserts it attaches and reports `UNEXPECTED_TABLE_ENGINE` when read. A further arm replays a whole database rather than single tables. `ATTACH DATABASE` runs the `TablesLoader` that `InterpreterCreateQuery` shares with server startup, so it is the one shape a stateless test can use to replay definitions the way a restart does: the replay context is a copy of the global context, whose current database is not the session's, and every table's load job is wired to that table's own startup job. The arm puts a bound, a dangling and a self-referential definition into one auxiliary database, plus one holding a PromQL query the grammar rejects, so a single `ATTACH DATABASE` covers all four. The bound ones must return the source's row count, which is only possible if the stored name carries the database it was created in, and the rest must report their own failure on the first read instead of at load time. Each count is labelled, because two bare counts are indistinguishable in a diff and the two table functions carry separate copies of the qualification. What that arm still cannot reach is the load job's self-wait, and not by accident: a binary that resolves at parse time also skips the name write-back, so its loader resolves in the global database and never waits on the half-loaded table. Reaching it needs a definition written by one binary and replayed by another. The test drops every table and database it creates. By the end nine of its definitions name a source that is gone, and an unmaterializable stored definition is not something the rest of the suite should inherit. The drops deliberately omit `SYNC`: a proxy whose materialization always throws still holds its table function, and a synchronous drop waits for that. Inserts go through `INSERT ... SELECT`: with an inline `VALUES` payload the client keeps reading stdin for further rows, and stdin under the test runner is an inherited pipe that never ends.
Internal second-model review: adjudication log (click to expand)Pre-publication review of this diff: three rounds, each an independent pass of my own plus a ❌ A self-referential definition could newly have made the server unstartable. With an explicit
💡 Noted, not fixed here (also in the description): a definition already on disk whose source is 💡 The description said this change defers "source and PromQL query alike"; I narrowed that before 💡 The test's cleanup comment attributes the omitted Session id: cron:clickhouse-review-slot-8:20260912-184000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20260912-170700 |
|
Workflow [PR], commit [3d51331] Summary: ✅
AI ReviewSummaryThe PR defers source resolution for Missing context / blind spots
Final VerdictStatus: ✅ Approve |
|
cc @vitlibar @nikitamikhaylov, could you review this? |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units12 translation units recompiled, 42 s compile time in total, 12 of them have a recent master baseline. |
`parseArgumentsOnly()` fills in the database of the source table and writes the resolved
`database.table` back into the arguments, so a stored definition replays against the
database it was created in. An empty table name cannot be written back: the
single-argument form builds a compound `ASTIdentifier`, whose constructor asserts
`!part.empty()`, so `prometheusQuery('', 'up', 1000)`, `prometheusQueryRange('', ...)` and
`timeSeriesSelector('', ...)` aborted a debug server with `Logical error: '!part.empty()'`.
`AST fuzzer (amd_debug, targeted)` found it on this branch.
Nor is there anything to write back: `StorageID::assertNotEmpty()` rejects a database name
without a table name, so the qualified pair is invalid whichever node carries it. Leaving
such arguments as parsed restores what these functions did before this branch, and matches
what the two-argument form already does: resolution reports `Code: 60`, `UNKNOWN_TABLE`.
Measured on both `enable_analyzer` values.
Arm (l2) covers the three functions. Each of them takes an unfixed debug server down at
the first query of the arm.
|
Fixed in cc477d7: a name that cannot name a table is left as parsed, so resolution reports One thing the deferral admits, for the record: with an explicit column list, a definition naming a temporary table as its source is now created instead of rejected, and after the session its stored name resolves like any other unqualified reference. |
…-selector-defer-table-resolution # Conflicts: # src/Storages/StoragePrometheusQuery.cpp # src/Storages/StorageTimeSeriesSelector.cpp # src/TableFunctions/TableFunctionTimeSeriesSelector.cpp
Master renamed the outer column of new TimeSeries tables from `time_series` to `samples`, so the test's inserts failed with `No such column time_series` and every arm built on them fell through. The reference is unchanged.
Comments only, no code change. They now state only what the code below them cannot show: why the write-back uses a compound identifier, that a stored definition is replayed against the loader's current database, and why an empty or temporary name is left as written. The narration of the split itself moved out, since the commit that introduced it already explains it. The temporary-table comment also said such a table cannot appear in a stored definition, which is not what the code guarantees: its name can be stored as written, only its resolved id cannot, because that names an internal database.
|
Dear @vitlibar, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…-selector-defer-table-resolution # Conflicts: # src/Storages/StorageTimeSeriesSelector.cpp # src/TableFunctions/TableFunctionTimeSeriesSelector.cpp
…n test Master made the `return_columns` argument of timeSeriesSelector() mandatory and no longer allows external target tables for new TimeSeries tables (version 10 and later). `timestamp_and_value` keeps the columns and rows the test read before, so the reference is unchanged, and the arm that drops the tags target pins version 9, the last version with external target tables. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`parseArgumentsOnly()` built the `PrometheusQueryTree` from the selector, so a selector that cannot be parsed now failed before the lookup of the TimeSeries table. Master checks the table first. In a build without ANTLR4 every PromQL parse throws `SUPPORT_IS_DISABLED`, so the Fast test of `05054_timeseries_under_distributed` got 344 instead of the expected `UNEXPECTED_TABLE_ENGINE` for a Distributed table. Keep the selector as a string and parse it in `resolveConfiguration()`, after the lookup, the engine check and the version check, which is where master parses it. `prometheusQuery()` already keeps its query as a string until then. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - acf79f2Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261029-160007 |
…-selector-defer-table-resolution # Conflicts: # src/Storages/StoragePrometheusQuery.cpp # src/Storages/StorageTimeSeriesSelector.cpp
PromQL Compliance ReportBaseline: S3 master
Extended support (upstream engine tests): native-histogram exclusions: 149; excluded assertions: 248; upstream Note: Prometheus compliance score is unchanged vs baseline. |
Related: #116629
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A table created as
AS timeSeriesSelector(...),AS prometheusQuery(...)orAS prometheusQueryRange(...)no longer stops the server from starting once its sourceTimeSeriestable is dropped or renamed. These table functions now look the source up when such a table is read, not while metadata loading replays its definition, so the table attaches and reports the missing source on read.Description
CREATE TABLE sel AS timeSeriesSelector(ts, 'up', 0, 9999999999, 'samples'); DROP TABLE ts;and a restart is enough: withasync_load_databases = 0the server never starts again; at the default it comes up, but that table andDROP TABLEon it raiseCode: 722for good. An unqualified source name in a non-default database does the same with nothing dropped.This is the requested investigation: the eager lookup below is what #116629 was reverted over, when its test left such definitions behind for a stress restart to replay. The lookup predates that PR and is on 26.3-26.10.
Both storages resolve the source at the end of
getConfiguration(), which their table function calls fromparseArguments(), so the lookup runs beforeexecute()can hand back the lazyStorageTableFunctionProxythat carries the structureITableFunction.hcaches in metadata "to avoid failures on server startup". SogetConfiguration()splits intoparseArgumentsOnly()(no catalog) andresolveConfiguration(), called fromgetActualTableStructure()andexecuteImpl(), asloop()andmergeTreeIndex()already do. BothConfigurationstructs, both constructors and bothreadImpl()are untouched. The source name is canonicalized todatabase.tablein the stored argument.One deliberate consequence: an inferred-structure
CREATEstill requires the source, while an explicit column list defers it, andprometheusQuery()'s PromQL text, to the first read.canBeUsedToCreateTable() { return false; }would be cheaper but only blocks new definitions.No access-rights code is touched. The
timeSeriesSamples()family resolves inparseArguments()too; #119786 refuses new tables over it and this PR does not touch it. One residual stays: a definition already on disk whose source is unqualified still binds against the loader's current database, because replay shares one loader context across databases.Base vs fixed on the same data directory
Validated by this A/B, a mutation ladder per arm, and 50x50 randomized runs of the new test.
The unqualified-name case, with a decoy
default.tsof a different engine present, on the fixedbinary:
SHOW CREATEreadsAS timeSeriesSelector(mydb.ts, 'up', 0, 9999999999, 'samples')and after a restartthe read binds to
mydb.ts, not to the decoy. Dropping the canonicalization makes it bind to the decoy.Workflow [PR]
Sync PR [sync-upstream/pr/119662]