Skip to content

Cherry pick #114188 to 26.3: Ignore redundant parentheses in stored table definitions - #114652

Merged
robot-ch-test-poll2 merged 12 commits into
backport/26.3/114188from
cherrypick/26.3/114188
Aug 13, 2026
Merged

robot-ch-test-poll2 merged 12 commits into
backport/26.3/114188from
cherrypick/26.3/114188

Conversation

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

Original pull-request #114188

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

alexey-milovidov and others added 10 commits August 10, 2026 16:55
The definition expressions of a table (keys, `TTL`, indices, projections,
constraints, column defaults) are stored in ZooKeeper as text and compared as
text. #92340 made the AST remember the redundant parentheses the user wrote, so
`PARTITION BY (a)` stopped comparing equal to `PARTITION BY a`, and
`ATTACH`/`REPLACE`/`MOVE PARTITION FROM` and adding a replica started to fail.

Format those definitions with a new `ignore_redundant_parentheses` mode, which
gives back the text every server produced before the parentheses were a part of
the AST. What the user wrote is still stored in the table metadata and still
shown by `SHOW CREATE`; only the comparisons and the Keeper payload became
insensitive to it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ageQueue metadata

The `columns` field of the ObjectStorageQueue metadata in ZooKeeper was
compared with the local serialization verbatim, so a queue table created
by a version that kept the redundant parentheses of the user in a column
`DEFAULT`, `CODEC` or `TTL` expression (26.5-26.7) would fail with
`METADATA_MISMATCH` on a server that does not store them (and the other
way around). When the strings differ, compare the parsed
`ColumnsDescription` structurally, like `StorageKeeperMap` already does.

Co-Authored-By: Claude Fable 5 <[email protected]>
… when reusing a partially created replica

A retry of a partially created replica could find `/metadata` and `/columns` written
by a server version with a different (redundantly parenthesized) spelling of the same
table definition; the raw string comparison in `createReplicaAttempt` then failed with
`REPLICA_ALREADY_EXISTS`. Fall back to structural comparison
(`ReplicatedMergeTreeTableMetadata::checkEquals` / `ColumnsDescription::parse`)
when the texts differ.

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

The test hand-crafts the ZooKeeper nodes of a replica as a 26.5..26.7 server
would have left them after failing between the ZooKeeper transaction and saving
the local metadata: the same definitions, spelled with redundant parentheses.
Retrying `CREATE TABLE` must reuse the empty replica instead of throwing
`REPLICA_ALREADY_EXISTS`.

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

Per review: do not swallow exceptions in `createReplicaAttempt` when comparing the
`metadata` and `columns` of an existing empty replica. A structural mismatch or an
unparseable node now throws (e.g. `METADATA_MISMATCH`), which describes the problem
better than the `REPLICA_ALREADY_EXISTS` of the fall-through create attempt. This
also resolves the style-check finding about silent `catch (...)`.

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

The style check requires shell tests to include it in `ReplicatedMergeTree` paths
to avoid overlaps between concurrent test runs.

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

Ignore redundant parentheses in stored table definitions
@robot-ch-test-poll robot-ch-test-poll added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Aug 13, 2026
…ypick/26.3/114188

Only the part of #114188 that applies to 26.3 is taken.

The `parenthesized` flag of `IAST` was introduced by #92340 in 26.5, so 26.3
never writes a table definition with the redundant parentheses the user has
written, and the bug the pull request fixes cannot happen here. Everything
built on `IAST::FormatSettings::ignore_redundant_parentheses` -
`IAST::formatIgnoringRedundantParentheses` and all of its call sites - would
be dead code on this branch, and the tests
`04836_parenthesized_definitions_attach_partition_from` and
`04837_parenthesized_definitions_replicated_metadata` assert that `SHOW CREATE`
prints the parentheses back, which is 26.5 and later behavior. Those are left out.

What is taken are the two places that have to accept a definition stored by
26.5..26.7, which 26.3 needs in order to read such a table at all:

- `ObjectStorageQueueTableMetadata::checkImmutableFieldsEquals` compares the
  `columns` payload structurally when the stored and the local text differ,
  covered by the unit test
  `ObjectStorageQueueTableMetadata.ColumnsComparisonIgnoresRedundantParentheses`.
- `StorageReplicatedMergeTree::createReplicaAttempt` recognizes an
  already-created empty replica by comparing its `/metadata` and `/columns`
  structurally, covered by
  `04850_parenthesized_definitions_replica_recovery`.

Both fail on 26.3 without this change.
@alexey-milovidov

Copy link
Copy Markdown
Member

Conflicts resolved. Only the part of #114188 that applies to 26.3 is taken, so this is not a verbatim cherry-pick — please read this before merging it.

The parenthesized flag of IAST was introduced by #92340 in 26.5. 26.3 never writes a table definition with the redundant parentheses the user has written, so the bug that #114188 fixes cannot happen on this branch, and everything built on IAST::FormatSettings::ignore_redundant_parentheses (IAST::formatIgnoringRedundantParentheses and all of its call sites in AlterCommands, ColumnsDescription, ConstraintsDescription, IndicesDescription, MergeTreeData, ProjectionsDescription, ReplicatedMergeTreeTableMetadata and StorageReplicatedMergeTree::alter) would be dead code here. The tests 04836_parenthesized_definitions_attach_partition_from and 04837_parenthesized_definitions_replicated_metadata also assert that SHOW CREATE prints the parentheses back, which is 26.5 and later behavior, so they would fail on this branch. All of that is left out.

What is taken are the two places that have to accept a definition stored by 26.5..26.7, which 26.3 needs in order to read such a table at all - a user bitten on 26.5..26.7 who moves the table to 26.3 hits exactly these:

  • ObjectStorageQueueTableMetadata::checkImmutableFieldsEquals compares the columns payload structurally when the stored and the local text differ. Covered by the unit test ObjectStorageQueueTableMetadata.ColumnsComparisonIgnoresRedundantParentheses.
  • StorageReplicatedMergeTree::createReplicaAttempt recognizes an already-created empty replica by comparing its /metadata and /columns structurally instead of as raw strings. Covered by 04850_parenthesized_definitions_replica_recovery. This branch's checkEquals takes no virtuals, so the call uses the signature this branch has.

Both of these fail on 26.3 without this change.

If you would rather not carry the two tolerance fixes on 26.3 at all, just close this pull request - nothing else on the branch depends on it.

The changed translation units were compile-checked against this branch's sources.

@alexey-milovidov

Copy link
Copy Markdown
Member

Closing: #114188 is not needed on 26.3.

The bug it fixes needs IAST's parenthesized flag, which arrived with #92340 in 26.5, so 26.3 never writes a table definition with the redundant parentheses the user has written and cannot hit any of the Tables have different ... / METADATA_MISMATCH / INCOMPATIBLE_COLUMNS failures. Carrying the fix here would only add dead code.

The reduced variant pushed to this branch earlier (the two structural-comparison fixes that let 26.3 read a table whose metadata was stored by 26.5..26.7) is not being taken either. The backports to 26.5, 26.6 and 26.7 are where the fix belongs: #114653, #114654, #114655.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants