Skip to content

Reject a column SETTINGS name that is not a column-level setting - #121663

Open
groeneai wants to merge 9 commits into
ClickHouse:masterfrom
groeneai:groeneai/reject-unknown-column-setting-name
Open

groeneai wants to merge 9 commits into
ClickHouse:masterfrom
groeneai:groeneai/reject-unknown-column-setting-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):

A column-level SETTINGS (...) clause, in CREATE, a full-definition ATTACH and ALTER, now rejects a name that is not a column-level setting when it is spelled name = DEFAULT or param_name = value, and in MODIFY COLUMN ... RESET SETTING name, as the ordinary name = value spelling already did. Such a name used to be accepted and silently dropped, leaving a typo unapplied with no diagnostic. min_compress_block_size and max_compress_block_size are the only names settable per column.

Description

Related: #121202. Requested in #121394 (comment); database and dictionary SETTINGS follow as separate PRs.

Root cause. A column SETTINGS clause is one ASTSetQuery with three payloads: changes, default_settings (name = DEFAULT) and query_parameters (param_name = value). Only changes reached MergeTreeColumnSettings::validate, the sole name check; RESET SETTING names, and since #119475 the = DEFAULT reset on MODIFY COLUMN, land in settings_resets, which nothing checked either.

Change. validateName owns the allowed set and the message; validateNames applies it to the two unseen payloads. CREATE screens the clause AST, a TimeSeries table's INNER COLUMNS included, before formatColumns discards them; ALTER carries the names it does not act on into the command and checks them in AlterCommand::apply, and a subcolumn CODEC change refuses them like any other SETTINGS.

Not screened. An ignored ADD COLUMN IF NOT EXISTS or MODIFY COLUMN IF EXISTS, already a no-op; a replay (isReplayedTableDefinition at CREATE, isSecondaryDDLReplay or a recovery at ALTER) and the internal create of a hidden inner table, which would refuse a definition already judged; and a structure string, as in CREATE TABLE ... AS <table function>: it is stored verbatim with no replay signal, so screening it would break existing views that hold one.

Compatibility. No existing table is affected. Only changes reach stored metadata, except in a TimeSeries INNER COLUMNS clause, kept verbatim; its inner tables are created internally and not screened, so a backup of one restores. A full-definition ATTACH is screened, a short one is a replay. Checked by loading a data directory and restoring a backup written by the unpatched binary.

Validation. Three new stateless tests, 20 runs each under randomization; on both binaries, 15 previously-accepted statements are now refused and 10 acceptance controls still pass.


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

A column-level `SETTINGS (...)` clause is one `ASTSetQuery` with three payloads:
`changes` (`name = value`), `default_settings` (`name = DEFAULT`) and
`query_parameters` (`param_name = ...`, prefix stripped). Every consumer of a
column-level clause forwarded only `changes` to the single name check
`MergeTreeColumnSettings::validate`, so the other two names were already gone by
the time it ran, and the names in `settings_resets` (`RESET SETTING`, and since
ClickHouse#119475 the `= DEFAULT` reset) were never checked at all. A name that is not a
column-level setting was therefore accepted and silently dropped in every
spelling but the ordinary one, so a typo left the setting unapplied with no
diagnostic. Only `min_compress_block_size` and `max_compress_block_size` are
settable per column.

One `validateName` now owns the allowed set and the message, and `validateNames`
runs it over the two payloads `validate` never sees. `CREATE`/`ATTACH` screens
the clause AST in `getTablePropertiesAndNormalizeCreateQuery`, after
`getColumnsDescription` so a bogus `changes` name still reports first, and before
`formatColumns` replaces the column list and throws those payloads away. The
`ALTER` sites convert the names they do not act on into a validation-only
`AlterCommand` member at parse time and check them in `AlterCommand::apply`, on
the same lines as the existing `validate(settings_changes)` calls, so every
spelling is gated exactly as the ordinary one is. The same rewrite drops
`validate`'s unused `static const MergeTreeSettings merge_tree_settings;` local,
which was the receiver for a `checkCanSet` call that has since become
static-qualified.

Two things are deliberately left unscreened. An `ALTER` command that does not
take effect (an ignored `ADD COLUMN IF NOT EXISTS`, a skipped
`MODIFY COLUMN IF EXISTS`) is not screened in any payload, because the ordinary
spelling is already a no-op there; that is why the check sits in `apply` rather
than in `AlterCommand::parse`. A node re-executing a definition another node
already judged is not screened either: an `ALTER` is enqueued verbatim, so a
statement an older initiator accepted survives in the queue, and a newer
secondary refusing it would retry that entry forever. The guard is master's own
three replay terms from `checkStorageSettingNames`, extracted next to their
sibling `isFreshTableDefinition` as `isReplayOfJudgedDefinition`;
`checkStorageSettingNames` itself is left calling them inline, to keep this
change off the lines ClickHouse#121394 edits. `ADD COLUMN` also keeps its plain `.changes`
assignment rather than reusing `parseSettingsChangesAndResets`, whose
`BAD_ARGUMENTS` throws would be new parse-time rejections for clauses it accepts
today, and a parse-time throw fires on a secondary before `apply` can exempt it.
So this change adds no parse-time throw.

`ENGINE = TimeSeries` is a third case, and the new rows pin it as parity rather
than as coverage. `normalizeTimeSeriesDefinition` regenerates the outer column
list from resolved types and replaces it wholesale, long before this screening
runs, so a column clause is discarded there whatever the spelling, along with
that column's type, codec, TTL and comment. Screening the original declarations
would reject the exotic spellings on that one engine while the ordinary one
stayed accepted, which is the asymmetry this change exists to remove; measured,
that is exactly what moving the check ahead of normalization does.

No grandfathering marker is needed. The creator keeps only `changes` and
`setProperties` then rewrites the column list with `formatColumns`, so neither
exotic payload can be in stored metadata: a table created with
`SETTINGS (min_compress_block_size = 100, not_a_setting = DEFAULT, param_bogus = 1)`
by a binary without this change stores only `min_compress_block_size = 100`, and
a binary with it loads that data directory unchanged and keeps the setting. A
full-definition `ATTACH TABLE t UUID '...' (...)` states its settings itself and
is screened; the short form is a replay and is not.

Related: ClickHouse#121202

Co-Authored-By: Claude Opus 5 <[email protected]>
@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; 5 gate findings across three rounds, plus
9 from my own cold reviews; bounded: a full pass on the first head, two fix rounds, and a delta recheck of
each). This branch is a single amended commit, so the fixes below are not separately addressable by sha.

