Skip to content

Cherry pick #113156 to 26.3: Fix allow_feature_tier for MergeTree settings - #117491

Merged
robot-clickhouse-ci-1 merged 32 commits into
backport/26.3/113156from
cherrypick/26.3/113156
Sep 1, 2026
Merged

robot-clickhouse-ci-1 merged 32 commits into
backport/26.3/113156from
cherrypick/26.3/113156

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Original pull-request #113156

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

Algunenano and others added 30 commits August 3, 2026 16:55
The tier lookup in `SettingsConstraints::getChecker` used `Settings::getTier`, so a
`merge_tree_`-prefixed name (which refers to `MergeTreeSettings`) was reported as an unknown
setting whenever `allow_feature_tier` was not 0. It is now resolved through `resolveSetting`.

`MergeTreeSettingsImpl::sanityCheck` also applied the tier check to values set by the server
itself, through `compatibility` or the `merge_tree` config section, which made every
`CREATE TABLE` fail once the tier disallowed one of them. Those are now tracked and skipped,
while changes coming from a query are still checked.
`sanityCheck` gated the tier check on `isValueChanged()` (a sticky "ever explicitly
assigned" flag, not a live comparison against the compiled default) plus a
`changed_by_server` exemption list. This mostly happened to work, but relying on
`isValueChanged()` is fragile, and it made a genuine no-op - a query re-declaring a
`MergeTree` setting to the value already in effect - trip the tier check, unlike the
equivalent `Settings` path (`SettingsConstraints::getNewValueToCheck`), which exempts
exactly that case.

Replace `changed_by_server` with `changed_by_query`, marking a setting only when a
query sets it to a value that differs from what is currently in effect. This matches
`Settings`' semantics: a real change is checked regardless of what the resulting value
happens to equal (so reverting an admin-forced EXPERIMENTAL/BETA setting back to its
compiled default is still caught), while re-declaring the same value is a no-op.

Also swaps the EXPERIMENTAL example setting used in the integration test, since
`compute_exact_num_defaults_for_sparse_columns` is being moved to BETA in a separate PR.
An ALTER replays the table's full stored SETTINGS list, not just its own delta.
`applyChangesFromQuery` compared each entry against a freshly-defaulted copy instead of
the table's live settings, so an EXPERIMENTAL/BETA override already on the table got
re-flagged as a change on every subsequent unrelated ALTER once the tier tightened.

Add an optional baseline to applyChanges/applyChangesFromQuery and pass the table's live
settings from MergeTreeData::changeSettings.
`ALTER TABLE ... RESET SETTING` drops the name from the post-ALTER SETTINGS list
instead of setting it to the default, so it never reached applyChangesFromQuery and
never tripped the feature tier check, unlike the equivalent MODIFY SETTING to the
default value. Add the removed name back with its reverted value so it's checked
the same way.

`ALTER USER/ROLE/SETTINGS PROFILE ... DROP SETTING` had the same asymmetry:
SettingsConstraints::check unconditionally skipped drop_settings. Route each dropped
setting through the same check as a MODIFY to its compiled default.
drop_settings can name a custom (user-defined) setting, which has no compiled
default and isn't builtin, so Settings::get threw UNKNOWN_SETTING for it. Skip
those the same way they were skipped before this check existed.
`merge_tree_`-prefixed drop: `Settings::hasBuiltin` doesn't recognize the
`merge_tree_` prefix convention, so dropping such a name from a user/role/profile
skipped the tier check entirely. Use `settingIsBuiltin`/`settingGetDefaultValue`
(resolveSetting-aware) instead.

`DROP ALL SETTINGS` (and old-style `SETTINGS ...` full replacement, which drops by
omission) bypassed the tier check the same way explicit `DROP SETTING` did before
the previous fix, since neither ever appeared in `drop_settings`. Add
`SettingsProfileElements::findRevertedSettingNames`, and have each of the three
ALTER interpreters (User/Role/SettingsProfile) fetch the target's current settings
and feed every name the change reverts into `drop_settings` before the check runs.

`MergeTreeData::changeSettings`'s RESET-detection compared canonical names (from
`old_settings->changes()`) against raw strings in `new_changes`, so a setting kept
alive under an alias looked removed and got silently reset to its default on any
unrelated ALTER - a correctness bug independent of allow_feature_tier. Compare
resolved names on both sides instead.
`CREATE USER/ROLE/SETTINGS PROFILE OR REPLACE` is a full replacement of an existing
entity too, just like an old-style `ALTER ... SETTINGS` or `DROP ALL SETTINGS`, so
it needs the same revert-name expansion; the previous fix only guarded on
`query.alter`.

