Skip to content

Reject a dictionary SETTINGS name that is not a setting at all - #121579

Open
groeneai wants to merge 8 commits into
ClickHouse:masterfrom
groeneai:dictionary-settings-unknown-name
Open

groeneai wants to merge 8 commits into
ClickHouse:masterfrom
groeneai:dictionary-settings-unknown-name

Conversation

@groeneai

@groeneai groeneai commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Backward Incompatible Change

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

CREATE DICTIONARY now rejects a SETTINGS name that is neither a builtin setting nor prefixed for user-defined settings, instead of accepting it and silently ignoring it. A dictionary whose stored definition already names one still loads, but restating that definition now fails until the name is dropped from it.

Description

Related: #121202. Requested by @ PedroTadim in #121394 (comment). It is the widest surface of that family: the ordinary name = value spelling gets through, so any typo is silently a no-op.

Root cause. getDictionaryConfigurationFromAST copies the whole ASTDictionarySettings payload into the generated config, and Context::applySettingsChanges applies it. Query Settings is declared ALLOW_CUSTOM_SETTINGS, so an unknown name falls through to getCustomSetting, which creates the entry rather than throwing. Measured on 26.10, SETTINGS(not_a_setting = 1) creates, persists, loads, and dictGet serves the row: a silent no-op, not a deferred error.

Change. Check the names in registerStorageDictionary, the one creator every DDL dictionary passes through. The predicate is the check every SET already passes (Settings::resolveName, the profile exemption, then AccessControl::checkSettingNameIsAllowed), which this path skipped: it reaches applySettingsChanges without passing SettingsConstraints. Aliases, obsolete settings, format settings, prefixed custom settings and profile stay accepted; all 28 dictionary SETTINGS names in tests, docs and the fuzzer are query settings, so nothing existing starts failing.

Grandfathering. Only a fresh definition is judged, so stored metadata, ATTACH, RESTORE and Replicated replay still load, with no new context marker. Config-file dictionaries never reach a storage creator, so a config reload cannot throw.

Category. No released version does anything wrong, it accepts what it should refuse, and previously-accepted DDL now errors: backward incompatible, not a bug fix. SHOW CREATE DICTIONARY output fed back, or a CREATE OR REPLACE, is fresh input and now fails until the name is dropped.

Scope. Names only: this path still bypasses SettingsConstraints, so a constrained setting is still applied unchecked. ALTER ... MODIFY SETTING is untouched.

Validation. Two new stateless tests cover rejection, acceptance and grandfathering over a stored definition edited to name a non-setting; both fail without the fix and are 100/100 under randomization.


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

groeneai and others added 2 commits September 22, 2026 13:24
A dictionary `SETTINGS(...)` clause accepted any name. `getDictionaryConfigurationFromAST`
copies the whole `ASTDictionarySettings` payload into the generated dictionary config,
`readSettingsFromDictionaryConfig` reads it back as `SettingsChanges`, and
`Context::applySettingsChanges` applies it. Query `Settings` is declared
`DECLARE_SETTINGS_TRAITS_ALLOW_CUSTOM_SETTINGS`, so `BaseSettings::set` misses in the
accessor and falls through to `getCustomSetting`, which creates the entry instead of
throwing. `throwSettingNotFound` is therefore unreachable on this path, which is why the
failure was a complete silent no-op rather than a deferred load error: measured on 26.10,
`SETTINGS(not_a_setting = 1)` created, persisted, loaded, and `dictGet` served the row, and
`SHOW CREATE DICTIONARY` wrote the bogus name back out.

Check the names in `registerStorageDictionary`, the single creator every DDL-originated
dictionary materialisation passes through. Because it is a `StorageFactory` creator it
already carries `args.mode` and `args.query.attach_short_syntax`, so no new context marker
is needed to tell a fresh definition from a replayed one.

The predicate is not a new one. It is the check every `SET` already passes:
`Settings::resolveName`, the `profile` exemption, then
`AccessControl::checkSettingNameIsAllowed`. This path skipped it only because it reaches
`applySettingsChanges` without ever passing `SettingsConstraints`. Accessor membership comes
from `LIST_OF_SETTINGS`, so aliases, obsolete settings and format settings stay accepted;
`Settings::has` would have been wrong, since a registered-prefix custom setting need not be
held by the session yet (the entry creates it) and `profile` is not a `Settings` entry at
all. A sweep of every dictionary `SETTINGS` name in tests, docs, utils and the BuzzHouse
generator found 28 distinct names, all query settings, six of them from
`FormatFactorySettings.h`, so nothing existing starts failing.

