Repository navigation
Reject a SETTINGS name that is not a setting at all for File, URL, S3 and the Log family - #120898
Conversation
… and the Log family `CREATE TABLE t (a UInt64) ENGINE = File(CSV) SETTINGS not_a_setting_at_all = 1` succeeded, stored the name in the table metadata, and nothing ever read it. `MergeTree`, `Memory` and `Set` refuse the same statement. The cost is a typo that never announces itself: `format_csv_delimiter` is a setting, `input_format_csv_delimiter` is not one anywhere, and a table declaring the latter was created without complaint and did not do what its definition appeared to say. `InterpreterSetQuery::applySettingsFromQuery` splits the clause, moving to the query context every name that is not a setting of this engine but is a query setting. What survives with the engine is therefore exactly "neither an engine setting of this engine nor a query setting". Around 35 engines reject that residue through `<X>Settings::loadFromQuery`, whose settings struct forbids custom settings. Eleven engine names do not, in two shapes: `File`, `URL` and the object-storage creators apply the residue to a copy of the query `Settings` (the one struct declared `DECLARE_SETTINGS_TRAITS_ALLOW_CUSTOM_SETTINGS`, so an unknown name becomes a custom field) and discard the copy a few lines later, while the `Log` family never reads any name but `disk`/`storage_policy`. Values were always validated; only names fell through. `checkStorageSettingNames` rejects a name that is neither an engine builtin, per the engine's registered `has_builtin_setting_fn`, nor `Settings::hasBuiltin`. That is the split loop's exact complement, so it cannot fire on a name the loop would have hoisted, and aliases, obsolete settings and format settings all stay accepted. It is called from the seven creators covering those eleven names rather than once in `StorageFactory::get`, because three engines accept names that are settings nowhere by design and a blanket check regresses them: `S3Queue`/`AzureQueue` strip `current_shard_num`/`total_shards_num`, `TimeSeries` skips validation for an unsupported schema version on `ATTACH` (asserted by `04613_timeseries_future_version.sh`), and `DeltaLakeLocal` loads `DataLakeStorageSettings` while registering `StorageObjectStorageSettings::hasBuiltin`, so its documented `SETTINGS disk = ...` would break. The `URL` call sits before `tryDispatchURLEngineByScheme` so a scheme-delegated definition is judged under `URL`'s own settings. Rejection is limited to a definition supplied now, so stored metadata keeps loading and an existing table still attaches after a downgrade. The four-term gate mirrors `registerStorageMergeTree.cpp`: `mode` alone cannot separate user input from a replay, because a `Replicated` database replays a full-definition `ATTACH` on every secondary under `LoadingStrictnessLevel::ATTACH`, a definition re-derived from Keeper arrives as a plain `CREATE` with no metadata transaction, and Shared Catalog secondaries re-execute the initiator's DDL. A secondary refusing what the initiator committed would retry its queue entry forever, so only the execution that judges the definition may refuse it. `ALTER ... MODIFY SETTING` needs no change: `IStorage::checkAlterIsPossible` already throws `NOT_IMPLEMENTED` for every engine here, and every engine that does accept it already rejects an unknown name. Contrary to the issue's premise, `MergeTreeSettingsImpl::loadFromQuery` does not gate its `UNKNOWN_SETTING` throw on `is_loading_from_existing_metadata` (`applyChanges` throws unconditionally), so this load tolerance is new rather than copied. One user-visible consequence beyond the intended rejection: `CREATE TABLE t AS other` copies the source table's stored `ASTStorage` into a fresh `CREATE` without passing the split loop, so it now fails when the source's stored definition carries a bogus name. Also corrects four comments that were untrue of names, and one claiming that the session's settings are ignored where the line below it reads the local context. Closes: ClickHouse#120705 Co-Authored-By: Claude Opus 5 <[email protected]>
An `ASTSetQuery` carries three independent payloads, and a storage `SETTINGS` clause is parsed by the same parser as a query one: `ParserSetQuery` routes `name = value` into `changes` and `name = DEFAULT` into `default_settings`, and `ASTSetQuery::formatImpl` writes the latter back out as `name = DEFAULT`. So `ENGINE = TinyLog SETTINGS disk = 'default', not_a_setting_at_all = DEFAULT` was accepted, stored in the table metadata and echoed by `SHOW CREATE TABLE` for the table's life, unread: the same defect, in a spelling the previous commit did not cover. `InterpreterSetQuery::applySettingsFromQuery` walks only `changes` too, so the name is not hoisted to the query context either, and it drops the settings node only when `changes` ends up empty. The predicate is unchanged and the message is unchanged; it is now applied to both payloads through one local lambda. A clause consisting only of resets is dropped before any engine sees it, so nothing is stored and there is nothing to refuse; `MergeTree` reads only `changes` as well, which leaves these engines stricter than it in that one spelling. Closing either would mean editing the split loop. `chassert(features.has_builtin_setting_fn != nullptr)` records why the pointer may be dereferenced without a null test: `StorageFactory::registerStorage` refuses to register an engine that advertises `supports_settings` without the function, and `StorageFactory::get` refuses a `SETTINGS` clause on an engine that does not advertise it, so reaching here with a settings node implies both. Tests. `05227` gains the two rejection arms above plus an acceptance control, `disk = 'default', max_threads = DEFAULT`, which is the only shape that reaches the new loop with a real name and therefore keeps the arms from passing by refusing every reset. It also gains `COSN`, `OSS`, `GCS`, `AzureBlobStorage` and `HDFS`: `registerStorageAzure` and `registerStorageHDFS` each carry their own call, and neither line was asserted before, whereas the S3-compatible names and the `Log` family share a creator with an arm already. `05228` gains `CREATE TABLE ... AS` over a table whose stored definition names a non-setting, which is the one path where a pre-existing table makes a new statement fail. `05229` drops `no-ordinary-database`, copied from the template it was modelled on: it creates its own `Replicated` database and its `ATTACH` names it explicitly, so the engine of the ambient database is irrelevant. Co-Authored-By: Claude Opus 5 <[email protected]>
Condense the four new comment blocks to the pre-existing properties a reader cannot derive locally, and drop the one narrating the URL call's placement.
Internal second-model review: adjudication log (click to expand)Pre-publication review over two rounds, each an independent-model pass (engine: codex) plus my own Round 1 (4 gate findings + 3 of my own)
Round 2 (1 gate finding + 3 of my own; delta re-review of the fix round)
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20260918-182100 |
Pre-PR validation gate (click to expand)
Existing-test sweep: the 50/50: 150/150 passed with randomized settings, 150/150 with Session id: cron:clickhouse-impl-slot-4:20260918-163801 |
|
Workflow [PR], commit [8175b68] Summary: ✅
AI ReviewSummaryThis PR adds a shared guard that rejects storage Missing context / blind spots
Final Verdict✅ No new inline findings. The previously open bot thread about LLVM Coverage ReportMeasured on commit 8175b68.
Changed lines: Changed C/C++ lines covered: 65/70 (92.86%) · Uncovered code |
The check rejected a name that `Settings::hasBuiltin` does not know, but the split loop in `InterpreterSetQuery::applySettingsFromQuery` keeps a name when `context_settings.has(name)` is false, and `Settings::has` is `hasBuiltin || hasCustom`. So a custom setting the session or profile holds is a query setting to the split loop and was an unknown name to the check. The reset payload is where that mismatch showed: `name = DEFAULT` is never moved to the query context, so after `SET custom_x = 1`, CREATE TABLE t (a UInt64) ENGINE = TinyLog SETTINGS disk = 'default', custom_x = DEFAULT was accepted on master and threw `UNKNOWN_SETTING` here. `CREATE ... AS SELECT` skips the move altogether, so `custom_x = 1` regressed the same way. The default server config registers the `SQL_` prefix, so this is reachable without extra configuration. Using `Settings::has` makes the predicate the split loop's exact complement, so it can only ever accept more than before. A custom name the context does not hold is still rejected: the split loop leaves it behind and no engine reads it, which is the case this check is for.
A `SETTINGS` node carries three payloads and the check walked two of them.
`ParserSetQuery::parseNameValuePairWithParameterOrDefault` routes a `param_`
prefixed entry into `query_parameters` with the prefix stripped, and
`ASTSetQuery::formatImpl` writes it back as `param_x = '1'`, so
CREATE TABLE t (a UInt64) ENGINE = TinyLog
SETTINGS disk = 'default', param_x = 1
was created and kept that clause in `SHOW CREATE` and in the stored metadata,
on every engine this check covers.
Only a standalone `SET` declares a query parameter
(`InterpreterSetQuery::execute`), so the name stored in a storage clause is read
by nothing: `SETTINGS disk = 'default', param_x = 1 AS SELECT {x:UInt8}` fails
with `Substitution 'x' is not set`. `isEmptySetQuery` in `executeQuery.cpp`
already treats the three payloads as one enumeration, for the same reason.
Alone in the clause the whole node is dropped before any engine sees it, so the
`AS SELECT` path, where the split does not run, is what reaches the check with
that payload alone.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes8 object files changed (+34.50 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units175 translation units recompiled, 1499 s compile time in total, 175 of them have a recent master baseline. |
…ight
checkStorageSettingNames accepted a `param_x` entry whenever the context held a
query setting of that name. For the changes and default_settings payloads that
predicate is right: InterpreterSetQuery::applySettingsFromQuery takes a
query-setting name out of the clause and applies it to the context, so the name
does something. It takes nothing out of query_parameters, which it leaves in the
clause on purpose so that the engine reports it, and no engine reads that
payload, so a name there cannot do anything whatever it is called.
The predicate therefore reopened, for one name, the hole this branch closes.
With custom_settings_prefixes containing `param_` and a profile defining a
custom setting `param_x`, measured before this commit:
CREATE TABLE d (a Int) ENGINE = MergeTree ORDER BY a
SETTINGS index_granularity = 4096, param_x = 1
-> accepted, stored as `..., param_x = '1'`, and ignored
That holds for every creator calling the helper, File and the other engines of
ClickHouse#120898 included, so the fix belongs in the helper rather than at the MergeTree
call site. A table whose stored definition already names one still loads: the
freshness gate is untouched, and three tables created that way on the previous
commit's binary re-ATTACH and load on this one's.
An integration test rather than a stateless one, because reaching the hole needs
`param_` registered as a custom-settings prefix, which is server configuration.
Its first assertion is that the custom setting is live, without which the
rejection it checks would hold on any server.
Raised by the automated review of ClickHouse#121394.
Co-Authored-By: Claude Opus 5 <[email protected]>
…-field-id Conflicts: master reworded the format-settings comments in `StorageFile.cpp`, `StorageURL.cpp` and `registerStorageObjectStorage.cpp` (ClickHouse#120898), where this PR replaced the blocks with `getFormatSettingsForTableDefinition` — kept the PR code and carried master's "validates the values, not the names" wording into that helper. `FormatFactory.{h,cpp}` and `SettingsChangesHistory.cpp`: kept both sides. Master is now 26.10, so the two new settings records move to the `26.10` block. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
CREATE TABLEnow rejects aSETTINGSname that is neither a setting of the table engine nor a query setting for theFile,URL,S3(withCOSN,OSS,GCS),AzureBlobStorage,HDFS,Log,TinyLogandStripeLogengines, withUNKNOWN_SETTING, asMergeTreealready did. Thename = DEFAULTandparam_name = valuespellings are rejected too, except where the whole clause is dropped before any engine sees it. Such a name used to be accepted, stored in the table metadata and never read, so a typo likeinput_format_csv_delimiterforformat_csv_delimitersilently did nothing. A table whose stored definition already names a non-setting still loads. Closes #120705.Description
CREATE TABLE t (a UInt64) ENGINE = File(CSV) SETTINGS not_a_setting_at_all = 1succeeded, andSHOW CREATE TABLEkept the name forever, unread.Root cause.
InterpreterSetQuery::applySettingsFromQuerymoves a name that is a query setting but not an engine setting into the query context, on the paths where it runs. Most engines reject what is left; eleven do not.File,URLand the object-storage creators apply the clause to a discarded copy of the querySettings; theLogfamily reads onlydisk/storage_policy.Change. One shared
checkStorageSettingNames, called first in those 7 creators, rejecting a name that is neither an engine builtin nor a query setting the context holds: the split loop's exact complement, so aliases, obsolete and format names stay accepted. All three payloads are walked:name = DEFAULTandparam_x = 1land indefault_settingsandquery_parameters, both persisted. Only a fresh definition is judged, so stored metadata still loads; the freshness gate mirrorsregisterStorageMergeTree.cpp, so noReplicatedsecondary refuses what its initiator committed. Not a blanket check inStorageFactory::get:TimeSeries,S3Queue/AzureQueueandDeltaLakeLocalaccept non-settings by design;param_xstays accepted elsewhere,MergeTreeincluded.Compatibility cost:
CREATE TABLE t AS old_tablecopies a storedASTStorageinto a freshCREATE, so it now fails ifold_tablenames a non-setting; restate it fromSHOW CREATE TABLEwithout the name. Retag toBackward Incompatible Changeif you prefer.Validation. Three new stateless tests cover the rejection on all eleven engine names with acceptance controls, stored-definition tolerance, and the replicated replay boundary. All three fail on master and pass here, and the affected
file|url|s3|log_familystateless suites show no regression.Workflow [PR]
Sync PR [sync-upstream/pr/120898]
Version info
26.10.1.149(included in26.10and later)