# Sev Finding Verdict Evidence / action
1 ❌ On ENGINE = TimeSeries a column SETTINGS clause is still discarded before the new check, so an unknown name is not rejected there AGREE on the fact, fixed; remedy re-prescribed normalizeTimeSeriesDefinition regenerates the outer column list from resolved types and replaces it wholesale, because those columns "are designed to work as IO interface. They store no data". I did not extend the check: the ordinary name = value spelling is equally unscreened there on both binaries (a TimeSeries column keeping a valid min_compress_block_size = 100 also loses the clause), and this PR promises parity with that spelling, so screening TimeSeries would make the exotic spellings stricter than the ordinary one on a single engine. The type, codec, TTL and comment of such a column are regenerated away by the same statement. What I did fix is the claim: the test comment said the rule does not depend on the engine, which is false, and it now names the exception, with three parity rows asserting that all three spellings stay accepted there and that the clause is dropped rather than stored
2 ❌ A JSON AST MODIFY_COLUMN can carry remove_property: "SETTINGS" alongside col_decl.settings, a combination SQL cannot express, and the recorded names then never reach the new check DISAGREE The mechanism is real and I confirmed all of it, but the pre-existing ordinary-spelling validate(settings_changes) sits inside the very branch that RemoveProperty::SETTINGS skips, and that is already true on master: at this PR's base, AlterCommands.cpp:877-880 is the removal arm, the else opens at :881, and that call is at :912 inside it. So the ordinary spelling is equally unscreened on this carrier today, and the changelog entry promises exactly parity with it. REMOVE SETTINGS also clears the column's settings, so a nested payload is discarded by the user's own request and nothing is silently lost. Validating only the new names would make the exotic spellings stricter than the ordinary one on one more carrier; validating both would change the ordinary carrier's behaviour, which is a separate incompatible change. The guard that permits the combination is in ASTAlterQuery.cpp, untouched here
3 ⚠️ The replay exemption's false branch is untested: both tests run on an Atomic database, so nothing shows that an initiator holding a live metadata transaction still rejects AGREE, fixed Added 05237_column_settings_unknown_name_replicated.sh, the column-clause analogue of the merged 05229_storage_settings_unknown_name_replicated.sh: six rejections on a Replicated database plus an acceptance control. Pinned by a mutation: widening the term to metadata_txn != nullptr fails the new test and leaves the other three green
4 ⚠️ MergeTreeColumnSettings::validate carries a static const MergeTreeSettings it never reads AGREE, fixed Deleted. 4ff4b0a84bccd added it as the receiver for merge_tree_settings.checkCanSet(...); the call later became the static MergeTreeSettingsImpl::checkCanSet(...), so it had no remaining use
5 ⚠️ isReplayOfJudgedDefinition duplicates the same three replay terms that checkStorageSettingNames already spells out inline; give the invariant one owner DISAGREE The terms are equal only at this instant. #121394 edits that exact if and adds a fourth term to it, isStorageSettingsFromStoredMetadata(), which marks stored storage settings and has no column-clause equivalent, so the two predicates diverge by design as soon as it lands. Collapsing them today would conflict with a PR already under review and make the shared helper wrong next week. The PR body states this, so it can be checked against that diff
6 ⚠️ A table-function structure string still accepts the two exotic payloads DISAGREE Screening it would break existing definitions: parseColumnsListFromString takes no LoadingStrictnessLevel and hardcodes CREATE, so it has no replay signal, and a structure argument is a string literal kept verbatim in stored metadata, unlike a column list that formatColumns rewrites. A view created today over s3(..., 'x UInt64 SETTINGS (bogus = DEFAULT)') would start throwing on every query. The two settable names are MergeTree part-writer settings and have no effect on a table function in any spelling
7 💡 The short-ATTACH test label claims more than its assertion discriminates DISAGREE True of the path, but a stored definition holds the name in changes, which the new check does not read, so the assertion holds either way. It is a sound detach and attach round-trip control, and the label is echoed into the .reference
8 💡 On a Replicated database an ALTER mixing a valid change with a bogus exotic name is refused by the initiator but applied by a secondary, so metadata can diverge until recovery re-syncs DISAGREE Noted, not blocking. This is the shape the merged checkStorageSettingNames already ships for its own site, and the only alternative, validating on secondaries too, turns an older initiator's queue entry into a permanent retry loop
9 💡 Three test-hygiene nits from my own last pass: one missing defensive DROP TABLE IF EXISTS, and two assertions that match an error class or an unanchored substring rather than the offending name AGREE, noted, not changed None is observable: each test runs in a fresh database, and a run of both shell tests against the unpatched binary produces none of the rejection lines, so every assertion is live. I left the two shell tests line-for-line with the merged 05228 and 05229 they are modelled on rather than diverging for no present gain

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal
per finding. Findings on hunks unchanged by a fix round are auto-dropped.

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

@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [12d7958]

Summary: ✅


AI Review

Summary

