Skip to content

Allow a SETTINGS clause without ENGINE in CREATE/ATTACH DATABASE - #118423

Merged
alexey-milovidov merged 5 commits into
masterfrom
inline-disk-for-database
Sep 20, 2026
Merged

alexey-milovidov merged 5 commits into
masterfrom
inline-disk-for-database

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

CREATE DATABASE and ATTACH DATABASE now accept a SETTINGS clause without an explicit ENGINE, so an inline disk(...) can be used the way a single table uses it:

CREATE DATABASE db SETTINGS disk = disk(type = local, path = '/var/lib/clickhouse-disks/db/');

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 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. 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 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.

Closes: #118409

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

CREATE DATABASE and ATTACH DATABASE now accept a SETTINGS clause without an explicit ENGINE clause, defaulting to the Atomic engine, 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 single SETTINGS clause of CREATE DATABASE can now also mix database-engine settings with ordinary query settings.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Workflow [PR]
Sync PR [sync-upstream/pr/118423]

Version info

  • Merged into: 26.10.1.276-master (included in 26.10 and later)

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
@alexey-milovidov alexey-milovidov self-assigned this Sep 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [df3cad1]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

This PR allows CREATE DATABASE / ATTACH DATABASE to accept a SETTINGS clause without an explicit ENGINE, defaulting to Atomic and splitting engine settings from ordinary query settings the same way CREATE TABLE already does. The main split logic looks reasonable, but the new empty-storage ATTACH DATABASE path now makes a formerly rejected class of statements succeed while silently discarding other user-supplied clauses, so I don't think it is ready to merge yet.

Findings

⚠️ Majors

  • [src/Interpreters/InterpreterCreateQuery.cpp:341] Once applySettingsFromQuery hoists every entry out of a no-ENGINE SETTINGS clause, this branch treats the statement as short ATTACH DATABASE and overwrites create from metadata without rejecting the rest of the user query. ATTACH DATABASE db SETTINGS max_threads = 1 COMMENT 'x' (and the same with TABLE OVERRIDE ...) therefore succeeds but silently ignores that clause. Suggested fix: mirror the short-ATTACH TABLE guard in createTable and reject any top-level or storage clauses that would be dropped before create = ast->as<ASTCreateQuery &>().
Final Verdict

Changes requested.

LLVM Coverage Report

Measured on commit df3cad1.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 91.80% 91.70% -0.10%
Branches 80.60% 80.60% +0.00%

Changed lines: Changed C/C++ lines covered: 149/160 (93.12%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. labels Sep 6, 2026
alexey-milovidov and others added 2 commits September 11, 2026 06:41
…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]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit df3cad127e7eeb5f2b2b9d14bc3e6cb7d562a015 with master failed: RuntimeError: CI logs cluster query failed: SELECT file, library, argMax(dur, time) AS ….

See the job log for details.

alexey-milovidov and others added 2 commits September 18, 2026 11:22
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (one conflict in DatabaseOrdinary.cpp: the new Ordinary engine documentation on master, plus this PR's has_builtin_setting_fn), addressed the AI review thread (SETTINGS name = DEFAULT was dropped by the hoisting path, now fixed and tested), and triaged the two CI failures of the previous run at 14314d5, both unrelated to this change:


fs::path metadata_path;
if (!create.storage && create.attach)
if (!has_storage_definition && create.attach)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 &>().

@clickhouse-gh

clickhouse-gh Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

⚠️ AI verdict: not_sure — no significant changes across 37 queries analysed

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_official

⚠️ 1 inconclusive

Flagged queries (1 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 1 not_sure 63 50 -20.6% <0.0001 Flagged improvement (-20.6%) on an unstable, noisy baseline; the PR only touches CREATE/ATTACH DATABASE settings parsing, which a TPC-H SELECT never executes. Treat as variance.

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
  • StressHouse run: ca0e0d21-87d2-45b4-a54b-615548ac0f8f
  • MIRAI run: e30b1afa-3246-48a7-90fb-dc1a297c1b71
  • PR check IDs:
    • clickbench_750157_1789753791
    • clickbench_750163_1789753792
    • clickbench_750169_1789753792
    • tpch_adapted_1_official_750175_1789753791
    • tpch_adapted_1_official_750191_1789753791
    • tpch_adapted_1_official_750209_1789753792

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 20, 2026
Merged via the queue into master with commit 0cc1c63 Sep 20, 2026
175 of 177 checks passed
@alexey-milovidov
alexey-milovidov deleted the inline-disk-for-database branch September 20, 2026 05:12
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 20, 2026
alexey-milovidov pushed a commit to zwy991114/ClickHouse that referenced this pull request Sep 20, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-database-engines Database engine implementations (e.g., Atomic/Replicated) and database-level behavior. pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CREATE/ATTACH DATABASE cannot use an inline disk(...) the way a single table can

2 participants