`findRevertedSettingNames` only looked at `element.value`, missing constraint-only
elements (`MIN`/`MAX` with no plain value), which `SettingsConstraints::check`
checks against the tier too.
The synthetic drop-check in SettingsConstraints compared against the acting
admin's own session instead of the target's value, so an admin at compiled
defaults could still strip another user's genuine EXPERIMENTAL/BETA override.
findRevertedSettingNames only diffed direct elements, missing settings
inherited through an attached SETTINGS PROFILE and mismatching on aliases.
Decide what a statement changed by comparing the settings in effect before it
with the settings in effect after it, instead of inspecting how the change was
written.

`MergeTreeSettings::sanityCheck` no longer performs the feature tier check and
loses its three tier parameters, along with the `allowed_experimental = true` it
was passed at server startup. The check now lives in `SettingsConstraints`,
which every query-side path already reaches with the settings in effect and the
changes to apply, so the call sites pass `changesFrom(settings_in_effect)`. A
value the server itself set through `compatibility` or the `merge_tree` config
section is therefore not a change made by the query, while `RESET SETTING`, a
name respelled through an alias and a revert to the compiled default are.

`SettingsConstraints::getChecker` resolved the tier with `Settings::getTier`,
which does not know about the `merge_tree_` prefix used to reference
`MergeTreeSettings` in a settings profile, so such a name was rejected as
unknown even for a PRODUCTION setting. The tier is now resolved through
`resolveSetting`, and a custom setting belongs to no tier.

For access entities, `SettingsProfileElements::findChangedSettings` diffs the
entity's effective settings, with inherited profiles substituted, aliases
resolved and the last occurrence winning, so a change is measured against the
entity being altered rather than against the session of whoever runs the
statement. A full-definition `ATTACH TABLE`, granting or revoking a role that
carries settings, and assigning a settings profile are checked as well.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The feature tier check moved out of `MergeTreeSettingsImpl::sanityCheck`, and it
was the only thing throwing `READONLY` in this file.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ource

`CREATE USER ... SETTINGS PROFILE p` reported every setting `p` carries as a
change made by the user, so `max_sessions_for_user`, which may only be set in a
profile, was refused with `READONLY`.

The effective settings diff now records whether a value comes from a substituted
profile or from the entity's own settings, and checks the inherited ones with
`SettingSource::PROFILE`. What the statement writes on the entity itself is
unaffected: it still goes through the entity's own source, so setting
`max_sessions_for_user` directly on a user stays refused.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`getEffectiveSettings` takes its elements by const reference, so the `std::move`
at the call site moved nothing. `clang-tidy` rejects it with
`performance-move-const-arg`, and the tidy build treats warnings as errors.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`CREATE USER OR REPLACE u ... ROLE r` checked everything `r` carries as if the
role were granted for the first time, so replacing a user with the roles it
already holds was refused once the feature tier was tightened, even though it
grants nothing.

Only the roles that are new to every target are a change now, the same way
`GRANT` and a settings profile's `TO` clause already work. `IF NOT EXISTS` on an
existing user is covered too, since that statement changes nothing at all.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The diff of the entity's effective settings ran the whole checker on every
change it found, and forced it to run by declaring the change already known,
which skips the comparison with the caller's own settings. Two things that must
be allowed were refused by that: writing a value the caller already has under a
`CONST` constraint of its own (`CREATE USER u SETTINGS max_threads = 1 CONST`
run by a user whose `max_threads` is `1 CONST`), and referencing a profile that
carries a setting the caller may not change (`CREATE USER u SETTINGS PROFILE p`
where `p` sets `cloud_mode`). Neither is the caller changing its own setting.

Constraints, writability and the source of a setting are decided by the checks
over the elements the statement writes, against the caller's own settings, as
before. `allow_feature_tier` answers a different question - whether the entity's
settings change at all - so it is now the only thing the diff decides, and the
diff reports names rather than values.

A setting written explicitly to its compiled default is no longer reported as a
change, matching what `SET` does with the same value.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A user only gets the settings of the roles that are default for it: measured on
a granted role that is not default, the setting it carries reads as its compiled
default, and `SET ROLE` does not change that, over a client session or over HTTP
with a session id. Granting such a role therefore changes no setting, but it was
refused once the feature tier was tightened.

`GRANT` and `REVOKE` now look only at the roles a user would actually enable,
and the `ROLE` clause of `CREATE USER` is intersected with the default roles the
resulting user will have. Roles granted to a role keep being checked in full,
because all of them are enabled along with it.

Nothing is let through: making such a role default is the change that matters,
and it is checked where the default roles change.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…erge-tree-settings

# Conflicts:
#	src/Interpreters/Access/InterpreterSetRoleQuery.cpp
`allow_feature_tier` is about the settings a user ends up with, and a statement's
effect on that is only visible once the whole access graph is resolved. Deciding
it from the entity being written cannot see the rest: a role or a settings
profile changes what its dependents get without changing anything about itself,
dropping an override falls back to whatever it shadowed rather than to the
compiled default, `DROP ROLE` and `DROP SETTINGS PROFILE` rewrite every entity
that referenced them, and a check that runs before the storage update is not
atomic with it, so two harmless statements can compose into a forbidden result.

Every one of those was found as a separate case, and each fix made room for the
next. They are one problem, and it needs a way to resolve settings against the
access graph with the entities a statement is about to write or delete applied as
overrides, which is a change to how roles and settings profiles are resolved
rather than something to add per statement. Recorded in
#116126, so what remains here is the `MergeTree` settings
this branch set out to fix, where a table has no dependency graph and comparing
the settings in effect before and after is exact.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`set` stores a constraint under the canonical name and remembers the alias it was
declared with, if it was declared with one. The lookups went through that memory
alone, so a constraint declared canonically was invisible to a statement that
wrote the same setting through its alias:

    <constraints><merge_tree_enable_block_number_column><const/></...></constraints>
    SELECT 1 SETTINGS merge_tree_allow_experimental_block_number_column = 1

refused the canonical name and accepted the alias. The lookups now resolve the
name the way `set` resolves it. `Settings::resolveName`, which the callers apply,
leaves a `merge_tree_`-prefixed name alone, so only such a name needs resolving
again here and an ordinary setting still costs nothing.

This is not limited to the feature tier: `MIN`, `MAX`, `CONST` and disallowed
values on a `merge_tree_`-prefixed constraint could all be bypassed the same way.
The tier check reaching these settings at all is what makes it reachable, since
before that such a statement failed as an unknown setting.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A `merge_tree_`-prefixed name is carried through `Settings` as a custom setting,
so its value is stored under the spelling that wrote it and without the declared
type of the setting. Two things followed from that. Writing the value a setting
already has was taken for a change, because the stored value keeps the type it
was parsed as (`Bool_1`) while the statement supplies another (`UInt64 1`), and
that is true of the canonical name as much as of the alias. And a value written
under one name was invisible to the other, so an alias never saw it at all.

Together they made a statement that changes nothing be refused by a `CONST`
constraint:

    CREATE SETTINGS PROFILE p SETTINGS merge_tree_enable_block_number_column = 1 CONST
    SELECT 1 SETTINGS merge_tree_enable_block_number_column = 1        -- refused
    SELECT 1 SETTINGS merge_tree_allow_experimental_block_number_column = 1  -- refused

The value in effect is now read under either spelling and compared in the type
the setting declares, and a reset clears both spellings, so one name cannot leave
behind what the other wrote. Writing a value that really differs is still a
change and is still refused.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…n replay

`Settings` keeps a `merge_tree_`-prefixed name as a custom setting under the exact name that wrote
it, so a value written as `merge_tree_allow_experimental_block_number_column` was not found when
looking up `merge_tree_enable_block_number_column`, its other name for the same setting. Look under
every name when reading the current value of a setting and when resetting it to the default.

`ALTER` no longer re-checks the settings constraints when a `Replicated` database replays the query
on another replica. `allow_feature_tier` comes from each replica's own config, so a replica set to a
stricter tier refused a change that was already in the DDL queue: that stopped the queue and left
the replicas with different table metadata. `CREATE` already skips the same check on replay.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A `merge_tree_`-prefixed name is not a `Settings` setting, so `SET merge_tree_... = DEFAULT` took the
path for custom settings, which validates the value the setting already has. That value always passes,
so a constraint was escaped by dropping the setting instead of by writing a value it forbids: with a
profile declaring `merge_tree_index_granularity MIN 16384`, the reset was accepted and left the
setting at its default of 8192.

Such a name does have a declared default, the one of the `MergeTreeSettings` setting it names, so
resolve the name and check the reset against that default, the same way a reset of a plain setting is
checked.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A full-definition `ATTACH TABLE t UUID '...' (...) ENGINE = ...` is user input like `CREATE`
is, which the extended syntax already took into account. Two other carriers of the same
settings did not.

The old engine syntax states `index_granularity` as an engine argument instead of in a
`SETTINGS` list, and validated it only under `CREATE`, so an `ATTACH` stating it that way
escaped a `merge_tree_index_granularity` constraint that the same `CREATE` is refused by.

A projection carries a `MergeTree` settings list of its own in `WITH SETTINGS`, gated on
`CREATE` as well, so a full-definition `ATTACH` could carry a projection setting outside the
list projections accept, one violating a constraint, or one of a disabled feature tier.

The rule itself is now `isFreshTableDefinition`, next to `isLoadingFromExistingMetadata`,
because three call sites need it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…te it

`Settings` carries a `merge_tree_`-prefixed setting as a custom setting, keyed by the exact
name that wrote it, and its alias resolution knows only its own settings. So the two names of
one `MergeTreeSettings` setting became two entries holding two values: a profile stating
`merge_tree_enable_block_number_column = 1` and
`merge_tree_allow_experimental_block_number_column = 0` gave a different answer for each name.
Looking a value up under every name of the setting repaired reads, not this.

A custom setting is now stored under the canonical name of the setting. `BaseSettings` gains
`resolveCustomSettingName`, the identity for every settings class, and `Settings` alone
resolves a `merge_tree_`-prefixed alias to the name the same setting has otherwise. Writing,
reading and resetting under either name all reach one value, and a list stating both names is
the same as stating the last of them twice.

`MergeTreeSettings::getAllAliasNames` reads nothing but the alias table, so it is static now
and the two `MergeTreeSettings` built only to call it are gone.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…erge-tree-settings

`master` grew `BaseSettings::tryGetTierOfBuiltin`, which reads the tier of a setting without an
instance and says nothing instead of throwing when the name is not a built-in one. That is what
this branch added `getBuiltinTier` for, so the branch drops its own and uses that, for
`MergeTreeSettings` as well. A custom setting reaching `settingGetTier` is now the empty result
rather than a separate `hasBuiltin` call.
…e it on trust

`getProjectionFromAST` took the answer as a parameter, and a caller that did not state it got
`false`. `ALTER TABLE ... ADD PROJECTION` and `MODIFY PROJECTION` state `LoadingStrictnessLevel::CREATE`
and nothing else, so they silently stopped checking the settings of the projection they create:
a settings list outside the one projections accept, or an `index_granularity` of 0, was accepted.

The two parameters described one thing twice and could disagree. The freshness of the definition
is now derived where it is used, from the strictness level and the syntax of the `ATTACH`, so a
call site states what it knows and cannot state it wrong.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…the constraints

`MergeTreeData` runs `sanityCheck` on the settings it is handed when the mode says `CREATE`, so a
full-definition `ATTACH` never reached it: it could state `index_granularity = 0`, which the same
`CREATE` refuses, and the table was created broken. It is checked where the rest of a fresh
definition is checked, leaving the mode-driven check in the constructor alone, because that one
also decides how strictly a stored definition is read back.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A value in a session is now kept under one name, but the metadata that outlives the session was
still matched by the name as written. A table storing `allow_experimental_block_number_column`
did not notice `ALTER TABLE ... RESET SETTING enable_block_number_column`, which named the same
setting: the reset found nothing and said nothing, and `MODIFY SETTING` under the other name
added a second entry, so one definition stated one setting twice with two values. A settings
profile behaved the same way for `DROP SETTING`.

Both carriers now find an entry by the setting it names rather than by the name it uses, and a
statement that writes a setting already there replaces that entry under the name it just stated.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…f its names

A definition can already hold an entry under each name of one setting, from a `CREATE` stating
both or from metadata written before the two names were made to mean the same setting. Writing
the setting then rewrote the first entry and left the second, which is the one in effect, so
`ALTER TABLE ... MODIFY SETTING` appeared to do nothing, and a reset removed one of the two and
left the setting set.

Writing a setting now leaves it holding one entry, and resetting it removes every entry it has.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…e-settings

Fix allow_feature_tier for MergeTree settings
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Sep 1, 2026
Resolve the conflicts of the 26.3 backport of #113156:
- 26.3 has no `PRIVATE_PREVIEW` tier and no `background_pool_auto_lowered`
  argument on `sanityCheck`, so both are dropped.
- 26.3 rebuilds the post-ALTER settings locally in `checkAlterIsPossible`, and
  `getNewValueToCheck` keeps its 26.3 shape (no `ignore_unchanged_settings`).
- Projections do not carry `MergeTreeSettings` in 26.3, they read only
  `index_granularity` and `index_granularity_bytes` through `loadSettings`, so
  the `ProjectionsDescription` part of the change and its test do not apply.
- `changesFrom`, `getAllAliasNames` and `tryGetTierOfBuiltin` are added, and the
  `MergeTree` setting the integration test states in the config is one that
  exists in 26.3.
@robot-clickhouse-ci-1
robot-clickhouse-ci-1 merged commit 8008c70 into backport/26.3/113156 Sep 1, 2026
1 check passed
@robot-clickhouse-ci-1
robot-clickhouse-ci-1 deleted the cherrypick/26.3/113156 branch September 1, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants