Skip to content

Represent ALTER ... MODIFY SETTING name = DEFAULT as a reset - #119475

Merged
Algunenano merged 11 commits into
ClickHouse:masterfrom
Algunenano:modify-setting-default-engine-guards
Sep 21, 2026
Merged

Algunenano merged 11 commits into
ClickHouse:masterfrom
Algunenano:modify-setting-default-engine-guards

Conversation

@Algunenano

@Algunenano Algunenano commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Closes: #119132
Related: #118526

MODIFY SETTING name = DEFAULT resets the setting, but the reset was carried inside a MODIFY_SETTING alter command. Every engine-side check is keyed on RESET_SETTING, or inspects only settings_changes when the type is MODIFY_SETTING, so none of them saw it: TimeSeries let an immutable setting be dropped and the table became unwritable, Memory dropped a setting from the stored definition while the running table kept enforcing the old value, and MergeTree accepted a setting name that does not exist.

The reset is now taken out of the MODIFY_SETTING command by the parsers, in ParserAlterCommandList and in ASTAlterQuery::readJSON: a command which only resets becomes RESET_SETTING, and one which also changes settings is split into a MODIFY_SETTING and a RESET_SETTING. The same holds for MODIFY COLUMN ... MODIFY SETTING, and a = DEFAULT written in the SETTINGS (...) clause of a column declaration is no longer ignored. All the existing checks then apply unchanged, including ones added later, and AlterCommand::parse throws a LOGICAL_ERROR when a command still carries the modify syntax of a reset, so a parser cannot skip the rewrite unnoticed.

A command which modifies and resets the same setting keeps its error. ALTER DATABASE ... MODIFY SETTING name = DEFAULT is rejected, because a database engine applies only the changes and has no reset. Resetting a MergeTree setting rebuilds the metadata derived from the settings, such as the implicit minmax indices, which only MODIFY SETTING did before. ReplicatedMergeTree rejects a reset of table_readonly the same way it rejects setting it.

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 ALTER TABLE ... MODIFY SETTING name = DEFAULT skipping the checks an engine makes on a setting reset: TimeSeries allowed an immutable setting to be dropped, leaving the table unwritable, Memory removed a setting from the table definition while the table kept enforcing the old value, and MergeTree accepted a name which is not a setting.


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

Version info

  • Merged into: 26.10.1.388-master (included in 26.10 and later)
  • Backported to: 26.9.2.3

The parser keeps `name = DEFAULT` entries apart from the changes, and
`AlterCommand::parse` stored them in `settings_resets` of a command whose
type stayed `MODIFY_SETTING`. Every engine-side check is keyed on
`RESET_SETTING`, or inspects only `settings_changes` for `MODIFY_SETTING`,
so none of them saw the reset: `TimeSeries` let an immutable setting be
dropped and the table became unwritable, `Memory` dropped a setting from the
stored definition while the running table kept enforcing the old value, and
`MergeTree` accepted a setting name that does not exist.

Move the resets out of the `MODIFY_SETTING` command instead: a command that
only resets becomes `RESET_SETTING`, and one that also changes settings is
split into a `MODIFY_SETTING` and a `RESET_SETTING`. All the existing checks
then apply unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Algunenano
Algunenano requested a review from vitlibar September 11, 2026 15:10
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [dcfbbf7]

Summary: ❌

job_name test_name status info comment
Performance Comparison (arm_release, master_head, 1/6) FAIL Performance dashboard
order_by_read_in_order #1 FAIL dashboard IGNORED

AI Review

Summary

This PR makes ALTER ... MODIFY SETTING name = DEFAULT flow through the engine reset paths by splitting the reset out of MODIFY_SETTING, extends that handling to column/database/JSON-dialect cases, and rebuilds MergeTree's settings-derived metadata after resets. The main execution path is much closer to correct now, but one stale-metadata replay path is still left behind in mutation planning, so I do not think the PR is ready to merge yet.

Findings

⚠️ Majors

  • [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/119475#discussion_r4061548896] [src/Storages/MergeTree/MergeTreeData.cpp:5495-5497, src/Storages/AlterCommands.cpp:1721-1729, src/Storages/AlterCommands.cpp:999-1011] checkAlterEligibility now replays the ALTER with settings_defaults, but AlterCommand::tryConvertToMutationCommand still applies non-mutating commands to the planning snapshot without them. A reset that should drop implicit minmax indices therefore leaves those implicit indices visible to later commands in the same ALTER. On a table created with SETTINGS add_minmax_index_for_numeric_columns = 1, ALTER TABLE ... MODIFY SETTING add_minmax_index_for_numeric_columns = DEFAULT, ADD INDEX auto_minmax_index__a a TYPE minmax GRANULARITY 1 should succeed after the reset removes the implicit auto_minmax_index__a, but planning still sees that index and rejects the later ADD INDEX as duplicate / reserved before execution. The same settings_defaults threading needs to reach the metadata replay in tryConvertToMutationCommand, and the regression test should combine a reset with a later command that inspects secondary_indices, not just DROP INDEX IF EXISTS.
Tests
  • The new tests cover engine-side reset checks, the ReplicatedMergeTree table_readonly guard, JSON AST input, and the S3Queue compatibility-name ordering fix, but they do not exercise the mutation-planning replay path that still uses stale settings-derived metadata.
Final Verdict

Changes requested.

LLVM Coverage Report

Measured on commit dcfbbf7.

Metric Baseline Current Δ
Lines 88.00% 88.00% +0.00%
Functions 91.80% 91.70% -0.10%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 96/97 (98.97%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 11, 2026
Comment thread src/Storages/AlterCommands.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). label Sep 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing dcfbbf755 with master 608ee281e (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of b48ea161d; 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

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

Job report

@vitlibar vitlibar self-assigned this Sep 14, 2026
`MODIFY SETTING table_readonly = DEFAULT` now becomes a `RESET_SETTING` command, which the
engine guard did not inspect, so the setting could be reset silently. Check `settings_resets`
too, which also covers plain `RESET SETTING table_readonly`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread src/Storages/AlterCommands.cpp Resolved
Moving a `MODIFY SETTING name = DEFAULT` onto a `RESET_SETTING` command lost the rebuild of the
implicit minmax indices, which only the `MODIFY_SETTING` branch performed. Both branches now call
one helper, seeded from the engine's config defaults so that a setting dropped from the definition
falls back to the configured value rather than the compiled one.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 queries analysed

Release-transition baseline: compared against the most recent available 26.9 masters at or before the trusted base-commit anchor because no 26.10 master baseline exists there.

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 452565ff-0eb6-4f32-b66d-93479487051c
  • MIRAI run: 066b3104-8d95-4f8f-aa77-a129e8b319a0
  • PR check IDs:
    • clickbench_1204826_1790010619
    • clickbench_1204839_1790010619
    • clickbench_1204845_1790010619
    • tpch_adapted_1_official_1204856_1790010619
    • tpch_adapted_1_official_1204882_1790010619
    • tpch_adapted_1_official_1204896_1790010619

alexey-milovidov and others added 2 commits September 19, 2026 18:02
Both parsers (`ParserAlterCommandList` and `ASTAlterQuery::readJSON`) now turn the entry into a
`RESET SETTING` command, splitting the command in two when it changes other settings as well, so
engines see the command type they key their checks on. `AlterCommand::parse` keeps the check for a
contradictory command and throws a `LOGICAL_ERROR` when a parser leaves the modify syntax behind.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Algunenano Algunenano added v26.9-must-backport pr-bugfix Pull request with bugfix, not backported by default and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Sep 21, 2026
Comment thread src/Parsers/ASTAlterQuery.cpp Resolved
removeImplicitStatistics(new_metadata.columns);
commands.apply(new_metadata, local_context, share_nested_offsets);
auto settings_defaults = getDefaultSettings();
commands.apply(new_metadata, local_context, share_nested_offsets, settings_defaults.get());

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.

Threading settings_defaults into the main commands.apply() path fixes the final metadata, but the mutation-planning path still replays earlier non-mutating setting alters without it.

checkAlterEligibility() calls getMutationCommands() before this, and AlterCommand::tryConvertToMutationCommand() still does apply(metadata, ...) with a null settings_defaults. That means mixed ALTERs still plan against stale implicit-index state. For example,

ALTER TABLE t
    MODIFY SETTING enable_block_number_column = DEFAULT,
    DROP INDEX IF EXISTS auto_minmax_index__block_number

still produces a DROP INDEX mutation (and can be rejected by allow_non_metadata_alters = 0) even though the real commands.apply() path has already removed that implicit index after the reset.

getMutationCommands() / tryConvertToMutationCommand() need the same defaults threading as the real apply path.

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.

🕵 The code observation is right, but the symptom does not reproduce: the DROP INDEX mutation here never depends on the replayed metadata.

getMutationStageDecision sets requires_mutation = true for DROP_INDEX unconditionally, and AlterCommands::prepare sets ignore only for a missing column, never for DROP INDEX IF EXISTS. So the mutation is planned whether or not the implicit index is still present in the metadata the planning replays:

CREATE TABLE di (a UInt64) ENGINE = MergeTree ORDER BY a;
ALTER TABLE di DROP INDEX IF EXISTS never_existed; -- one mutation, no settings command involved

That produces one mutation both on this branch and on a pre-branch master binary. The same holds for the example above: (MODIFY SETTING enable_block_number_column = DEFAULT), (DROP INDEX IF EXISTS auto_minmax_index__block_number) plans the DROP INDEX mutation with and without settings_defaults threaded into getMutationCommands, and allow_non_metadata_alters = 0 rejects it in both cases, so the threading changes nothing observable.

I also went looking for a planning decision which does read the settings-derived metadata: getMutationStageDecision only inspects metadata.columns and the TTL definitions, and the metadata getMutationCommands replays into is a by-value copy used solely for planning, while the metadata that gets stored comes from the real commands.apply which is given the defaults. Since I could not construct a case where the missing defaults change an outcome, I am leaving the mutation-planning path untouched instead of adding threading this change does not need, the more so as it is meant to be backported.

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.

On a table created with SETTINGS add_minmax_index_for_numeric_columns = 1, ALTER TABLE ... MODIFY SETTING add_minmax_index_for_numeric_columns = DEFAULT, ADD INDEX auto_minmax_index__a a TYPE minmax GRANULARITY 1 should succeed after the reset removes the implicit auto_minmax_index__a, but planning still sees that index and rejects the later ADD INDEX as duplicate / reserved before execution. The same settings_defaults threading needs to reach the metadata replay in tryConvertToMutationCommand, and the regression test should combine a reset with a later command that inspects secondary_indices, not just DROP INDEX IF EXISTS.

add_minmax_index_for_numeric_columns cannot be modified as of today (and has never been)

Algunenano and others added 2 commits September 21, 2026 12:54
Rewriting the entry in the parsers dropped the check for a setting which is both modified and reset
in one command: resolving the aliases of a setting needs the storage settings, which a parser cannot
reach, so the contradiction was split into two commands and silently accepted. The split goes back
to `InterpreterAlterQuery`, which both query paths pass through, as the added test shows.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
An engine which maps a compatibility name of a setting onto its canonical one, such as the
`s3queue_` prefix of `ObjectStorageQueue`, can have the change and the reset of one command land on
the same setting. A single command applies its resets first, so the change wins; the split command
has to keep that order.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Merged via the queue into ClickHouse:master with commit f16ef19 Sep 21, 2026
175 of 177 checks passed
@Algunenano
Algunenano deleted the modify-setting-default-engine-guards branch September 21, 2026 22:07
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 21, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 21, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 22, 2026
Backport #119475 to 26.9: Represent `ALTER ... MODIFY SETTING name = DEFAULT` as a reset
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 25, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). 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-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.9-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MODIFY SETTING x = DEFAULT reset bypasses every RESET_SETTING engine guard

5 participants