The guard is one freshness call plus the Cloud Shared Catalog term. The storage sibling's
separate `is_ddl_replay` term is redundant here, because
`InterpreterCreateQuery.cpp:1821-1822` folds the metadata transaction and
`is_restore_from_backup` into `SECONDARY_CREATE`, and its
`isRecoveryFromStoredMetadata()` term is unreachable for a dictionary: the Keeper-restore
loop skips any create query with no `ASTStorage`, `SYSTEM RESTART REPLICA` refuses anything
that is not a `StorageReplicatedMergeTree`, and `recoverLostReplica` already installs a
non-initial transaction. A full-definition `ATTACH DICTIONARY` does not exist as syntax
(`ParserCreateQuery.cpp:1874-1891` parses the definition only `if (!attach)`), so there is
no attach-shaped bypass, and config-file dictionaries never reach a `StorageFactory` creator
at all, so a config reload cannot throw.

Rejected alternatives: validating in `getDictionaryConfigurationFromAST` (also called on
stored definitions during database loading, with no `mode`, so it would fail the whole load
and could not grandfather), validating in `readSettingsFromDictionaryConfig` (runs on every
load and on XML dictionaries), and reusing `checkStorageSettingNames` (it asserts a
`has_builtin_setting_fn` the `Dictionary` storage does not register, and its
`engine builtin || Settings::has` predicate is the wrong one here).

Names only: this path still bypasses `SettingsConstraints`, so a constrained setting is
still applied unchecked. That is a wider change and is not folded in.

Requested by @PedroTadim in
ClickHouse#121394 (comment).
Related: ClickHouse#121202

Co-Authored-By: Claude Opus 5 <[email protected]>
Condense both comments to one line each and drop the clause restating how the check is built.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 22, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding), plus my own cold
review of the same tree written before I read the implementation notes (3 nits). No fix round
was needed.

# Sev Finding Verdict Evidence / action
1 ❌ A Replicated secondary replaying a full-definition ATTACH DICTIONARY ... SETTINGS(...) would be judged as fresh DDL and would spin its queue entry forever, so the non-initial metadata-transaction exemption is missing DISAGREE That statement does not exist. ParserCreateQuery.cpp:1874-1891 parses a dictionary definition only if (!attach), so query->dictionary is null for every attach (IAST.h:221-224 ignores a null child) and the check returns before it ever reads args.mode; typed out, it is Code: 62 at position 23. A replay re-parses the entry text with the current parser (DDLTask.cpp:297-305), and a stored dictionary definition is replayed as a CREATE, not an ATTACH (DatabaseOnDisk.cpp:216-217), which is already SECONDARY_CREATE. The exemption would be dead code, and the regression test asked for would assert a syntax error
2 💡 The rejection reuses AccessControl::checkSettingNameIsAllowed, so the message names neither the dictionary nor the clause and drops the Maybe you meant ... hint the same predicate gets under SET DISAGREE Deliberate: no new error text and no ErrorCodes entry keeps this to one helper and one message that users already know from SET
3 💡 A merge_tree_-prefixed MergeTree setting name still passes the check and still has no effect DISAGREE resolveSetting.h:29-41 resolves that prefix, so SET merge_tree_index_granularity = 1 is accepted for the same reason. Refusing it here would make a dictionary stricter than SET, which is not what this change claims

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-10:20260922-132700

@clickhouse-gh clickhouse-gh Bot closed this Sep 22, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 22, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, 100%, one command: a clickhouse local script that creates a dictionary over SOURCE(CLICKHOUSE(...)) with SETTINGS(not_a_setting = 1), then dictGets it. Unfixed it prints 42.
b Root cause explained? Yes. The whole ASTDictionarySettings payload is copied into the generated dictionary config and applied with Context::applySettingsChanges; query Settings is declared ALLOW_CUSTOM_SETTINGS, so an unknown name falls through to getCustomSetting, which creates the entry instead of throwing. throwSettingNotFound is unreachable on this path, which is why the failure is a silent no-op and not a deferred load error.
c Fix matches root cause? Yes. The name is refused where the definition is stated, in the one creator every DDL-originated dictionary passes through, using the name check every SET already passes. No widened bound, no no-random-* tag, no defensive guard at the symptom, no new bespoke predicate.
d Test intent preserved / new tests added? No existing test weakened. Two new stateless tests: 05237 (rejection and acceptance arms) and 05238 (grandfathering over a stored definition edited to name a non-setting, with a grep negative control proving the edit landed).
e Both directions demonstrated? Yes, on Build-ID-verified binaries (base 83ca5b69, fix 0c038499). Repro: 42 unfixed, Code: 115 UNKNOWN_SETTING fixed. 05237 fails on the unmodified binary on 5 arms, 05238 on its restatement arm; both pass with the fix.
f Fix is general across code paths? The check sits at the single StorageFactory creator, so CREATE and CREATE OR REPLACE are both covered (the latter tested). Measured, not argued: a full-definition ATTACH DICTIONARY is a syntax error (Code: 62), because the parser reads the definition only if (!attach), so there is no attach-shaped bypass. SYSTEM RELOAD DICTIONARY re-reads the built config object and never re-runs the creator; config-file dictionaries never reach a creator at all.
g Fix generalizes across inputs (params/datatypes/wrappers)? The varying domain here is the name space, not a value domain. Exercised: builtin, alias (resolved before the check, so an alias cannot be rejected), obsolete, format setting, registered-prefix custom setting, profile, param_-prefixed, unknown, and a case-shifted prefix.
h Backward compatible? (maintainer-approved exception only) This is the backward-incompatible change itself, handled the sanctioned way: only fresh definitions are judged, so every stored definition keeps loading (05238 pins startup, short-syntax ATTACH, and that the name survives in create_table_query). Restating such a definition now fails, which the changelog entry states. No setting added, removed or re-defaulted, so no SettingsChangesHistory.cpp entry is owed.
i Invariants and contracts preserved? The helper is read-only: it inspects the AST and either throws or returns, holds no lock, and runs before any dictionary object is constructed, so no partially-built state exists on the throw path. It runs after args is populated and before the existing DICTIONARY_ALREADY_EXISTS probe, so no ordering contract changes. A Replicated secondary and a Cloud Shared Catalog secondary both return early, so neither can refuse its initiator's DDL and spin its queue entry forever.

Session id: cron:clickhouse-impl-slot-40:20260922-113600

@groeneai
groeneai requested a review from PedroTadim September 22, 2026 14:08
@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [20ee3bc]

Summary: ❌

job_name test_name status info comment
Fast test FAIL
05248_dictionary_setting_name_quoting FAIL cidb
05828_create_dictionary_key_value_formatting FAIL cidb
Code Review DROPPED
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_asan_ubsan) DROPPED
Build (arm_binary) DROPPED

@clickhouse-gh clickhouse-gh Bot added the pr-backward-incompatible Pull request with backwards incompatible changes label Sep 22, 2026
@PedroTadim PedroTadim self-assigned this Sep 22, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-dictionary Dictionaries (in-memory key-value, periodically refreshed from sources). label Sep 22, 2026
Asked for on the PR: the `param_` and `= DEFAULT` cases, and an `ATTACH` that fails.

`ParserDictionarySettings` parses this clause with the plain
`ParserSetQuery::parseNameValuePair`, so it has one `name = value` payload. Unlike the
storage-engine clause, a `param_` name is not hoisted into a query parameter: it arrives
verbatim and is checked like any other name, which the test already covered, and there is
no `DEFAULT` branch to parse into, so that spelling is a syntax error whatever the name,
a real setting included. A dictionary definition is parsed only for a create
(`ParserCreateQuery.cpp:1874-1891`), so an `ATTACH` stating settings is a syntax error
too, with or without a `UUID`, which is why the exempt replay path is not reachable from
SQL and needs the stored-definition test.

Both new spellings fail in the client, hence `clientError SYNTAX_ERROR`. Each arm was
confirmed live by flipping its expectation and watching the test fail.

05238 now states what it covers, since a reader is otherwise left to guess: a definition
already stored with such a name, which needs a file edit because SQL will not write that
state any more.

