Skip to content

Fix allow_feature_tier for MergeTree settings - #113156

Merged
Algunenano merged 30 commits into
ClickHouse:masterfrom
Algunenano:fix-feature-tier-merge-tree-settings
Sep 1, 2026
Merged

Algunenano merged 30 commits into
ClickHouse:masterfrom
Algunenano:fix-feature-tier-merge-tree-settings

Conversation

@Algunenano

@Algunenano Algunenano commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

Closes: https://github.com/ClickHouse/clickhouse-private/issues/67193

Two problems with allow_feature_tier and MergeTree settings, both at any non-zero value of the setting (at 0 the tier checks are never reached).

SettingsConstraints::getChecker looked up the tier with Settings::getTier, which does not know about the merge_tree_ prefix used to reference MergeTreeSettings in a settings profile. Any profile element or query setting using such a name was rejected with UNKNOWN_SETTING, even for a PRODUCTION setting:

CREATE SETTINGS PROFILE p SETTINGS merge_tree_max_avg_part_size_for_too_many_parts MIN 536870912
Code: 115. DB::Exception: Unknown setting 'merge_tree_max_avg_part_size_for_too_many_parts'.

MergeTreeSettingsImpl::sanityCheck applied the tier check to every setting whose value differs from the compiled-in default, including the values the server itself sets through compatibility or the merge_tree config section. A single EXPERIMENTAL or BETA setting there made every CREATE TABLE fail, the system log tables included.

Both come from deciding what a query changed by looking at the settings object alone. This decides it by comparing states instead: the settings in effect after the statement are diffed against the settings in effect before it, and only that difference is checked. RESET SETTING, a name respelled through an alias, an override dropped by omission and a value the server itself put in effect all follow from that one rule rather than each needing its own case. A table has no dependency graph, so the comparison is exact.

The tier check now lives in one place, SettingsConstraints, for every kind of setting. MergeTreeSettings::sanityCheck loses its three tier parameters, and with them the allowed_experimental = true it was passed at server startup; the MergeTree call sites pass changesFrom(settings_in_effect) to the constraints check that already existed for them. A custom setting belongs to no tier, which also fixes SET custom_x = 1 failing the first time a session sets it.

A MergeTree setting reached through a settings profile also had to be made to behave as one setting under either of its names. A constraint is stored under the canonical name, so a constraint declared canonically did not apply to a statement that wrote the same setting through its alias, which let MIN, MAX, CONST and disallowed values be bypassed by spelling the setting differently, whatever allow_feature_tier is set to. These names are also carried through Settings as custom settings, so a value was stored under the spelling that wrote it and without the declared type of the setting, and writing the value a setting already had was taken for a change and refused by a CONST constraint. Both names now resolve to the same stored value, compared in the type the setting declares, and a reset clears both. Only the tier check reaching these settings made this reachable: before it, such a statement failed as an unknown setting.

The same rule cannot be applied to users, roles and settings profiles by looking at the entity a statement writes, because their settings reach a session through the whole access graph: a role changes what its dependents get without changing anything about itself, dropping an override falls back to whatever it shadowed, and dropping a role or a profile rewrites everything that referenced it. That is recorded, with the cases and a proposal, in #116126 and is not attempted here.

Related: #116126

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix allow_feature_tier rejecting merge_tree_-prefixed settings in settings profiles as unknown, and rejecting CREATE TABLE because of MergeTree settings set by the server through compatibility or the merge_tree config section. Also fix constraints on a merge_tree_-prefixed setting being bypassed when the setting is written through its alias, and a statement that rewrites the value such a setting already has being refused by a CONST constraint.


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

Version info

  • Merged into: 26.9.1.478 (included in 26.9 and later)
  • Backported to: 26.8.3.7, 26.7.7.6, 26.6.5.18, 26.3.29.3

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.
@clickhouse-gh

clickhouse-gh Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5536701]

Summary: ✅


AI Review

Summary

This PR centralizes allow_feature_tier and constraint handling for MergeTree settings, canonicalizes the merge_tree_ alias paths, and fixes the main ALTER / RESET / profile cases. The remaining problems are in the new "fresh full-definition ATTACH should behave like CREATE" invariant: one previously discussed UNIQUE KEY bypass is still real, and there is still at least one unaddressed CREATE-only table-shape check that a fresh ATTACH can skip.

Findings

❌ Blockers

  • [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/113156#discussion_r3882558751] [src/Storages/MergeTree/registerStorageMergeTree.cpp:760-768,953-970; src/Storages/MergeTree/MergeTreeData.cpp:1197-1211] Full-definition ATTACH is now treated as fresh user input for settings validation, but the remaining UNIQUE KEY guards still key off args.mode <= LoadingStrictnessLevel::CREATE / !attach. That still lets ATTACH TABLE ... UUID ... ENGINE = MergeTree ... UNIQUE KEY ... bypass the experimental gate, the local-only storage-policy check, and the TTL / projection rejects, leaving table shapes reachable through ATTACH that CREATE still forbids. I agree with keeping it out of this PR if it needs a larger follow-up, but the current head still violates the fresh-definition invariant.

⚠️ Majors

  • [src/Storages/MergeTree/registerStorageMergeTree.cpp:689] is_fresh_definition is only wired into the settings and sanity-check paths. Several later CREATE-only table-shape checks still use raw args.mode <= LoadingStrictnessLevel::CREATE / == LoadingStrictnessLevel::CREATE, so a full-definition ATTACH can still skip validation that the equivalent CREATE TABLE rejects. Concrete current examples are allow_suspicious_primary_key at lines 734 / 1096, allow_floating_point_partition_key at lines 1134-1139, and the special *MergeTree + projection reject at lines 1142-1151 for deduplicate_merge_projection_mode = throw. Those should use the same fresh-vs-replayed predicate as the new settings checks.
Final Verdict

Changes requested.

LLVM Coverage Report

Measured on commit 5536701.

Metric Baseline Current Δ
Lines 88.50% 88.50% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 80.80% 80.80% +0.00%

Changed lines: Changed C/C++ lines covered: 269/280 (96.07%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 3, 2026
@Algunenano Algunenano added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Aug 3, 2026
`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.
Comment thread src/Access/SettingsConstraints.cpp Resolved
Comment thread src/Access/SettingsConstraints.cpp Resolved
`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.
Comment thread src/Access/SettingsProfileElement.cpp Resolved
`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.
Comment thread src/Access/SettingsProfileElement.cpp Resolved
Comment thread src/Access/SettingsConstraints.cpp Resolved
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.
Comment thread src/Access/SettingsProfileElement.cpp Resolved
Comment thread src/Access/SettingsConstraints.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5536701e7 with master 0cba27059 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 710.14 MiB 707.11 MiB -3.03 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

19 object files changed (+74.17 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Access/SettingsConstraints.cpp.o 209.01 KiB 243.36 KiB +34.35 KiB (+16.43%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

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]>
@Algunenano
Algunenano force-pushed the fix-feature-tier-merge-tree-settings branch from d44526b to 0a23d98 Compare August 24, 2026 15:11
@Algunenano
Algunenano deleted the fix-feature-tier-merge-tree-settings branch September 1, 2026 10:12
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 1, 2026
Algunenano added a commit that referenced this pull request Sep 1, 2026
Resolve the conflicts of the 26.7 backport of #113156:
- 26.7 has no `PRIVATE_PREVIEW` tier, so its checks are dropped.
- 26.7 has no `alter_effective_settings` in `checkAlterIsPossible`, so the
  post-ALTER settings are rebuilt locally for the constraints check.
- `tryGetTierOfBuiltin` is added to `BaseSettings` and `Settings`, which the
  new `settingGetTier` needs and 26.7 did not have.
Algunenano added a commit that referenced this pull request Sep 1, 2026
Resolve the conflicts of the 26.6 backport of #113156:
- 26.6 has no `PRIVATE_PREVIEW` tier, so its checks are dropped.
- 26.6 has no `alter_effective_settings` in `checkAlterIsPossible`, so the
  post-ALTER settings are rebuilt locally for the constraints check.
- `changesFrom` and `getAllAliasNames` follow the 26.6 `MergeTreeSettings`
  signatures, which take no `ContextPtr`.
- `tryGetTierOfBuiltin` is added to `BaseSettings` and `Settings`, which the
  new `settingGetTier` needs and 26.6 did not have.
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 1, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request Sep 1, 2026
Cherry pick #113156 to 26.6: Fix allow_feature_tier for MergeTree settings
robot-clickhouse-ci-2 added a commit that referenced this pull request Sep 1, 2026
Cherry pick #113156 to 26.7: Fix allow_feature_tier for MergeTree settings
Algunenano added a commit that referenced this pull request 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 added a commit that referenced this pull request Sep 1, 2026
Cherry pick #113156 to 26.3: Fix allow_feature_tier for MergeTree settings
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 1, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 1, 2026
Backport #113156 to 26.6: Fix allow_feature_tier for MergeTree settings
clickhouse-gh Bot added a commit that referenced this pull request Sep 1, 2026
Backport #113156 to 26.8: Fix allow_feature_tier for MergeTree settings
clickhouse-gh Bot added a commit that referenced this pull request Sep 1, 2026
Backport #113156 to 26.7: Fix allow_feature_tier for MergeTree settings
Algunenano added a commit that referenced this pull request Sep 1, 2026
Backport #113156 to 26.3: Fix allow_feature_tier for MergeTree settings
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.6-must-backport v26.7-must-backport v26.8-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants