Repository navigation
Allow a SETTINGS clause without ENGINE in CREATE/ATTACH DATABASE - #118423
Conversation
A single table can carry an inline disk definition in its `SETTINGS`
clause without spelling out the engine, because the engine then comes
from `default_table_engine`:
CREATE TABLE t (x UInt32) ORDER BY x
SETTINGS disk = disk(type = local, path = '/var/lib/clickhouse-disks/t/');
`CREATE DATABASE` and `ATTACH DATABASE` could not do the same. `Atomic`
is the only default database engine there is - `default_database_engine`
is obsolete - and it does support `SETTINGS disk = ...`, but the clause
was only accepted when `ENGINE` was written out explicitly. Without it
the clause was parsed as *query* settings, so the query failed with
`Unknown setting 'disk'`, or, for an inline `disk(...)`, with the rather
opaque `Couldn't restore Field from dump: CustomType_('AST', 'disk(...)')`:
the `disk` function parses into a `FieldFromAST` custom `Field`, which
cannot survive the client-to-server settings round-trip. `ParserStorage`
said as much:
/// For DATABASE we currently don't allow SETTINGS without ENGINE
/// (it could be implemented in a similar fashion if necessary)
The documentation already advertised the syntax that did not work, in
`docs/reference/engines/database-engines/atomic.mdx`:
CREATE DATABASE test [ENGINE = Atomic] [SETTINGS disk=...];
The clause is now split into database-engine settings and query settings
the same way `CREATE TABLE` splits its own, so the two kinds can also be
mixed in one clause - `CREATE DATABASE db ENGINE = Atomic SETTINGS
lazy_load_tables = 1, max_threads = 4` used to fail with `Unknown setting
'max_threads'`. The split needs each database engine to name its
settings, so `DatabaseFactory::EngineFeatures` gained a
`has_builtin_setting_fn` that `registerDatabase` requires from every
engine declaring `supports_settings`, mirroring `StorageFactory`.
A `SETTINGS` clause holding nothing but query settings leaves an empty
storage node behind once they are hoisted onto the context.
`createDatabase` treats such a node as no storage definition at all, so
the short `ATTACH DATABASE db` syntax still reads the database
definition from its metadata file.
Closes: #118409
|
Workflow [PR], commit [df3cad1] Summary: ❌
AI ReviewSummaryThis PR allows Findings
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit df3cad1.
Changed lines: Changed C/C++ lines covered: 149/160 (93.12%) · Uncovered code |
…ange The test makes a `CREATE DATABASE` fail with `UNKNOWN_SETTING` and counts the error codes in the client output. With a `SETTINGS` clause without an `ENGINE` now belonging to the database engine, the unknown setting is reported from `DatabaseMetadataDiskSettings::loadFromQuery` while the query is being executed, instead of while the query settings are being applied, so the server also writes an `executeQuery` log line for it. The test enables server logs on the client through `CLICKHOUSE_CLIENT_OPT` (`--send_logs_level=warning`), that line is forwarded to the client, and its text names the error code a second time. The test is about the resynchronization of the connection after a server error, not about the server log, so the log is turned off for its client. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing commit See the job log for details. |
…abase # Conflicts: # src/Databases/DatabaseOrdinary.cpp
…E` SETTINGS clause
Address review: when one `SETTINGS` clause of `CREATE DATABASE` / `CREATE TABLE`
mixes engine settings with query settings, only the `changes` list was split, so
a reset such as `CREATE DATABASE db SETTINGS lazy_load_tables = 1, max_threads = DEFAULT`
kept `lazy_load_tables` but silently dropped the `max_threads` reset: `ParserSetQuery`
stores `name = DEFAULT` in `default_settings`, which the splitter never looked at, and
then pruned the whole clause once `changes` was empty.
Now a query-setting reset is checked against the settings constraints and applied
to the query context the same way `executeForCurrentContext` does, and the clause is
pruned only when `changes`, `default_settings` and `query_parameters` are all empty.
A parameterized value (`max_threads = {threads:UInt64}`) already worked, because
`ReplaceQueryParameterVisitor` substitutes the storage `SETTINGS` before
`applySettingsFromQuery` runs; the test now pins both cases.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Merged
|
|
|
||
| fs::path metadata_path; | ||
| if (!create.storage && create.attach) | ||
| if (!has_storage_definition && create.attach) |
There was a problem hiding this comment.
Once applySettingsFromQuery hoists every entry out of a no-ENGINE SETTINGS clause, has_storage_definition goes false and this branch falls back to short ATTACH DATABASE. Unlike the table-side short-attach path, it then overwrites create from metadata without first rejecting the rest of the user query, so ATTACH DATABASE db SETTINGS max_threads = 1 COMMENT 'x' (and the same with TABLE OVERRIDE ...) now succeeds but silently ignores that clause. This needs the same "no dropped clauses" guard as createTable before create = ast->as<ASTCreateQuery &>().
|
📊 Cloud Performance Report
This PR changes how CREATE DATABASE / ATTACH DATABASE dispatch a SETTINGS clause between engine settings and query settings (parser, InterpreterSetQuery, DatabaseFactory), plus docs and tests. None of that is on the query-execution hot path exercised by a TPC-H Q1 SELECT. The single flagged item, tpch_adapted_1_official Q1, shows a -20.6% shift the math already left as not_sure on an unstable, noisy baseline; it is run-to-run variance, not a PR effect. No actionable regressions or improvements attributable to this change. clickbench🟢 No significant changes tpch_adapted_1_officialFlagged queries (1 of 22)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
…et is stored This test asserts which SETTINGS names the File/URL/S3/Log-family check rejects. Three of its expected lines also pinned, through a full `SHOW CREATE TABLE` echo, *where* an accepted `name = DEFAULT` query-setting reset ends up in the stored clause. That placement is decided by the SETTINGS split, not by the check, and commit df3cad1 of ClickHouse#118423 moved it: a second loop over `ASTSetQuery::default_settings` in `InterpreterSetQuery::applySettingsFromQuery` now applies such a reset to the query context and erases it from the clause, and the clause is pruned only when `changes`, `default_settings` and `query_parameters` are all empty (it was pruned on `changes.empty()` alone). The placement already has a test that travels with the behaviour: `05099_create_database_with_inline_disk`, added by ClickHouse#118423, pins the hoisted clause plus a `system.query_log` read-back proving the reset reaches the context. 05227 pinned it a second time, in a file that does not travel with it, which is the defect here. So the three affected read-backs now assert what this test is about: that the `CREATE` was accepted, that the table exists, and that the engine setting survived the split. Every `CREATE` statement is unchanged, so each world's coverage of the check is preserved, and every `-- { serverError UNKNOWN_SETTING }` assertion is untouched. Full-echo accept coverage of the `default_settings` payload moves to the one route where the split does not run at all, `CREATE ... AS SELECT`, which returns through `if (create_query->select)` before either loop. The result is correct with and without df3cad1, verified against both a master build and a build with that commit reverted in the working tree. Three comments that made split-dependent claims are rewritten. Co-Authored-By: Claude Opus 5 <[email protected]>
CREATE DATABASEandATTACH DATABASEnow accept aSETTINGSclause without an explicitENGINE, so an inlinedisk(...)can be used the way a single table uses it:Before, only the fully spelled-out form worked. Omitting
ENGINE = Atomic— which the documentation already presented as optional — parsed the clause as query settings, so it failed withUnknown setting 'disk', or, for an inlinedisk(...), with the rather opaqueCouldn't restore Field from dump: CustomType_('AST', 'disk(...)'): thediskfunction parses into aFieldFromASTcustomField, which cannot survive the client-to-server settings round-trip. The parser said as much:/// For DATABASE we currently don't allow SETTINGS without ENGINE (it could be implemented in a similar fashion if necessary)The clause is now split into database-engine settings and query settings the same way
CREATE TABLEsplits its own, so the two kinds can also be mixed in one clause —CREATE DATABASE db ENGINE = Atomic SETTINGS lazy_load_tables = 1, max_threads = 4used to fail withUnknown setting 'max_threads'. The split needs each database engine to name its settings, soDatabaseFactory::EngineFeaturesgained ahas_builtin_setting_fnthatregisterDatabaserequires from every engine declaringsupports_settings, mirroringStorageFactory.Closes: #118409
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
CREATE DATABASEandATTACH DATABASEnow accept aSETTINGSclause without an explicitENGINEclause, defaulting to theAtomicengine, so a database can define its metadata disk inline the same way a single table does:CREATE DATABASE db SETTINGS disk = disk(type = local, path = '...'). A singleSETTINGSclause ofCREATE DATABASEcan now also mix database-engine settings with ordinary query settings.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/118423]
Version info
26.10.1.276-master(included in26.10and later)