Skip to content

Fix ALTER and _table of S3 and data lake tables after RENAME TABLE or EXCHANGE TABLES - #133156

Open
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:object-storage-current-storage-id
Open

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:object-storage-current-storage-id

Conversation

@groeneai

@groeneai groeneai commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

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):

Fixed ALTER TABLE of an S3, AzureBlobStorage, HDFS or data lake table after RENAME TABLE, EXCHANGE TABLES or RENAME DATABASE: it failed with CANNOT_GET_CREATE_TABLE_QUERY or another table's error (a LOGICAL_ERROR when the other table is an Alias), and the _table virtual column of such a table returned its old name.

Description

On 26.8 and 26.10, RENAME TABLE t TO t2 followed by ALTER TABLE t2 COMMENT COLUMN c 'x' on an S3 table is rejected with CANNOT_GET_CREATE_TABLE_QUERY (Table t doesn't exist), and SELECT _table FROM t2 returns t.

Found by La Casa Del Dolor: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130259&sha=ec0f52f7aad97919cf5cfdc16144373541b929db&name_0=PR&name_1=La%20Casa%20Del%20Dolor%20%28amd_debug%29 (Logical error: 'Cannot alter table t27 metadata doesn't have structure', STID 3623-3a50).

StorageObjectStorage kept its own copy of its StorageID, set in the constructor. RENAME/EXCHANGE/RENAME DATABASE update only the id of IStorage, so alter (the max_query_size check and alterTable), alterSettings and read (_table) kept using the old name. After EXCHANGE TABLES with an Alias table, whose stored definition has no columns, the check throws the LOGICAL_ERROR; with any other partner, alterTable fails its UUID check after an Iceberg table has already written its new metadata.

The copy is removed and getStorageID() is used everywhere, as mutate, alterPartition and StorageObjectStorageCluster already do.

Validation: the new test 05837_object_storage_alter_after_rename (S3 and IcebergS3: _table, COMMENT COLUMN after RENAME and after EXCHANGE with an Alias, ADD COLUMN and MODIFY SETTING of a renamed Iceberg table) fails on master and passes 50/50 with randomized settings. Fixing only the max_query_size check is not enough: alterTable and _table still use the old name.

🤖 Generated with Claude Code


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

…EXCHANGE

`StorageObjectStorage` kept its own copy of its `StorageID`, initialised once
in the constructor. `RENAME TABLE`, `EXCHANGE TABLES` and `RENAME DATABASE`
update only the id of `IStorage` (`IStorage::renameInMemory`), so the copy
kept the name the table was created with, and every reader of it used the old
name:

- `alter` loaded the stored CREATE of the old name for the `max_query_size`
  check and then called `alterTable` with the old id. After a RENAME the old
  name does not exist, so `ALTER TABLE ... COMMENT COLUMN` (and, for data lake
  tables, ADD/DROP/MODIFY COLUMN) failed with CANNOT_GET_CREATE_TABLE_QUERY.
  After an EXCHANGE the old name belongs to the partner table: an `Alias`
  partner has no columns in its stored CREATE, so
  `applyMetadataChangesToCreateQuery` threw LOGICAL_ERROR (found by
  La Casa Del Dolor, STID 3623-3a50); any other partner failed the UUID check
  of `alterTable` after an Iceberg table had already written its new metadata.
- `alterSettings` called `alterTable` with the old id, so MODIFY SETTING of a
  renamed data lake table failed the same way.
- `read` passed the old name to `ReadFromObjectStorageStep`, so `_table`
  returned the old name.

Remove the copy and use `getStorageID()` everywhere, as the rest of the class
(`mutate`, `alterPartition`, `configuration->alter`) and
`StorageObjectStorageCluster` already do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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; 1 finding).

# Sev Finding Verdict Evidence / action
1 ⚠️ The test does not check ALTER after RENAME DATABASE, nor _table after EXCHANGE TABLES DISAGREE The change is in the readers of the id (read/_table, the max_query_size check and alterTable in alter, alterSettings), and the test exercises each of them; each case fails without the fix, and so do builds that fix only some of them. RENAME TABLE, EXCHANGE TABLES and RENAME DATABASE all update the id through IStorage::renameInMemory (DatabaseAtomic.cpp:404-406, :843-848), which this PR does not change, so another trigger covers no changed line. RENAME DATABASE followed by ALTER ... COMMENT COLUMN was checked by hand on the fixed build.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261120-060404

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. CREATE TABLE d.t (c0 Int32) ENGINE = S3(...); RENAME TABLE d.t TO d.t2; ALTER TABLE d.t2 COMMENT COLUMN c0 'x' fails with CANNOT_GET_CREATE_TABLE_QUERY every time on master; EXCHANGE TABLES with an Alias table, then the same ALTER, aborts a debug build with the CI stack (applyMetadataChangesToCreateQuery <- checkMetadataDoesNotExceedMaxQuerySize <- StorageObjectStorage::alter).
b Root cause explained? StorageObjectStorage kept a private StorageID set in the constructor; RENAME/EXCHANGE/RENAME DATABASE update only the id of IStorage, so alter, alterSettings and read looked the table up under its old name: missing after RENAME, the partner after EXCHANGE (an Alias partner has no columns in its stored definition).
c Fix matches root cause? Yes. The copy is removed; every reader uses getStorageID(), the id RENAME keeps current. No guard on the symptom.
d Test intent preserved / new tests added? New SQL test 05837_object_storage_alter_after_rename (S3 + IcebergS3); no existing test changed.
e Both directions demonstrated? Master: _table returns the old name, COMMENT COLUMN fails 390, the Alias case aborts the server, Iceberg ADD COLUMN/MODIFY SETTING fail 390. Fix: all pass, 50/50 with randomized settings. A build fixing only the max_query_size check still fails 4 of 5 cases; one fixing all but read still returns the old _table.
f Fix is general across code paths? All readers of the copy changed (alter, alterSettings, read, write, drop, executeCommand, constructor). StorageObjectStorageCluster, StorageObjectStorageQueue, File and URL already use getStorageID(); Azure, HDFS, Local and the data lakes are the same class.
g Fix generalizes across inputs (params/datatypes/wrappers)? RENAME TABLE, EXCHANGE TABLES (with Alias and with MergeTree), RENAME DATABASE; Atomic and Replicated databases. Type wrappers do not apply.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change; a table that was never renamed gets the same id as before.
i Invariants and contracts preserved? getStorageID() takes IStorage::id_mutex briefly with nothing nested under it; alter takes the id once, as StorageMergeTree::alter does.

Session id: cron:clickhouse-impl-slot-4:20261120-051205

@clickhouse-gh

clickhouse-gh Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [eb8c52b]

Summary: ✅


AI Review

Summary

Removes the stale StorageID copy from StorageObjectStorage so ALTER TABLE and _table use the current identity after RENAME TABLE, EXCHANGE TABLES, or RENAME DATABASE. The added S3 and IcebergS3 regression test covers the affected metadata and read paths. No actionable findings in commit eb8c52b14d94cf2095d7b77be7a464e13dfc2673.

Missing context / blind spots
  • ⚠️ Tests were not run locally. The author documents failure before the fix and 50 randomized passes afterward. The current CI report reports bugfix-validation jobs dropped after Config Workflow; a completed run would provide independent runtime confirmation.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default can be tested Allows running workflows for external contributors labels Nov 20, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. label Nov 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing eb8c52b14 with master e627fea5e (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

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

Job report

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-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant