Repository navigation
Allow COMMENT after all the other column modifiers - #112788
Conversation
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.
|
Workflow [PR], commit [56657a8] Summary: ✅
AI ReviewSummaryThis PR makes column-declaration modifiers reorderable and extends the Final Verdict✅ No new findings on the current PR head. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 158/167 (94.61%) · Uncovered code |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
…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.
|
🕵 The |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 45/51 (88.24%) · Uncovered code |
`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
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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 units868 translation units recompiled, 7840 s compile time in total, 868 of them have a recent master baseline. |
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
…order # Conflicts: # docs/en/sql-reference/statements/alter/column.md # docs/en/sql-reference/statements/create/table.md
…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]>
|
🕵 CI analysis for commit 5bed1f3 and the follow-up:
|
…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]>
|
🕵 Triage of the 3 stress-test failures on 8290399 — all unrelated to this PR (parser /
@groeneai, please investigate item 2 (the Master has been merged (95e797b), which already pulls in everything merged for item 1. |
|
Item 2 is already fixed by your own #113563 ("Do not analyze the shared row policy AST in place in 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
On master #113563 currently has 158 green checks and no reviews, so it only needs a reviewer. |
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`.
|
🕵 CI triage of the two stress reds on
@groeneai, investigate the failure: https://github.com/ClickHouse/ClickHouse/actions/runs/31462014264/job/93718472531 ( |
|
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: Failing query: Two corrections to my own triage above, both measured on CIDB
Also for the record: #86050 and #91132 were both closed as completed for this message, #91132 attributed to #91792 ( |
…`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
left a comment
There was a problem hiding this comment.
Great change, and it even improves the code.
…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]>
…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]>
The parser accepted the modifiers of a column declaration in one fixed order only, so
COMMENThad to be written beforeCODEC,STATISTICS,TTLand per-columnSETTINGS: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 KEYandSETTINGS- are parsed in a loop, so they can be written in any order, and each of them at most once. InCREATE TABLE, everything that was accepted before is still accepted, andASTColumnDeclaration::formatImplkeeps printing the modifiers in the canonical order, soSHOW CREATE TABLEoutput does not change.The
ALTERsurface is made consistent instead of merely permissive.ALTER TABLE ... ADD COLUMN/MODIFY COLUMNapplies the declared modifiers -COMMENT,CODEC,STATISTICS,TTLand per-columnSETTINGS- and these can now be written in any order. Per-columnSETTINGSinADD COLUMNand a declaredSTATISTICSinADD COLUMN/MODIFY COLUMNused to be silently dropped and are now applied (and validated), like inCREATE:ADD COLUMNsets the declared statistics on the new column, andMODIFY COLUMNreplaces the explicit statistics of the column. The column-declarationSTATISTICSin theseALTERcommands honors theallow_statisticssetting and requires the sameALTER ADD STATISTICS/ALTER MODIFY STATISTICSaccess rights, like the dedicatedADD/MODIFY/DROP STATISTICScommands, and is excluded from the comment-only fast path in the distributed DDL routing. It is also gated on engine support (newIStorage::supportsStatistics, true for theMergeTreefamily): storages that reject the dedicatedADD/DROP/MODIFY STATISTICScommands, such asMemoryorDistributed, reject the column-declaration spelling with the sameNOT_IMPLEMENTEDerror instead of accepting it through the generic column alter.StorageAliasforwardssupportsStatisticsto its target table, andStorageProxyforwards it (together withsupportsTTL) to the nested table, so support does not depend on whether the table is addressed directly, through anAlias, or through the lazy-loading proxy of a database withlazy_load_tables = 1.COLLATEandPRIMARY KEYinADD COLUMN/MODIFY COLUMNnow 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-columnPRIMARY KEYcannot be altered at all.This also fixes a formatting round-trip:
formatImplprintsCOLLATEafterCOMMENTand afterTTL, while the parser used to acceptCOLLATEonly immediately after the type or afterNULL/NOT NULL, so the formatted result ofx String COLLATE utf8_bin COMMENT 'text'did not parse back:Changelog category (leave one):
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 KEYand per-columnSETTINGS- can now be written in any order inCREATE 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. InALTER TABLE ... ADD COLUMN/MODIFY COLUMN, the supported modifiers -COMMENT,CODEC,STATISTICS,TTLand per-columnSETTINGS- can also be written in any order; per-columnSETTINGSinADD COLUMNand a declaredSTATISTICSinADD COLUMN/MODIFY COLUMNare now applied instead of being silently dropped, andCOLLATEandPRIMARY KEYin theseALTERcommands now throw an exception instead of being silently ignored.