Skip to content

Allow COMMENT after all the other column modifiers - #112788

Merged
alexey-milovidov merged 29 commits into
masterfrom
column-comment-any-order
Aug 14, 2026
Merged

alexey-milovidov merged 29 commits into
masterfrom
column-comment-any-order

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

The parser accepted the modifiers of a column declaration in one fixed order only, so COMMENT had to be written before CODEC, STATISTICS, TTL and per-column SETTINGS:

CREATE TABLE t (x UInt64 CODEC(ZSTD) COMMENT 'text') ENGINE = Memory;
-- Code: 62. DB::Exception: Syntax error: failed at position 38 (COMMENT).
-- Expected one of: STATISTICS, TTL, PRIMARY KEY, SETTINGS, ...

while the same declaration with the two modifiers swapped was accepted. There is no ambiguity here, only an accident of how the parser was written, and it is annoying: nothing in the syntax hints that the comment has to go first, and the same is true for ALTER TABLE ... ADD COLUMN / MODIFY COLUMN.

Now the modifiers that follow the type - COMMENT, CODEC, STATISTICS, TTL, COLLATE, PRIMARY KEY and SETTINGS - are parsed in a loop, so they can be written in any order, and each of them at most once. In CREATE TABLE, everything that was accepted before is still accepted, and ASTColumnDeclaration::formatImpl keeps printing the modifiers in the canonical order, so SHOW CREATE TABLE output does not change.

The ALTER surface is made consistent instead of merely permissive. ALTER TABLE ... ADD COLUMN / MODIFY COLUMN applies the declared modifiers - COMMENT, CODEC, STATISTICS, TTL and per-column SETTINGS - and these can now be written in any order. Per-column SETTINGS in ADD COLUMN and a declared STATISTICS in ADD COLUMN / MODIFY COLUMN used to be silently dropped and are now applied (and validated), like in CREATE: ADD COLUMN sets the declared statistics on the new column, and MODIFY COLUMN replaces the explicit statistics of the column. The column-declaration STATISTICS in these ALTER commands honors the allow_statistics setting and requires the same ALTER ADD STATISTICS / ALTER MODIFY STATISTICS access rights, like the dedicated ADD/MODIFY/DROP STATISTICS commands, and is excluded from the comment-only fast path in the distributed DDL routing. It is also gated on engine support (new IStorage::supportsStatistics, true for the MergeTree family): storages that reject the dedicated ADD/DROP/MODIFY STATISTICS commands, such as Memory or Distributed, reject the column-declaration spelling with the same NOT_IMPLEMENTED error instead of accepting it through the generic column alter. StorageAlias forwards supportsStatistics to its target table, and StorageProxy forwards it (together with supportsTTL) to the nested table, so support does not depend on whether the table is addressed directly, through an Alias, or through the lazy-loading proxy of a database with lazy_load_tables = 1. COLLATE and PRIMARY KEY in ADD COLUMN / MODIFY COLUMN now throw an exception instead of being silently ignored: some spellings of them (with a type present) used to parse successfully and do nothing, which was a bug, not a feature - per-column PRIMARY KEY cannot be altered at all.

This also fixes a formatting round-trip: formatImpl prints COLLATE after COMMENT and after TTL, while the parser used to accept COLLATE only immediately after the type or after NULL/NOT NULL, so the formatted result of x String COLLATE utf8_bin COMMENT 'text' did not parse back:

SELECT formatQuery(formatQuery('CREATE TABLE t (a String COLLATE utf8_bin COMMENT \'a comment\') ENGINE = Memory'));
-- before: Code: 62. DB::Exception: Syntax error: failed at position 48 (COLLATE).

Changelog category (leave one):

  • Improvement

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

