Repository navigation
Conversation
A database SETTINGS clause is one ASTSetQuery with three payloads: `changes` (name = value), `default_settings` (name = DEFAULT) and `query_parameters` (param_name = value, prefix stripped). All six database engines that accept settings apply `changes` only, and InterpreterCreateQuery::createDatabase serialises the whole AST into the database .sql after the creator ran, so a name in either of the other two payloads was accepted and then persisted in system.databases.engine_full where no code ever reads it. DatabaseFactory::validate checks only whether a clause is allowed for the engine, never the names in it. Add checkDatabaseSettingNames and call it once from createDatabase, which is the only caller of DatabaseFactory::get and the only place where all three replay discriminators exist at once. `changes` is deliberately left to the engines: every one of the six already rejects an unknown name there, and DatabaseDataLakeSettings::loadFromQuery attaches a tailored "use the setting without `iceberg_` prefix" hint that a generic UNKNOWN_SETTING would replace. A param_name entry is rejected outright rather than looked up, mirroring the storage side: nothing hoists a name out of query_parameters and no database engine reads one, so such an entry did nothing even where a custom setting of that name existed. The freshness predicate is the database-side one, not isFreshTableDefinition. loadMetadata.cpp hard-codes /*create*/ true for a database, so setForceAttach is never called and the stored full `ATTACH DATABASE db ENGINE = ...` is replayed at plain ATTACH with attach_short_syntax == false, the same (mode, attach_short_syntax) pair a user's own full-definition ATTACH DATABASE carries. isFreshTableDefinition would therefore have rejected every settings-carrying database at server startup. DatabaseBackup.cpp already computes the correct database-side form, and it is reused here. RESTORE was the one replay path with no marker: RestorerFromBackup set only setInternal(true), and the backup stores a CREATE DATABASE, so the mode is CREATE. It now also sets setIsRestoreFromBackup(true), which the table path already used for this purpose and which is behaviour-neutral on the database path today, every other consumer of that member being table-only. Two alternatives were rejected: passing secondary = is_restore_from_backup would move the mode to SECONDARY_CREATE and flip DatabaseReplicated's is_create_query and its DROPPED_MARK handling for every restored Replicated database, and setRecoveryFromStoredMetadata is the broad flag that also disables StorageDistributed local-shard access checks. No is_ddl_replay term is added, because a Replicated database's DDL log carries the definitions of the tables inside it and never its own, so no CREATE DATABASE is ever replayed under a ZooKeeperMetadataTransaction. Related: ClickHouse#121202 Related: ClickHouse#121394
… engines
The sibling checkStorageSettingNames carries five exemption terms. Four have
a correctly translated or correctly absent database analogue, but
is_shared_catalog_replay had none, and the path is real from this tree alone:
the DatabaseMySQL constructor has an explicit
`SharedDatabaseCatalog::initialized() && !isInitialQuery(context_)` branch
that tolerates a connection failure exactly as it does for attach, reachable
only through DatabaseFactory::get and so only through createDatabase. A
CREATE DATABASE therefore is re-executed on a secondary as a non-initial
shared-catalog query, and MySQL is one of the six engines that accept
settings. On that path is_metadata_replay, attach_short_syntax and
is_restore_from_backup are all false with mode CREATE, so nothing exempted
it and a definition stored before this change could be refused on a
secondary, which retries its queue entry forever.
No test: SharedDatabaseCatalog.h is not in this tree, so the branch is
unreachable in an OSS build and a test would assert nothing.
The stateless test previously proved the rejection on Atomic and Ordinary,
which share one has_builtin_setting_fn, leaving four of the six engines
measured only by hand. Because the check runs before the creator, a
rejection needs no external service, so the remaining engines are asserted
directly: Replicated (both spellings, since the param_ loop is
engine-independent), MySQL, DataLakeCatalog, and MaterializedPostgreSQL
behind its experimental gate, which fires earlier than the check.
The Replicated path stays a literal. A {...} inside a Replicated zk path is
expanded as a macro rather than substituted as a query parameter, so the
per-run form fails with NO_ELEMENTS_IN_CONFIG once the path is reached. It is
never reached here, the settings check rejecting first, which is exactly why
the arm would have passed either way.
The fast test build configures -DENABLE_LIBRARIES=0, which defaults ENABLE_MYSQL, ENABLE_LIBPQXX and ENABLE_AVRO off, so configure_config.cmake leaves USE_MYSQL, USE_LIBPQXX and USE_AVRO unset and registerDatabases.cpp never registers MySQL, MaterializedPostgreSQL or DataLakeCatalog. With the engine absent from the registry the new check takes its own early exit for an engine it cannot resolve, and DatabaseFactory::get then throws UNKNOWN_DATABASE_ENGINE where those three arms assert UNKNOWN_SETTING. The file carried no tag line, so --fast-tests-only selected it. The merged sibling 05227_storage_settings_unknown_name.sql already carries the same block for the same reason on the S3 engine. The companion .sh test needs no tag: its only engines are Atomic, MergeTree and File backups, and registerBackupEnginesFileAndDisk registers File and Disk unconditionally.
On a short `ATTACH DATABASE db` the interpreter replaces the query with the definition parsed out of the stored metadata file, so the stored clause is the one that reaches the check, and then sets attach_short_syntax. On that path the metadata-replay flag is false because it is a user query rather than the startup load, the restore flag is false, the Shared Catalog term is false in an OSS build, and the mode is exactly ATTACH. So attach_short_syntax is the only term that exempts it, and nothing in the tree exercised a short detach and attach of a database whose stored clause names a non-setting. The other three terms already have live arms: a full-definition ATTACH is rejected, a stored definition still loads at startup, and a RESTORE still succeeds. The new arm re-asserts the stored name first, so a definition rewritten by the load above it cannot make it pass while asserting nothing.
Drop the restore-flag narration; state the ATTACH-mode, DEFAULT-parse and declaration contracts as bare invariants.
Internal second-model reviewBefore opening this I ran an independent cold review plus a second-model pass over the diff, in four rounds, and adjudicated every finding. Four were taken into the diff, three scope limits are noted below, and the last round's second-model pass returned none. ❌ Taken (fixed here)
💡 Verified rather than assumed
|
|
Workflow [PR], commit [e61e706] Summary: ✅
AI ReviewSummaryReviewed Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units38 translation units recompiled, 196 s compile time in total, 38 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.95 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
CI finish ledger - 148aa70Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The rest of the run is clean: 133 of 176 checks pass and 40 are skipped, with Session id: cron:our-pr-ci-monitor:20260923-063151 |
|
@groeneai is this going to be safe for upgrades if a setting gets deprecated? Don't change anything yet |
|
For the database-engine surface: yes, and by construction. Nothing already stored is judged, so an upgrade cannot leave a database unable to attach. No changes pushed. A stored definition is never checked. Only a definition stated now is. Every replay path is exempt, and each has its own arm in Deprecating a setting does not make its name unknown. The same convention is what protects the ordinary One window it does not cover, and it is your call: a |
…nown-database-setting-name Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - c667baeEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261013-213007 |
|
🕵️ @groeneai Thanks, the upgrade answer is clear. One thing:
|
…nown-database-setting-name Resolved `src/Databases/DatabaseFactory.cpp` by keeping both additions: master's `DatabaseFactory::Arguments::isLoadingFromExistingMetadata` and this branch's `checkDatabaseSettingNames`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a setting For a database, the initiator of `CREATE DATABASE ... ON CLUSTER` only enqueues the query, so the clause is judged on the host that runs the queue entry. No arm covered that leg, so exempting the DDL worker (which would reopen ClickHouse#121202 for every ON CLUSTER create) left the suite green. Both spellings are asserted; `FORMAT Null` keeps the per-host status row out of the output under the default `throw` mode. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Added in 44fb1df: two I'll do the initiator-side check for tables and databases in a separate PR and link it here. The |
…SE on the initiator A plain `ON CLUSTER` leg runs with no Keeper metadata transaction, so it judged the `SETTINGS` names of the enqueued `CREATE` as a fresh definition. A host then refused an entry that an older initiator, which judged nothing, had enqueued: the object ended up on some hosts only. The initiator now judges the names before it enqueues anything, and the hosts skip the check: a database at every entry format (its engine is explicit or `Atomic`), a table only for entries stored in format 4 or later, whose `CREATE` the initiator normalized (format 3 is stored as 2); with the legacy formats the hosts keep judging tables. The engines that judge names carry `StorageFeatures::checks_setting_names`, so `StorageFactory::get` and the initiator read one flag instead of seven creator calls. Requested in ClickHouse#121661 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The initiator-side check for tables and databases is in #129609. |
|
#129609 was closed as too large, so I'm not pursuing the initiator-side check. |
…nown-database-setting-name # Conflicts: # tests/integration/test_replicated_database/test.py
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
CREATE DATABASEnow rejects an engineSETTINGSname that is neither a setting of the database engine nor a query setting when it is spelledname = DEFAULT, and rejectsparam_name = valuein that clause, because no database engine reads one. A database whose stored definition already names one still loads and still restores from a backup; restating that definition now fails until the name is dropped.Description
The database half of #121202, per the request in #121394 (comment). The ordinary
name = valuespelling was refused; the other two were accepted, and persisted:Root cause. The clause is one
ASTSetQuerywith three payloads:changes,default_settings(name = DEFAULT) andquery_parameters(param_name = value). Engines applychangesonly, yet the whole node is stored.Change. One
checkDatabaseSettingNamescall inInterpreterCreateQuery::createDatabase, the only caller ofDatabaseFactory::get, judgingname = DEFAULTagainst the engine's builtins and the query settings, and refusing everyparam_nameentry.changesstays with the engines, which already reject an unknown name.Compatibility. Only a definition stated now is judged. Startup replays the stored
ATTACH DATABASE db ENGINE = ...at plainATTACH, the same mode a user's own full-definitionATTACH DATABASEcarries, so the metadata-replay flag is the discriminator; a backup stores aCREATE DATABASE, whichRESTOREmarks withis_restore_from_backup, as on the table path; a Shared Catalog secondary is exempt as there. AReplicateddatabase's DDL log carries its tables' definitions, never its own, so the storage-sideis_ddl_replayterm has no analogue here (correcting my #121394 sweep).ALTER DATABASE ... MODIFY SETTINGrewrites the stored definition through a different site, not this one.Validation. A stateless
.sqlover both spellings, all six settings-taking engines, anON CLUSTERcreate, a setting of another engine, and the reset forms that must still pass; a.shover a checked full-definitionATTACHand the three replay paths; a two-replicaReplicatedcase that loads on both with its DDL queue draining. Each file fails without the fix.Closes: #125618
Workflow [PR]
Sync PR [sync-upstream/pr/121661]