The change rejects unsupported column-level SETTINGS names in CREATE, full-definition ATTACH, and effective ALTER commands, including reset and query-parameter spellings, while preserving metadata replay compatibility. Reviewed head 12d795891e91b487dda36f133eee1527f9dd5c44 and all prior discussion; no actionable findings remain.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 12d795891 with master 8930b7fa5 (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

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

Job report

@PedroTadim PedroTadim self-assigned this Sep 23, 2026
Review ask: reduce the volume, not the breadth. One row now covers each
validation site and payload spelling once; rows that only repeated another
file's coverage on a second database or engine flavour are gone, as are the
section labels that were echoed into the reference files. 237 added test
lines become 142.

The Replicated-database arm no longer needs a shell test. Its full-definition
`ATTACH` row was the only statement that needed a shell-generated UUID, and
that path is already covered on the Atomic database by the JSON/ATTACH test,
so the arm is now a `.sql` test stating its expectations with
`{ serverError UNKNOWN_SETTING }`, in the shape of
`03224_invalid_alter.sql`. It keeps what only a Replicated database can show:
that the initiator judges its own definition although it holds a metadata
transaction, at both the `CREATE` and the `ALTER` site.

Kept: all three payload spellings at each of the five validation sites, the
ordinary spelling that master already rejected as a control, all three reset
spellings, the short-`ATTACH` replay exemption, the `TimeSeries`
normalization case, and both payload fields of the JSON AST dialect.

Measured on a debug build of this branch and on a master build without the
change: the three tests pass with it and fail without it, the replicated one
on both of its refusal rows.

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

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 46852d5

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
Performance Comparison (arm_release, master_head, 2/6) / read_in_reverse_order_final #0, #1 dashboard confirmed_regression, client_time +70.0% and +30.9%. The fixture creates its ReplacingMergeTree with no column SETTINGS, so the validation this PR adds runs once at CREATE and never in the measured FINAL queries. On master both queries went from 2-3 ms to 8-9 ms at the merge commit of #122073 (302e001eeb33), which stopped background merges during the measured runs a fix task is created (investigating at full effort, fixing-PR link to follow here)
Performance Comparison (arm_release, master_head, 4/6) / formats_columns_nullable #1 dashboard confirmed_regression, client_time 0.0083 -> 0.0126 (+50.3%). The fixture reads File(<format>) tables without column SETTINGS, and the query was flagged slower or unstable on 44 PRs and 9 master runs in the last 7 days ClickHouse/performance-comparison#5 (external): the dashboard's confidence scoring, where @ fm4v handles these verdicts. That repository is not publicly readable, so its state cannot be measured from here
Mergeable Check, PR rollup rows, red only because of the two shards above ClickHouse/performance-comparison#5 (external) and a fix task is created, the same owners as the two rows above

All 173 check runs completed, and Finish Workflow and CH Inc sync are green on this head.

Session id: cron:our-pr-ci-monitor:20260925-203211

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the read_in_reverse_order_final Performance Comparison rows created: #122335

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - aafc37e

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
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05210_lightweight_update_materialized_cte_in_ignore flaky, not from this PR: a replica fails with UNKNOWN_TABLE on the _materialized_cte_c_* temporary table (#112642); 86/86 reruns with the same settings passed. Same failure on 37 master runs and 205 other PRs since 2026-10-08. The fix merged after this run started #123121 (mine, merged)
Mergeable Check, PR praktika rollups of the row above #123121 (mine, merged)

The NOT_FAILED rows (blacklisted tests that passed) do not fail their jobs. CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261013-230005

@PedroTadim

PedroTadim commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

🕵️ @groeneai

Thanks for trimming the tests. The checks look right to me, and since neither payload can reach stored metadata, this one has no upgrade exposure.

Two small things:

  1. The bot's point about CREATE ... AS <table function> and other structure strings has no reply on its thread. Your reason for leaving it (a structure string is stored verbatim and has no replay signal, so screening it would break existing views) is sound, but please answer it there and add it to "Not screened" in the description.
  2. isReplayOfJudgedDefinition copies the body of isSecondaryDDLReplay (DDLTask.cpp), including the Cloud block. It could be isSecondaryDDLReplay(context) || context->isRecoveryFromStoredMetadata(), which also avoids the new Interpreters includes in LoadingStrictnessLevel.cpp. At the CREATE site the condition is exactly !isReplayedTableDefinition(mode, create, getContext()).

PedroTadim and others added 2 commits November 5, 2026 13:07
The `CREATE` site now uses `isReplayedTableDefinition`, whose terms are
exactly the ones it spelled out. The `ALTER` sites keep a file-local
`isReplayOfJudgedDefinition` that is `isSecondaryDDLReplay` plus a recovery
from stored metadata, instead of a copy of `isSecondaryDDLReplay`'s body
with its Shared Catalog block, so `LoadingStrictnessLevel` is untouched.

No behaviour change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Storages/AlterCommands.cpp Resolved
groeneai and others added 2 commits November 5, 2026 14:57
`MODIFY COLUMN <subcolumn> CODEC(...)` refuses any SETTINGS clause, but
`validateSubcolumnCodecCommand` did not look at `settings_names_to_check`,
so `SETTINGS (param_not_a_setting = 1)` passed the guard, and the subcolumn
branch of `apply` returns before that name is checked: the codec was applied
and the name dropped. Now it is refused like the other spellings, except on a
replay, where an initiator without this check may have accepted it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A TimeSeries table keeps its `INNER COLUMNS` declarations verbatim in its
own definition and creates each inner table through an internal
`InterpreterCreateQuery` in `CREATE` mode, also on `RESTORE`. The column
SETTINGS name check ran in those internal creates, so a backup of such a
table written by an unpatched server failed to restore with
`UNKNOWN_SETTING`, and a fresh `CREATE` was refused only after the first
inner tables had been created.

The check now skips internal creates and screens the inner column lists of
the parent instead, so a fresh `CREATE` is refused before any inner table
exists and a restore is judged as a replay, like the parent.

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

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, both done:

  1. Answered in the bot thread (Reject a column SETTINGS name that is not a column-level setting #121663 (comment)), and structure strings are listed under "Not screened".
  2. 2cd8024: the CREATE site is !isReplayedTableDefinition(mode, create, getContext()), and isReplayOfJudgedDefinition is now a file-local isSecondaryDDLReplay(context) || context->isRecoveryFromStoredMetadata() in AlterCommands.cpp, so LoadingStrictnessLevel is untouched.

Re-checking against the merged master turned up two more cases, fixed in the same push:

  • 96060ca: with subcolumn codecs, MODIFY COLUMN p.a CODEC(ZSTD) SETTINGS (param_x = 1) applied the codec and dropped the name, while every other spelling is refused there. It is refused now, except on a replay.
  • ebf1a87: the "no upgrade exposure" point rests on a line in my description that was wrong for TimeSeries. A TimeSeries table keeps its INNER COLUMNS verbatim, and its inner tables are created by an internal CREATE that also runs on RESTORE, so a backup of TAGS INNER COLUMNS (id UUID SETTINGS (not_a_setting = DEFAULT)) taken on master failed to restore with UNKNOWN_SETTING. The check now screens INNER COLUMNS at the parent and skips internal creates: that backup restores again, and a fresh CREATE is refused before any inner table exists. The Compatibility paragraph is corrected.

@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - ebf1a87

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
AST fuzzer (amd_debug) / Logical error: 'Inconsistent AST formatting: the query:' (STID: 1941-1bfa) logical error in the AST formatter, not from this PR (it changes column SETTINGS validation only): the fuzzed query has a {2..3} glob inside a back-quoted part of a compound function name, the formatter splits that part on its dots into an empty part, and the result does not parse back. The fix merged after this run's base 3822703ab6b6 was taken #129405 (mine, merged)
Mergeable Check, PR praktika rollups of the row above #129405 (mine, merged)

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261105-220009

@clickhouse-gh clickhouse-gh Bot added comp-ddl DDL command coordination and execution (ON CLUSTER, DDL queue). and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 19, 2026

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