The modifiers of a column declaration - COMMENT, CODEC, STATISTICS, TTL, COLLATE, PRIMARY KEY and per-column SETTINGS - can now be written in any order in CREATE TABLE, and each of them at most once. Previously only one fixed order was accepted, and, for example, x UInt64 CODEC(ZSTD) COMMENT 'text' was a syntax error. In ALTER TABLE ... ADD COLUMN / MODIFY COLUMN, the supported modifiers - COMMENT, CODEC, STATISTICS, TTL and per-column SETTINGS - can also be written in any order; per-column SETTINGS in ADD COLUMN and a declared STATISTICS in ADD COLUMN / MODIFY COLUMN are now applied instead of being silently dropped, and COLLATE and PRIMARY KEY in these ALTER commands now throw an exception instead of being silently ignored.

The parser accepted the modifiers of a column declaration in one fixed
order only, so `COMMENT` had to be written before `CODEC`, `STATISTICS`,
`TTL` and per-column `SETTINGS`, and

    CREATE TABLE t (x UInt64 CODEC(ZSTD) COMMENT 'text') ENGINE = Memory

was a syntax error, while the same declaration with the two modifiers
swapped was accepted.

Now the modifiers that follow the type - `COMMENT`, `CODEC`,
`STATISTICS`, `TTL`, `COLLATE`, `PRIMARY KEY` and `SETTINGS` - are parsed
in a loop, so they can be written in any order, and each of them at most
once. `ASTColumnDeclaration::formatImpl` keeps printing them in the
canonical order, so `SHOW CREATE TABLE` is unaffected.

This also fixes a formatting round-trip: `formatImpl` prints `COLLATE`
after `COMMENT` and after `TTL`, while the parser used to accept
`COLLATE` only immediately after the type or after `NULL`/`NOT NULL`, so
the formatted result of `x String COLLATE utf8_bin COMMENT 'text'` did
not parse back.
@alexey-milovidov
alexey-milovidov requested a review from a team as a code owner July 31, 2026 18:32
@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [56657a8]

Summary: ✅


AI Review

Summary

This PR makes column-declaration modifiers reorderable and extends the ALTER TABLE ... ADD COLUMN / MODIFY COLUMN path so column-level STATISTICS and per-column SETTINGS are carried through consistently, with matching parser behavior, access checks, engine gating, DDL routing, and nested-column handling. I re-checked the current PR head against the full prior thread history and did not find any remaining correctness, compatibility, or contract issues in the changed surface.

Final Verdict

✅ No new findings on the current PR head.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.00% 79.10% +0.10%

Changed lines: Changed C/C++ lines covered: 158/167 (94.61%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jul 31, 2026
@mintlify

mintlify Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🟢 Ready View Preview Jul 31, 2026, 6:57 PM

Comment thread src/Parsers/ParserCreateQuery.h Resolved
…column declarations

In `ALTER TABLE ... MODIFY COLUMN` without a type, a leading `SETTINGS`,
`STATISTICS` or `COLLATE` was consumed by `ParserDataType` as a type name,
so spellings such as `MODIFY COLUMN c SETTINGS (...) COMMENT 'x'` failed
while `MODIFY COLUMN c COMMENT 'x' SETTINGS (...)` was accepted. Extend
the no-type guard in `IParserColumnDeclaration::parseImpl` and the paired
reserved-keyword list in `ParserDataType::parseImpl`, and add type-less
`MODIFY COLUMN` regressions.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The Stress test (amd_msan) failure — Logical error: Sizes of nested column and null map of Nullable column are not equal after deserialization — is unrelated to this parser-only change: it has been failing across many unrelated PRs (and master) for months per CIDB. It is tracked in #112213 with a fix in progress in #112484.

Comment thread src/Parsers/ParserCreateQuery.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 45/51 (88.24%) · Uncovered code

Full report · Diff report

`AlterCommand::parse` copies only `comment`, `ttl`, `codec` and `settings`
out of `ASTColumnDeclaration`, and `AlterCommand::isCommentAlter` still
classifies the result as a comment-only alter. Exempting `STATISTICS` and
`COLLATE` from the requirement to have a type therefore turned
`ALTER TABLE ... MODIFY COLUMN c STATISTICS(tdigest) COMMENT 'x'` from a
rejected query into one that succeeds while applying only the comment.

Keep both of them out of the type-less exemption list (and out of the
reserved names in `ParserDataType`), so they are read as the type name and
rejected downstream exactly as before. `SETTINGS` stays exempted: it is the
one addition that is actually carried through `AlterCommand`.

Addresses the review finding on
#112788
Comment thread src/Parsers/ParserCreateQuery.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 56657a816 with master 97c3c3cba (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 405e218ff; 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 692.10 MiB 689.10 MiB -3.00 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.

Compile time of recompiled translation units

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

Job report

pull Bot pushed a commit to AKJUS/ClickHouse that referenced this pull request Aug 4, 2026
The check flagged three of its five sections as significant on
ClickHouse#112788 - a change to
`ParserCreateQuery` that cannot affect any of them - and every finding was an
artifact of the comparison:
ClickHouse#112788 (comment)

  * "685 object files removed, -40.18 MiB": the two builds do not have the same
    target set. The master warmup build compiles every object-file target ninja
    knows about, a pull request build only `clickhouse-bundle`, so the gRPC and
    protobuf libraries, the unit tests and the utils exist on the warmup side
    alone. Only the object files the pull request build produced are compared
    now; the baseline-only ones are counted in a footnote (and in the job log)
    instead of read as removals. A PR-only object file stays a real addition -
    the warmup side builds a superset, so it is a source file the PR added.

  * "+17.2 s / +439.45 KiB, new" next to an identical "gone" row: ThinLTO
    renames the clones it creates with a `.llvm.<hash>` suffix whose hash comes
    from the defining module, so two builds of the same source name the same
    clone differently. Both symbols and per-function times are keyed by the
    name with that suffix removed, which also folds the clones of one function
    into a single row.

  * `registerFunctionConversion` +104%, `_GLOBAL__sub_I_TargetLibraryInfo.cpp`
    +77% in `clickhouse-keeper` while `clickhouse`'s untouched functions came
    out 44-54% faster: each binary is its own ThinLTO link, and their
    systematic ratios to the baseline differ by more than a factor of two. The
    skew is now estimated per binary rather than once for both.

The thresholds of the two sections whose baseline is the official master build -
whose flags differ, and whose stripped binary alone drifts by ~3 MiB on a no-op
pull request - are widened to match that noise floor: per-function ThinLTO time
is reported from 5 s and 2x (was 2 s and 1.5x) and significant from 20 s (was
15 s), per-symbol size is reported from 64 KiB and significant from 512 KiB
(was 16 KiB / 256 KiB). The object-file thresholds are left alone: that
comparison is against a build compiled with the pull request's exact flags, so
it is deterministic.

Co-Authored-By: Claude Fable 5 <[email protected]>
…ot apply

Address AI review: `ALTER TABLE ... ADD COLUMN` silently dropped a per-column
`SETTINGS (...)` clause (`AlterCommand::parse` never copied it and `apply` built
the new `ColumnDescription` without it), and both `ADD COLUMN` and `MODIFY COLUMN`
silently dropped `STATISTICS`, `COLLATE` and `PRIMARY KEY` - already on master,
where these spellings (minus the trailing `COMMENT`) parse successfully.

Now `ADD COLUMN` carries per-column `SETTINGS` into the column description
(validated by `MergeTreeColumnSettings::validate`, same as the `MODIFY COLUMN`
path), and `AlterCommand::parse` throws `BAD_ARGUMENTS` / `NOT_IMPLEMENTED` for
`STATISTICS`, `COLLATE` and `PRIMARY KEY` in `ADD COLUMN` / `MODIFY COLUMN`
instead of silently applying only the modifiers it understands.

#112788
Comment thread src/Storages/AlterCommands.cpp Resolved
…order

# Conflicts:
#	docs/en/sql-reference/statements/alter/column.md
#	docs/en/sql-reference/statements/create/table.md
alexey-milovidov and others added 2 commits August 5, 2026 15:17
…ad of rejecting it

Rejecting a column-level STATISTICS clause in ALTER broke the master test
test_statistics_minmax_upgrade, which pins that re-stating a column of an
upgraded table with its pre-existing explicit `minmax` statistics
(`MODIFY COLUMN value Int64 STATISTICS(minmax)`) is accepted. Instead of
returning to silently dropping the clause, transfer it into the column
description like `CREATE` does: `ADD COLUMN` sets the declared statistics on
the new column, `MODIFY COLUMN` replaces the explicit statistics of the
column (implicit statistics from `auto_statistics_types` are re-added by the
storage). `COLLATE` and `PRIMARY KEY` are still rejected because ALTER cannot
apply them.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112788&sha=5bed1f30855ae96d05b2728d789649927e2a4c98&name_0=PR

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 CI analysis for commit 5bed1f3 and the follow-up:

alexey-milovidov and others added 2 commits August 11, 2026 05:18
…ine support

Non-MergeTree storages reject the dedicated `ALTER TABLE ... ADD/DROP/MODIFY STATISTICS`
commands in `checkAlterIsPossible`, but the column-declaration spelling
`ALTER TABLE ... ADD/MODIFY COLUMN c UInt64 STATISTICS(...)` travels as a generic
`ADD_COLUMN`/`MODIFY_COLUMN` command and bypassed those allowlists, so engine support
depended on how the same logical alter was spelled (and on `Distributed`/`Buffer` it
mutated only the local metadata).

Add `IStorage::supportsStatistics` (true for the `MergeTree` family, mirroring
`supportsTTL`) and reject `column_statistics_decl` in `AlterCommands::validate` when
the storage does not support statistics, matching the `NOT_IMPLEMENTED` error of the
dedicated commands.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Triage of the 3 stress-test failures on 8290399 — all unrelated to this PR (parser / ALTER column-declaration surface):

  1. Stress test (arm_asan_ubsan) — report: LeakSanitizer indirect leaks of query contexts (Settings copied in Context::createCopy, here reached via QueryTreeBuilder::buildSelectExpression / StorageMerge::getDatabaseIterator). This exact signature hit 187 stress checks across 139 PRs (including master) since 2026-08-07 18:27 UTC — the same fleet-wide abandoned-context-cycle regression tracked in LeakSanitizer: abandoned reference cycle of DDL query context + ZooKeeper session in stress tests (fleet-wide since 2026-08-07) #113954 (the partial fix Break a Context retain cycle in the DatabaseReplicated digest finalizer #113953 merged on 2026-08-08 did not stop it; latest occurrence 2026-08-11).

  2. Stress test (arm_tsan) — report: ThreadSanitizer data race (STID: 2264-28f8) between ASTLiteral::clone in QueryTreeBuilder::buildQueryTreeNode and the server-side ASTFuzzer thread mutating the same AST. Same STID on unrelated PRs Serialize iceberg metadata log content lazily #110437 (2026-08-05) and Chimp compression for floating point data #66467 (2026-08-03); 5 PRs in 14 days. No tracking issue found.

  3. Stress test (amd_debug) — report: hung check — a server-side fuzzed SELECT stuck in analyzer passes (executeASTFuzzerQueries → buildQueryTreeAndRunPasses), i.e. an uninterruptible CPU-bound analysis of a fuzzed query, same class as Uninterruptible CPU-bound function evaluation over a large value #112203. Stress hung checks hit 714 checks across 380 PRs in the last 14 days.

@groeneai, please investigate item 2 (the ASTFuzzer vs ASTLiteral::clone data race, STID 2264-28f8 — the fuzzer clones/mutates an AST another query thread is reading) and provide a fix in a separate PR; if a fix is already in progress, link it here.

Master has been merged (95e797b), which already pulls in everything merged for item 1.

@groeneai

Copy link
Copy Markdown
Collaborator

Item 2 is already fixed by your own #113563 ("Do not analyze the shared row policy AST in place in Merge"), open since 2026-08-05.

The stack on 8290399 matches it exactly. One correction to the framing: the fuzzer is not the mutating side. Both sides are ordinary query threads, and ASTFuzzer only supplies the concurrent load; the object being mutated is the row policy AST owned by RowPolicyCache, shared by every query that reads the table.

  • write, T2344: ActionsVisitor.cpp:1235 (const_cast<ASTLiteral &>(literal).unique_column_name = ...), reached from ReadFromMerge::RowPolicyData::RowPolicyData at StorageMerge.cpp:1515, which is the line Do not analyze the shared row policy AST in place in Merge #113563 clones.
  • read, T490: ASTLiteral::clone from buildFilterInfo / buildRowPolicyFilterIfNeeded (PlannerJoinTree.cpp:784), i.e. another table under the same policy.

On master StorageMerge.cpp:1515 is still the only consumer of RowPolicyFilter::expression that rewrites it in place: QueryAnalyzer.cpp:5835 and generateFilterActions in InterpreterSelectQuery.cpp clone it, StorageMergeTreeTextIndex.cpp:451 visits it with a const visitor, and ContextAccess.cpp:568 only checks it. So the clone in #113563 is sufficient and I am not opening a second PR that would collide on that one line. STID 2354-2dfa is the same defect seen from the other arm of that if in ActionsVisitor, so #113563 closes both.

#113563 currently has 158 green checks and no reviews, so it only needs a reviewer.

Comment thread src/Storages/AlterCommands.cpp Resolved
The new `IStorage::supportsStatistics` gate in `AlterCommands::validate` is
checked on the storage the `ALTER` is addressed to, and `StorageAlias`
inherited the default `false` while forwarding the alter (and `supportsTTL`)
to its target. So `ALTER TABLE alias_over_mergetree MODIFY COLUMN x UInt64
STATISTICS(tdigest)` was rejected with `NOT_IMPLEMENTED`, even though the
dedicated `MODIFY STATISTICS` spelling reached the target through
`StorageAlias::checkAlterIsPossible`.

Forward `supportsStatistics` to the target table, so support no longer depends
on whether the table is addressed directly or through an `Alias`. The test
`04839_column_declaration_statistics_engine_gate` now covers both directions
through an alias: accepted over `MergeTree`, rejected over `Memory`.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 CI triage of the two stress reds on fefac8e9d3cc (163 other checks green) — both are fleet-wide flakes unrelated to this PR:

  1. Stress test (amd_asan_ubsan) — Logical error: Sizes of nested column and null map of Nullable column are not equal after deserialization (null map size = A, nested column size = B) (STID: 6726-6444). Fleet-wide, and huge: 46 failures across 42 distinct PRs on 2026-08-11 alone, 51/44 on 2026-08-07, spiking since 2026-08-07 (CIDB checks, 7-day window). Tracked in Logical error: Sizes of nested column and null map of Nullable column are not equal after deserialization (null map size = A, nested column size = B) (STID: 6726-6444) #114368.

  2. Stress test (amd_debug) — Logical error: Temporary part A already added (STID: 2148-5754), thrown from the AST-fuzzer OPTIMIZE path (InterpreterOptimizeQuery::execute → MergeTreeData::optimizeDryRun → MergeTask::ExecuteAndFinalizeHorizontalPart::execute). Cross-PR flake: 15 occurrences in the last 21 days, each on a different PR (Fix backup lock file check errors handling #113637, Add a Chinese 🇨🇳 tokenizer (jieba) for the tokens function and text indexes #89945, Support GROUPS frame mode for window functions #108653, Support PromQL date/time functions called without arguments #111869, Enable lazy materialization for ORDER BY ... LIMIT in distributed plans (make_distributed_plan=1) #113111, Added Parquet Shredded VARIANT Support to ParquetReaderv3 #102499, A dummy PR to backport #113089, Fix flaky 04320_query_condition_cache_topk_correctness via deterministic data placement #113011, Serialize iceberg metadata log content lazily #110437, Do not rebuild a parameterized identifier as a resolved table name #112704, Resolve hive partitioning sample path lazily #111842, Parse the HTTP Last-Modified header without strptime #111619, Docs: remove legacy Docusaurus documentation #112141, Fix QCC write by topK query with split AND-chain filters #112083) and across all sanitizers/architectures, so it is not related to the column-declaration parser changes here. The old issue for the same message, Logical error: 'Temporary part tmp_clone_all_64_64_0_70 already added' #86050, was closed as completed on 2026-02-08, so this is a new occurrence of the signature with no open tracking issue.

@groeneai, investigate the failure: https://github.com/ClickHouse/ClickHouse/actions/runs/31462014264/job/93718472531 (Temporary part A already added in the fuzzer OPTIMIZE path) and provide a fix in a separate PR — an issue needs to be created for it too. If a fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

Investigated. A fix is already in progress and it is mine: #110916 (open since 2026-07-17). Issue filed as requested: #114399.

The stack in that job is the one #110916 targets, frame for frame:

5. TemporaryParts.cpp:28:15   DB::TemporaryParts::add
6. MergeTreeData.cpp:3888:21  DB::MergeTreeData::getTemporaryPartDirectoryHolder
8. MergeTask.cpp:587:66       MergeTask::ExecuteAndFinalizeHorizontalPart::prepare
11. MergeTask.h:622:18        DB::MergeTreeData::optimizeDryRun
12. InterpreterOptimizeQuery.cpp:135:26

Failing query: OPTIMIZE TABLE table_for_concurrent_alter DRY RUN PARTS 'all_1_1_0' CLEANUP. query_log on that server has 9 concurrent OPTIMIZE statements against the same table inside the same second, so the dry run overlapped a real merge on the same source parts. optimizeDryRun takes no CurrentlyMergingPartsTagger and no merge lock, so both derive the same tmp_merge_all_1_1_1 name and the second reservation throws. #110916 names the throwaway dry-run directory tmp_merge_dry_run_<uuid> instead. The guard is still absent from master (DRY_RUN_TEMP_INFIX: 0 hits in MergeTask.h on origin/master).

Two corrections to my own triage above, both measured on CIDB default.checks over 30 days, test_name LIKE '%Temporary part%already added%':

  1. The 15-in-21-days population I listed is a different STID bucket. Full window: 17 rows / 17 distinct PRs, 0 on master, first 2026-07-17 20:22:10. Bucket 2148-4dbb holds 16 of them, and 2148-5754 here is a single row. Same defect, two STIDs.
  2. That bucket is not homogeneous. 15 of the 17 throw with optimizeDryRun on the stack; 2 throw from the real merge side of the same collision, so the dry run is the holder rather than the victim: StorageMergeTree::optimize -> MergePlainMergeTreeTask on Added Parquet Shredded VARIANT Support to ParquetReaderv3 #102499, and MergeFromLogEntryTask -> ReplicatedMergeMutateTaskBase on Resolve hive partitioning sample path lazily #111842. CIDB does not record who held the directory, so for those two the holder is inferred, not proven. Fix LOGICAL_ERROR in OPTIMIZE ... DRY RUN racing a concurrent merge #110916's rename fixes both directions if the holder is a dry run; if a case turns out to be merge-versus-merge with no dry run involved, it is a separate defect.

Also for the record: #86050 and #91132 were both closed as completed for this message, #91132 attributed to #91792 (MergePlainMergeTreeTask). Neither covers the optimizeDryRun producer, whose first CI sighting is 2026-07-17, which is why #114399 is a new issue rather than a reopen.

Comment thread src/Storages/AlterCommands.cpp Resolved
alexey-milovidov and others added 2 commits August 12, 2026 21:57
…`StorageProxy`

With `lazy_load_tables = 1`, a re-attached table is a `StorageTableProxy`
wrapping the real storage, and `AlterCommands::validate` checks
`supportsStatistics` (and `supportsTTL`) on the proxy itself, which inherited
the `IStorage` default `false`. So the column-declaration `STATISTICS(...)`
spelling (and a column `TTL`) threw `NOT_IMPLEMENTED` on a lazily loaded
`MergeTree` table while the dedicated `MODIFY STATISTICS` reached the nested
table through the forwarded `checkAlterIsPossible` — support depended on the
database's `lazy_load_tables` setting instead of the storage engine.

Forward both capabilities to the nested storage, mirroring `StorageAlias`.
Both are only queried while validating an ALTER, which materializes the lazy
table anyway. New test `04870_column_declaration_statistics_lazy_load` pins
both spellings through an unloaded proxy, plus the negative control that a
lazily loaded `Memory` table is still rejected.

Co-Authored-By: Claude Fable 5 <[email protected]>

@alexey-milovidov alexey-milovidov left a comment

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.

Great change, and it even improves the code.

@alexey-milovidov alexey-milovidov self-assigned this Aug 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Aug 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 13, 2026
Merged via the queue into master with commit 2aa15ae Aug 14, 2026
181 checks passed
@alexey-milovidov
alexey-milovidov deleted the column-comment-any-order branch August 14, 2026 00:53
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 14, 2026
alexey-milovidov added a commit that referenced this pull request Sep 14, 2026
…ammar

Two statements of the new test assert behaviours that arrived in master with #112788, after the 26.7 branch cut:

- `ALTER TABLE ... MODIFY COLUMN c Int64 STATISTICS(...)` silently drops the column-level `STATISTICS` clause here, so no type validation runs and the expected `INCORRECT_QUERY` is never thrown. The statement is removed; the `ALTER TABLE ... ADD STATISTICS` line keeps the `ALTER` slot covered.
- Column modifiers must be written in the fixed order `COMMENT`, `CODEC`, `STATISTICS`, `TTL` on this branch, so `STATISTICS(tdigest) CODEC(ZSTD(3))` is a syntax error. The `CREATE TABLE ok` line is rewritten with `CODEC` before `STATISTICS`; `ASTColumnDeclaration` already formats it in that order, so the expected output is unchanged.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=119856&sha=03e5c7fd77e86da6abee8ab725a382bd0ffb4cd3&name_0=BackportPR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%29
PR: #119856

Co-Authored-By: Claude Fable 5.1 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Sep 14, 2026
…ammar

The test was written against master and relied on two behaviours from
#112788 that 26.6 does not have: order-agnostic column modifiers (26.6
requires `CODEC` before `STATISTICS`, so `STATISTICS(tdigest) CODEC(ZSTD(3))`
is a syntax error) and the `uniq_v2` statistics type. Column-level
`STATISTICS` inside `ALTER TABLE ... MODIFY COLUMN` is also silently dropped
on 26.6, so the `INCORRECT_QUERY` it asserted there never fires; that line is
removed, as in the 26.3 and 26.7 backports. `auto_statistics_types` now uses
`tdigest, uniq`, which are registered on every release branch.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=119855&sha=6528da4a5f23523b6bf2410036824ea8132a8cc8&name_0=BackportPR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%2C%201%2F2%29
PR: #119855

Co-Authored-By: Claude Fable 5.1 <[email protected]>

This branch was successfully deployed

1 active deployment
staging - docs — 56657a81 Deployed Aug 13, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements 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.

3 participants