Co-Authored-By: Claude Opus 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing edd0d152f with master bdbd1b837 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of b02fbee24; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 5eb386d

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Upgrade check (amd_release) / Error message in clickhouse-server.log Code 69 ARGUMENT_OUT_OF_BOUND, The range given in function countResample is empty, raised in AsyncLoader::worker while attaching a previous-release table typed AggregateFunction(countResample(10, 5, 1), UInt64, UInt64). Unreachable from this PR's diff, which only adds a dictionary SETTINGS name check. 22 distinct PRs carry it in 30 days, 0 true master #121590 (external, merged into 26.9). Neither rule 3c nor 3d applies, measured rather than assumed: 4d46c03d0066 is diverged from both master (ahead 106, behind 3782) and this head, so the fix is exclusive to the release branch and no master merge can pick it up. It changes the previous release's own stateless tests, so it takes effect here only once a v26.9 tag carries it; the newest published tag is v26.9.2.8-stable, which sits 9 commits behind that merge, so the release artifact this check downloads still predates the fix
Upgrade check (amd_release) / The mutation submitted before the upgrade was not finished by the new server False red produced by the row above rather than a stalled mutation: system.mutations resolves every table it enumerates before the WHERE narrows the set down, so the un-attachable table makes the verification query itself fail and the runner reports that as an unfinished mutation. 50 distinct PRs in 30 days, 0 true master #121315 (mine, open) for the misreporting, #121590 (external, merged into 26.9) for the underlying cause
Mergeable Check Aggregator reflecting the two Upgrade check rows above, no independent failure #121315 (mine, open), #121590 (external, merged into 26.9)
PR Aggregator reflecting the two Upgrade check rows above, no independent failure #121315 (mine, open), #121590 (external, merged into 26.9)

All 173 check runs are complete and Finish Workflow succeeded at 05:20:08Z: 66 success, 33 skipped, 1 failure, plus the two commit-status aggregators that reflect it. The three red entries above are the only ones.

Session id: cron:our-pr-ci-monitor:20260923-053134

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai is this going to be safe for upgrades if a setting gets deprecated? Don't change anything yet

@groeneai

Copy link
Copy Markdown
Collaborator Author

Yes, and both halves are pinned by the tests in the diff.

Deprecation keeps the name: MAKE_OBSOLETE entries stay in LIST_OF_SETTINGS, so Settings::resolveName and hasBuiltin still resolve them and checkSettingNameIsAllowed returns early; a renamed setting resolves through its alias the same way. The alias, obsolete, format arm of 05237 states a real obsolete setting (parallel_replicas_only_with_analyzer) and a real alias (insert_distributed_sync), and the dictionary loads and serves.

A name dropped from the accessor outright is safe too, which is the unattachable shape you described on #122204: the check sits behind isFreshTableDefinition, so startup loading, short ATTACH, Replicated replay and RESTORE (both SECONDARY_CREATE) never reach it, and its config-dependent half, the registered custom-setting prefixes, is therefore never evaluated at load time. 05238 measures that: a definition stored with a name that is not a setting at all loads, serves and survives DETACH/ATTACH, and only restating it is refused.

So an upgrade cannot turn a working dictionary into one that will not load. The only new refusal is a freshly stated CREATE. I have changed nothing, as you asked; this answers for the dictionary surface, and I will answer for the database surface on #121661.

@PedroTadim

Copy link
Copy Markdown
Member

🕵️ @groeneai

The check looks right to me: I traced startup, short ATTACH, Replicated replay, lost-replica recovery and RESTORE, and all of them reach it as a non-fresh definition, so stored dictionaries keep loading.

One nit: checkDictionarySettingNames builds its own exemption, !isFreshTableDefinition(...) plus an #if CLICKHOUSE_CLOUD copy of the Shared Catalog part of isSecondaryDDLReplay. isReplayedTableDefinition(args.mode, args.query, local_context) from StorageFactory.h already covers both, and also the Replicated secondary and isRecoveryFromStoredMetadata cases. Using it would keep this check in step with checkStorageSettingNames and drop the SharedDatabaseCatalog.h include.

PedroTadim and others added 2 commits November 5, 2026 12:43
Review feedback on ClickHouse#121579: reuse the shared predicate from StorageFactory.h
instead of rebuilding the exemption (isFreshTableDefinition plus a
CLICKHOUSE_CLOUD copy of the Shared Catalog half of isSecondaryDDLReplay).
It also covers a Replicated secondary and isRecoveryFromStoredMetadata, keeps
this check in step with checkStorageSettingNames, and drops the
SharedDatabaseCatalog.h include.

No behaviour change for a fresh CREATE DICTIONARY: on a Replicated database the
initiator runs under an initial metadata transaction, so the extra terms are
false there and the name check still fires.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Done in edd0d15: checkDictionarySettingNames now returns on isReplayedTableDefinition(args.mode, args.query, local_context), the same guard as checkStorageSettingNames, and the SharedDatabaseCatalog.h include is gone.

05237 and 05238 pass 10/10 each with randomized settings, and 05237 also 10/10 with --replicated-database, where the initiator still rejects the unknown name.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-dictionary Dictionaries (in-memory key-value, periodically refreshed from sources). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-backward-incompatible Pull request with backwards incompatible changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants