Skip to content

Fix ALTER TABLE ... MODIFY SETTING name = DEFAULT being ignored - #118526

Merged
vitlibar merged 2 commits into
ClickHouse:masterfrom
vitlibar:fix-alter-modify-setting-default
Sep 9, 2026
Merged

vitlibar merged 2 commits into
ClickHouse:masterfrom
vitlibar:fix-alter-modify-setting-default

Conversation

@vitlibar

@vitlibar vitlibar commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

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 being ignored
Closes #49613


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

Version info

  • Merged into: 26.9.1.1091 (included in 26.9 and later)

@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d68acf4]

Summary: ✅


AI Review

Summary

This PR teaches table-level ALTER TABLE ... MODIFY SETTING ... = DEFAULT to populate settings_resets, and the new stateless test covers one MergeTree metadata case. The implementation is still incomplete: an already-default reset on tables without a SETTINGS clause still becomes invalid metadata, and several existing storage/database apply or validation paths still ignore resets that arrive through MODIFY SETTING, so I would block this as-is.

Findings

❌ Blockers

  • [src/Storages/AlterCommands.cpp:1219-1227, src/Databases/DatabasesCommon.cpp:75-87, 265-266, src/Parsers/ASTCreateQuery.cpp:246-248, src/Parsers/ASTSetQuery.cpp:165-208] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/118526#discussion_r3948718916] MODIFY SETTING name = DEFAULT on a table that never had a SETTINGS clause still manufactures an empty ASTSetQuery. On extended table definitions such as MergeTree, applyMetadataChangesToCreateQuery persists that non-null node, the formatter emits a bare SETTINGS clause, and validateCreateQuery immediately re-parses it. So ALTER TABLE t MODIFY SETTING merge_with_ttl_timeout = DEFAULT on an already-default table is still a parse failure instead of the expected no-op. Suggested fix: drop metadata.settings_changes again when the post-reset/post-modify list is empty.
  • [src/Storages/AlterCommands.cpp:606, src/Storages/StorageTimeSeries.cpp:563-572, src/Storages/MergeTree/MergeTreeData.cpp:5422-5491, src/Storages/StorageReplicatedMergeTree.cpp:6987-6990] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/118526#discussion_r3948718925] The new reset carrier stops at AlterCommand::apply; storage-side guards that dispatch on command.type or command.settings_changes still miss name = DEFAULT. That lets ALTER TABLE ts MODIFY SETTING version = DEFAULT bypass the immutability check and rewrite a pinned TimeSeries schema version, lets UNIQUE KEY MergeTree tables drop storage_policy/disk through MODIFY SETTING ... = DEFAULT, lets codec-valued MergeTree settings re-enter from config defaults without the codec gate, and still bypasses the ReplicatedMergeTree rejection for table_readonly. Suggested fix: normalize MODIFY SETTING ... = DEFAULT into the existing RESET_SETTING path before storage checks, or make every consumer consult settings_resets regardless of command.type.
  • [src/Storages/AlterCommands.h:161-162, src/Storages/StorageMemory.cpp:441-445, 478-483] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/118526#discussion_r3950374382] Memory tables now accept reset-through-modify, but the live engine settings are rebuilt from the old runtime object plus new_metadata.settings_changes->changes only. When a setting is removed by settings_resets, the metadata loses it while memory_settings keeps the old value until restart. A concrete case is ALTER TABLE mem MODIFY SETTING max_rows_to_keep = DEFAULT: the ALTER succeeds, but the retention cap does not actually change. Suggested fix: rebuild MemorySettings from defaults or from the post-apply metadata instead of replaying only positive changes onto the old runtime object.

⚠️ Majors

  • [src/Storages/AlterCommands.cpp:609-614, src/Interpreters/InterpreterAlterQuery.cpp:608-609, src/Databases/DatabaseOnDisk.cpp:956-980, 1028-1053, src/Databases/DataLake/DatabaseDataLake.cpp:1274-1310, src/Databases/PostgreSQL/DatabaseMaterializedPostgreSQL.cpp:216-267] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/118526#discussion_r3948718929] ALTER DATABASE ... MODIFY SETTING name = DEFAULT is still not reset-aware. AlterCommand::parse drops ASTSetQuery::default_settings, InterpreterAlterQuery forwards only settings_changes, and the database engines never see the reset. On Atomic/Ordinary and DataLake, an empty change list can even persist a bare SETTINGS clause when no settings were stored before; on MaterializedPostgreSQL, the reset is silently ignored. Suggested fix: parse MODIFY_DATABASE_SETTING with the same helper and pass both changes and resets into the database alter path.
  • [src/Storages/AlterCommands.cpp:334-340, 856-860] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/118526#discussion_r3950374375] The column sibling is still broken: MODIFY COLUMN ... MODIFY SETTING name = DEFAULT keeps parsing only ASTSetQuery::changes, so settings_resets stays empty even though AlterCommand::apply already has a reset branch for column settings. The new syntax therefore remains a silent no-op for per-column settings. Suggested fix: run the column command_ast->settings_changes through parseSettingsChangesAndResets too.
Final Verdict

Status: ❌ Block
Minimum required actions:

  • Keep the main table path from materializing an empty SETTINGS clause.
  • Make reset-through-modify reach the existing validation/runtime paths for TimeSeries, MergeTree/ReplicatedMergeTree, and Memory.
  • Either narrow the contract explicitly or wire the same = DEFAULT semantics through the existing database and column alter surfaces.

LLVM Coverage Report

Measured on commit d68acf4.

Metric Baseline Current Δ
Lines 88.90% 88.90% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 29/30 (96.67%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 7, 2026
SELECT extract(create_table_query, 'SETTINGS .*') FROM system.tables WHERE database = currentDatabase() AND name = 't_alter_modify_setting_default';

SELECT '-- `MODIFY SETTING name = DEFAULT` removes the setting from the clause';
ALTER TABLE t_alter_modify_setting_default MODIFY SETTING merge_with_ttl_timeout = DEFAULT;

@vitlibar vitlibar Sep 7, 2026 •

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.

Before this PR ALTER TABLE ... MODIFY SETTING ... = DEFAULT didn't work at all.

This line did nothing, so merge_with_ttl_timeout was still equal to a customized value (10) after this line.

Comment thread src/Storages/AlterCommands.cpp Resolved
Comment thread src/Storages/AlterCommands.cpp Resolved
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 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing d68acf4ef with master 8a472967e (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

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, 17 s compile time in total, 7 of them have a recent master baseline.

Job report

@vitlibar
vitlibar force-pushed the fix-alter-modify-setting-default branch from 051fe47 to 34543dc Compare September 7, 2026 13:29
Comment thread src/Storages/AlterCommands.cpp Resolved
Comment thread src/Storages/AlterCommands.h Resolved
@vitlibar

vitlibar commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

@groeneai Investigate CI failures and suggest fixes

@groeneai

groeneai commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

@vitlibar There is exactly one red leaf at 34543dc1, and it is not from your diff: Build profile diff. Everything else you saw was on 051fe472 and is already cleared.

Build profile diff: a CI logs cluster grant, and it is repo-wide

The job aborts before it measures anything:

Code: 497. DB::Exception: ci: Not enough privileges. To execute this query, it's necessary to have
the grant SELECT(date, repo, pull_request_number, commit_sha, check_name, file) ON default.binary_sizes.
(ACCESS_DENIED) (version 26.8.1.84 (official build))

Raised in has_pr_data() (ci/jobs/build_profile_diff_job.py:721) via query() (:232), which converts any query failure into RuntimeError, so main() (:1574) dies.

Not specific to this PR. CIDB on check_name = 'Build profile diff':

window outcome
up to 15:46:34Z success, 582 rows / 93 PRs, zero errors
16:06:39Z to 21:30:50Z error, 112 rows / 104 distinct PRs

One PR (#118618, 20:46:58Z) slipped through after the break. The rows-per-PR ratio corroborates the mechanism: 6 rows per PR while healthy, 1 while broken, because the job dies before emitting its per-file measurements.

Suggested fix: nothing in your tree. The ci user's column-level SELECT on default.binary_sizes needs restoring on the CI logs cluster. No commit touched ci/jobs/build_profile_diff_job.py today (last change efe3e712, 2026-08-31), which points to a cluster-side change rather than anything in the repo. That area is @ Felixoid's (he did the column unification in #115607). Re-running will not clear it: the run on your head is already run_attempt 4.

It is also not gating you. Mergeable Check went green at 21:01:22Z and CH Inc sync is green; the only red commit status is PR, the workflow rollup that this job flips.

The reds on the previous head are resolved

  • 05136_alter_modify_setting_default. At 051fe472 it failed in five flaky-check flavours (each ending in Too many test failures) and in four ordinary stateless jobs. At 34543dc1 it is OK 50/50 in all five flaky checks, so 250 green runs. Narrowing the oracle from extract(create_table_query, 'SETTINGS .*') to extractAll of only the two settings under test is what fixed it, and it is the right shape: the full clause also carries whatever --random-merge-tree-settings injected, so the old form could never have a stable reference.
  • Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) / test_merge_tree_hdfs::test_move_replace_partition_to_another_table. Green at the current head, but a real trunk flake rather than noise: Code: 76. DB::Exception: Unable to open HDFS file: ... error: Parent directory doesn't exist: /clickhouse/ofx. I have a fix open for it in Fix spurious CANNOT_OPEN_FILE when writing to an hdfs disk #118654, so if it reappears on a later head, that is where it is tracked.
  • Finish Workflow / Post Hooks. The rollup of the above; green at 34543dc1.

}

auto & settings_from_storage = metadata.settings_changes->as<ASTSetQuery &>().changes;
resetSettings(settings_from_storage, settings_resets);

@vitlibar vitlibar Sep 8, 2026 •

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 main part of the fix is here - we need to reset settings not only on

ALTER TABLE ... RESET SETTINGS

but also on

ALTER TABLE ... MODIFY SETTINGS ... = DEFAULT

@vitlibar

vitlibar commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

@Algunenano please take a look when you have time

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. I was uncertain if this respected compatibility (I've also been reviewing #116933) and it seems it does it correctly (by removing it).

pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Sep 8, 2026
`HDFSObjectStorage::writeObject` creates the object key's prefix directory
(`hdfsCreateDirectory`) and opens the object (`hdfsOpenFile`) in two separate
NameNode requests, with a `createHDFSFS` connect in between, while
`removeEmptiedParentDirectories` deleted that directory as soon as it became
empty: from `removeObject`, from `WriteBufferFromHDFS::removeFileOnCancel`, and
transitively from `BlobKillerThread::removeBlobsBatch`. Object keys are a
hardcoded `[a-z]{3}/[a-z]{29}`, so two unrelated blobs sharing a prefix
directory is a birthday collision among 17576 buckets rather than an exotic
case. A removal that emptied the directory inside that window made
`hdfsOpenFile` fail `verifyParentDir`, so any write to an `hdfs` disk could
fail with `Code: 76. DB::Exception: Unable to open HDFS file: ... error: Parent
directory doesn't exist`. `REPLACE PARTITION` is where CI saw it, because it is
the one step that writes a new blob per cloned part while the parts it replaced
out are being removed.

The two requests cannot be collapsed into one: libhdfs3's C entry point
hardcodes `createParent = false`
(`contrib/libhdfs3/src/client/Hdfs.cpp:698`), so there is no atomic
create-with-parents to call. And no in-process coordination can help, because
one `hdfs` root is legitimately written and reclaimed by several servers:
`allow_remote_fs_zero_copy_replication` makes multi-server access to a single
root a first-class configuration, and blob removal for such a root runs on any
replica. A bounded retry would only lower the probability, not establish the
invariant. So remove the reclamation and keep the parent-directory creation:
with nothing deleting a prefix directory, a write that has created its parent
can always open its object, in every configuration, with no new state, no lock
and no retry. This also drops one NameNode request per object deletion.

The reclamation was added to keep the NameNode namespace from growing without
bound. For the `hdfs` disk that premise does not hold: keys come from
`createObjectStorageKeyGeneratorByPrefix`, so the retained set saturates at
17576 directories per root and does not grow with data volume, roughly 2.6 MB
of NameNode heap at 150 bytes per inode, and a disk holding many blobs already
has that many live directories. ClickHouse also already retains those
directories forever for `/`-rooted HDFS storages. The one residual cost is that
`listObjects` recurses into retained empty directories, bounded by the same
17576 per root.

Two consequences that are disclosed rather than fixed here. An `hdfs` object
storage with `metadata_type = plain` takes keys from
`MetadataStorageFromPlainObjectStorage` instead, where they are logical paths of
unbounded count and the object storage is the only directory manager, so this
change does leak empty directories there; the `hdfs` disk is itself documented
unsupported (`storing-data.mdx:48`), the combination has no test configuration
anywhere under `tests/`, and I measured it already failing before this change,
at `CREATE TABLE` with `Code: 660. DB::Exception: Cannot get file info for:
.../format_version.txt`, so nothing that works today regresses.
`LocalObjectStorage` has the same create-then-reap shape, but a local root has a
single writing process, so its reclamation can be made safe by coordination; I
have no observed failure of it and left it alone.

`test_no_leftover_directories_after_removal` becomes
`test_prefix_directories_are_not_reclaimed`: it records the set of directories
present and asserts that `TRUNCATE` removes the objects and none of those
directories. `test_no_leftover_directories_after_canceled_write` becomes
`test_no_leftover_files_after_canceled_write`: it keeps every assertion about
files, which is still correct behaviour, and makes the same set comparison
across the canceled insert. Comparing sets rather than counts is what keeps both
specific, since a directory retained by an earlier test in the module cannot
satisfy either assertion. Both fail on a binary that still reclaims, with no
failpoint and no timing: the first is left with an empty directory set, and the
second loses the prefix directory of the `sizes.json` blob that `LogSink`
rewrites upfront on every insert to be able to roll back (`FileChecker::save`
writes a new blob and `replaceFile`s over the old one). The file's one
`time.sleep` poll is gone.

Both of those assertions bite on the `removeObject` site. I measured that the
`removeFileOnCancel` site has no test oracle: a binary with only the
`removeObject` reclamation deleted leaves the whole module green. That site can
only ever reclaim the prefix directory of the file the canceled write itself
created, which is never a member of a set captured before that write, so no
before/after comparison in this test can see it. It is covered by the argument
that a canceled write and a concurrent write can collide on a prefix exactly as
a removal and a write can, not by a test.

Validated with a concurrent write/remove workload on an `hdfs` disk, with the
object-key space temporarily narrowed so the prefix collision is frequent
instead of once per few hundred CI runs: 4 client failures and 10 server-log
occurrences per 640 queries with the reclamation present, 0 with it deleted,
the two arms differing only by that mechanism. Both files were run on both
binaries: `test_log_family_hdfs` is 2 failed / 3 passed before the change and 5
passed after, the two failures being exactly the two adapted tests, and
`test_merge_tree_hdfs` is 7 passed on both, including the
`test_move_replace_partition_to_another_table` that CI reported.
`test_log_family_hdfs --count 20` is 100/100.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118526&sha=051fe4723d3ee9e1f6145a87924182005b690534&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%205%2F6%29
Carrier pull request whose CI produced that report (unrelated to the cause): ClickHouse#118526
Related: ClickHouse#113396

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

groeneai commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

@vitlibar Re-measured 34543dc1 and your new merge commit d68acf4.

34543dc1 has 151 success / 18 skipped check-runs and exactly one failure, Build profile diff, which is not from your diff. Its last real result is still the failing run at 2026-09-07T21:00:34Z. The green you now see on that context and on the PR rollup is a manual status @ alexey-milovidov posted at 2026-09-08T01:29:22Z, described as "overridden: infra failure (CI logs cluster query failed)". Statuses are per commit, so d68acf4 starts without that override.

The infra failure behind it is over. Repo-wide, Build profile diff errored on 140 distinct PRs between 2026-09-07 16:06Z and 23:42Z (exactly one PR got through in that window). On 09-08 it was 14 erroring PRs against 299 clean ones, and today it is 143 PRs with zero errors. So the run on d68acf4 should produce a real verdict rather than needing another override. A small residue still dies in the same place (has_pr_data() raising CI logs cluster query failed), so if that single job is red again, it is still not yours.

The two cross-PR reds from your earlier heads cannot recur on d68acf4, both by ancestry:

The run on d68acf4 started at 08:58Z and is still in flight.

@vitlibar

vitlibar commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

@groeneai Investigate CI failures and suggest fixes

@groeneai

groeneai commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

@vitlibar Both reds on d68acf4 are infrastructure, and neither one ran a line of your code (150 success / 18 skipped / 2 failure; Mergeable Check is red on exactly these two).

Stateless tests (amd_debug, sequential): SeaweedFS crashed at startup, before the first test

Start ClickHouse Server failed after 61 s with setup_seaweedfs.sh exited with code 1, and the job published one CIDB row and zero test results. seaweedfs.log has the reason, one second after launch (viper's internal frames elided):

fatal error: concurrent map read and map write

goroutine 70 [running]:
[...]
github.com/spf13/viper.(*Viper).GetStringMap(0x0?, {0x5436c9c?, 0x58b7c80?})
	/go/pkg/mod/github.com/spf13/[email protected]/viper.go:898 +0x18
github.com/seaweedfs/seaweedfs/weed/storage/backend.LoadConfiguration(0x9481770)
	/github/workspace/weed/storage/backend/backend.go:52 +0x39
github.com/seaweedfs/seaweedfs/weed/command.startMaster(...)
	/github/workspace/weed/command/master.go:183 +0x3f
created by github.com/seaweedfs/seaweedfs/weed/command.runServer in goroutine 1
	/github/workspace/weed/command/server.go:451 +0x1447

weed server starts master, volume, filer and s3 in separate goroutines, and the master one reads the shared viper config map while another writes it. A Go fatal error is unrecoverable, so weed was gone at once, and wait_for_it then polled port 11111 for all 60 of its iterations before giving up. It is not deterministic: the amd_debug, distributed plan, s3 storage, sequential job started 12 s later on the same head and brought the same SeaweedFS up without trouble.

Re-running that one job is the whole fix on your side.

The class-level gap, which is CI plumbing rather than yours: start_seaweedfs launches weed with nohup ... & and drops $!, so wait_for_it cannot tell "not ready yet" from "died at startup" and burns 60 s on a dead process before failing a required check. Keeping the pid and relaunching once or twice would make this a retry instead of a red. Only one occurrence survives in the reports still on S3, so I have not raised it. Your call if you want it.

Integration tests (amd_asan_ubsan, db disk, old analyzer, 3/6): the batch outgrew the 2 h pytest session timeout

1606 passed, 35 skipped, zero test failures, plus the one synthetic row Timeout / ERROR: session-timeout occurred during test execution. Batch 3 carried the most tests of the six on this run (1641 results against 957 to 1335 on its siblings), its pytest session was cut at the 7200 s bound, and the job took 125m37s end to end; the five green batches finished in 103m to 114m.

Capacity, not your diff, and chronic. Over 30 days batch 3/6 timed out on 46 of 11637 trees (0.4%) and 5/6 on 51 of 11522 (0.44%), against 0.10% and 0.11% for the two lightest batches. Runners are slower today, which puts both heavy batches at 2.0%.

The fix is open and approved: #118933 takes this arm from six batches to eight, which moves the heaviest shard from 119.7 to 82 of the 120 available minutes. Until it merges, re-running the batch clears it roughly 98 times out of 100.

@vitlibar
vitlibar added this pull request to the merge queue Sep 9, 2026
Merged via the queue into ClickHouse:master with commit f4b44f1 Sep 9, 2026
343 of 345 checks passed
@vitlibar
vitlibar deleted the fix-alter-modify-setting-default branch September 9, 2026 23:15
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 9, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@vitlibar @Algunenano — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

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-bugfix Pull request with bugfix, not backported by default 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.

ALTER ... MODIFY SETTING ... = DEFAULT does not work

5 participants