Skip to content

Fix RENAME COLUMN and DROP COLUMN of Memory tables leaving data under old names - #122954

Open
groeneai wants to merge 13 commits into
ClickHouse:masterfrom
groeneai:memory-alter-rename-drop-stored-columns
Open

groeneai wants to merge 13 commits into
ClickHouse:masterfrom
groeneai:memory-alter-rename-drop-stored-columns

Conversation

@groeneai

@groeneai groeneai commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #56892

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 ... RENAME COLUMN and DROP COLUMN on a Memory table: the rows inserted before the ALTER were read as default values under the new column name, and a column added later with an old name returned the data of the renamed or dropped column. A MODIFY SETTING combined with other commands in one ALTER of a Memory table now applies to the table right away, not only to its stored definition. RESTORE of a Memory table no longer loses a column added between two inserts, or fails after a MODIFY COLUMN between them.

Description

On 26.9 (and 26.3), RENAME COLUMN c0 TO c1 on a Memory table makes SELECT c1 return the default for every row inserted before it:

CREATE TABLE mem (c0 Nullable(UInt8)) ENGINE = Memory;
INSERT INTO mem VALUES (5), (NULL);
ALTER TABLE mem RENAME COLUMN c0 TO c1;
SELECT c1 FROM mem;                     -- \N, \N (expected 5, \N)
ALTER TABLE mem ADD COLUMN c0 UInt64;
SELECT c0 FROM mem;                     -- Code: 349, the old column is read as the new `c0`

Memory reads the columns of its stored blocks by name, and StorageMemory::alter changed only the metadata. The same stale names returned the data of a dropped column when its name was added again, mixed up the columns of a multi-command ALTER, broke UPDATE of a renamed column, and kept dropped columns in memory.

Now alter renames and drops the columns of the stored blocks, under the lock that INSERTs commit with, before alterTable commits the new definition. An INSERT or a RESTORE that started before the ALTER converts its blocks when it commits. A query racing such an ALTER fails with the retryable UNFINISHED. BACKUP takes the metadata and the blocks together and fails if the columns changed after it took the table definition; RESTORE reads each stored block with its own columns, drops columns the table lacks (backups of unfixed releases and inner tables of materialized views can have them), or fails if one may be renamed. Both check emptiness by rows. MODIFY SETTING in an ALTER with other commands now changes the running table.

Tests: 05295 covers each shape above; 05296 runs an INSERT, a RESTORE and a BACKUP across the ALTER. Both fail on master.

🤖 Generated with Claude Code


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

groeneai and others added 7 commits September 29, 2026 07:26
… old names

`StorageMemory` reads the columns of its stored blocks by name, and `alter` changed
only the metadata. After `RENAME COLUMN` the new name read defaults, a column added
later with an old name read the old data (or failed with Code 349), multi-command
ALTERs mixed up columns, `UPDATE` of a renamed column failed with
NOT_FOUND_COLUMN_IN_BLOCK, and dropped columns stayed in memory.

`alter` now replays the commands on a copy of the metadata to get the ordered renames
and drops, so the blocks follow the metadata exactly (`DROP COLUMN IF EXISTS` of a
`Nested` is a no-op there). Under the lock that INSERTs commit with, it converts a copy
of the blocks before `alterTable` commits the new definition, and publishes data, then
metadata, after it. A block left without columns gets a default-filled column, so it
keeps its row count. Such an ALTER is logged with the new metadata version, and an
INSERT or a RESTORE that captured older metadata converts its blocks when it commits.
A read whose metadata snapshot is older than the blocks it captured throws UNFINISHED
instead of reading defaults. BACKUP takes the metadata and the blocks together, and
RESTORE checks the column names of `columns.txt` against the table; a restore whose
names cannot be verified fails if a rename or drop ran during it.

RENAME COLUMN has been allowed for Memory since ClickHouse#56892.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A backup written by a release without the rename fix has `columns.txt` with the
new names but blocks under the old ones, and a restore with
`allow_different_table_def` appends columns the table does not have. Such a
column was kept, so a later `ADD COLUMN` with its name read the old data again.
`restoreDataImpl` now drops every restored column the table does not have,
after converting the blocks for the ALTERs that ran during the restore; a block
left without columns gets the fill column and keeps its rows. The fill column
rule moves to `chooseFillColumn`, shared by `alter` and the restore.

The fill column is compressed when the table has `compress = 1`, like the other
stored columns: a block that lost all its stored columns kept an uncompressed
column (100000 UInt64 rows: 800128 bytes instead of 3148).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`StorageMemory::alter` updated the runtime settings only when every command
of the ALTER was a settings command (`AlterCommands::isSettingsAlter` is
`all_of`). `ADD COLUMN b UInt64, DROP COLUMN a, MODIFY SETTING compress = 1`
therefore wrote `compress = 1` into the metadata, while the fill column built
by the same ALTER and every later INSERT stayed uncompressed (100000 UInt64
rows: 800128 bytes instead of 3148), and a mixed `max_rows_to_keep` never
removed rows.

The settings commands are now detected with `any_of`, and the new settings
and the eviction they cause are staged together with the converted blocks
and published after `alterTable`, like the conversion. Publishing the
eviction before it would drop rows on a mixed ALTER that `alterTable` then
rejects (`DROP COLUMN` of the last physical column fails with
`EMPTY_LIST_OF_COLUMNS_PASSED`). The eviction runs on the converted blocks,
which is the state after the ALTER.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s empty

A block that loses all its stored columns gets a fill column, and when that is
an empty `Tuple()` the block keeps its rows but takes 0 allocated bytes. So
after `ADD COLUMN e Tuple()` and `DROP COLUMN a`, `BACKUP` saw `totalBytes == 0`
and wrote no data (a `RESTORE` brought back 0 rows), and `RESTORE` saw the table
as empty and appended to it. A table created with only `Tuple()` columns had
the same problem.

Both checks now use the row count.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… was taken

`BackupEntriesCollector::run` writes the table definitions first and then
collects the data, holding only a shared table lock, which an `ALTER` does not
wait for. Since `alter` now renames and drops the stored columns, an `ALTER`
between the two stages gave a backup whose `CREATE` has the old columns while
`columns.txt` and `data.bin` have the new ones, and the `RESTORE` column check
of this change refused it with `CANNOT_RESTORE_TABLE`. A `Replicated` database
replica with a lagging DDL queue does the same without any concurrent `ALTER`,
because its definitions come from Keeper.

The collector now keeps the definition it wrote for each data path
(`getTableCreateQuery`), and `StorageMemory::backupData` throws the retryable
`INCONSISTENT_METADATA_FOR_BACKUP` when the stored columns of that definition
(everything except ALIAS and EPHEMERAL) differ from the metadata it backs up.
The new fail point `backup_pause_before_collecting_table_data` pauses between
the two stages for the test.

05296 runs a `RENAME COLUMN` in that pause, 05295 backs up and restores a table
with MATERIALIZED, ALIAS, EPHEMERAL and Nested columns, and checks that an
insert after a mixed `ALTER` with `MODIFY SETTING max_rows_to_keep` uses the
new setting.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A materialized view backs up and restores its inner table under its own data
path, so the definition that `BACKUP` compared with the data of an inner
`Memory` table was the view's, and `RESTORE` compared the backup's
`columns.txt` with an inner table created from the view's columns. After an
`ALTER` of the inner table itself, which the view follows only at the next
`MODIFY QUERY`, the view could not be backed up, and a backup of it written by
a release could not be restored. The same strict `RESTORE` check refused
backups that a release wrote across a concurrent `ALTER`, which restore on
master.

The collector now keeps the definitions per storage, so an inner table has
none of its own. `RESTORE` restores the blocks by name when their names differ
from the table, and fails only if a column of the table was renamed or
dropped. `BACKUP` also compares the column types of the definition, so a
concurrent `MODIFY COLUMN` fails the backup instead of leaving a definition
older than the data.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the comments on the ALTER publication order and on the RESTORE column name check, and drop one that restated the type comparison.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-self PR origin: self-found defect (impact-bar validated) labels Sep 29, 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; 11 findings over six rounds) plus my own cold review.

# Sev Finding Verdict Evidence / action
1 ❌ A backup written by an unfixed release after RENAME/DROP COLUMN has blocks under the old names, so RESTORE kept a stale column that a later ADD COLUMN with its name served AGREE, remedy changed Fixed in 0cb2a67: restored columns the table does not have are dropped. Not rejected: that would make every release backup taken after a plain DROP COLUMN unrestorable.
2 ⚠️ The column that keeps the row count of a block without stored columns ignored compress = 1 AGREE Fixed in 0cb2a67.
3 ⚠️ An ALTER mixing MODIFY SETTING with column commands never applied the settings to the running table (isSettingsAlter is all-of) AGREE Fixed in 16128e8: staged with the column conversion and published after alterTable, so a rejected ALTER applies nothing.
4 ❌ Rows left with only an empty Tuple() column take no bytes, so BACKUP skipped them and RESTORE treated the table as empty AGREE Fixed in 3fcf9ad: both count rows instead of bytes.
5 ⚠️ No committed test reddens when the readImpl version check or the lock in backupData is removed DISAGREE Measured in a 120 s stress run instead: without the check 5 of 2800 reads returned the wrong sum 0, with it 0 wrong and 6 UNFINISHED. A deterministic test needs a test-only pause fail point inside alter.
6 💡 With restore_replicated_merge_tree_to_shared_merge_tree, a restore into an existing, differently defined Memory table now fails with CANNOT_RESTORE_TABLE noted Loud failure in that configuration only.
7 💡 The fill column costs rows x the width of its type noted Only for rows inserted before every current column was added; compressed on compress = 1.
8 💡 column_changes is never pruned noted One small entry per ALTER that renames or drops columns.
9 💡 The restore filter keys on names: a restored column with the table's name but another type is kept and read through a cast noted Unchanged from master (measured).
10 💡 INSERT and the RESTORE data loading read compress without the lock under which ALTER replaces the settings noted Unchanged from master.
11 ❌ BACKUP writes the definition before it collects the data, so an ALTER in between (or a lagging Replicated replica) left a backup whose data names do not match its definition, and RESTORE refused it AGREE Fixed in 7e088b3: BACKUP compares them and fails with the retryable INCONSISTENT_METADATA_FOR_BACKUP.
12 ⚠️ No test wrote to the table after a mixed ALTER AGREE Fixed in 7e088b3: 05295 inserts after it and checks that max_rows_to_keep applies.
13 ❌ A materialized view passes its own backup data path to its inner Memory table, so after an ALTER of the inner table BACKUP of the view always failed and a release backup of it did not restore; the strict RESTORE check also refused release backups written across a concurrent ALTER AGREE Fixed in 5653b22: definitions are looked up by storage; on a name mismatch RESTORE restores by name and fails only if a column of the table was renamed or dropped.
14 ❌ The BACKUP check compared names only, so a concurrent MODIFY COLUMN left a backup whose restored (old) type casts the newer blocks AGREE Fixed in 5653b22: types are compared as well (by name only when a type cannot be built).
15 ❌ A release backup taken after DROP COLUMN b, RENAME COLUMN a TO b holds blocks {a, b} and columns.txt b, so RESTORE keeps the stale b DISAGREE It is byte-identical to a release backup after a plain DROP COLUMN a, where keeping b is right, and refusing it would refuse every release backup taken after any DROP COLUMN. The kept value is what the release itself returned. If you prefer, RESTORE can refuse any backup whose blocks hold a column that columns.txt lacks.
16 ❌ IDataType::equals ignores DateTime time zones and custom names such as Bool, so such a MODIFY COLUMN is not detected DISAGREE Such types store identical values, so every restored row is readable. Comparing type names would fail every BACKUP of a stored unversioned sumMap or groupBitmap state (ATTACH pins version 0, the rebuilt type prints version 1).
17 💡 The RESTORE refusal keys on every rename or drop since the table was created or attached noted Loud failure; it needs a matching definition as well.

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

Session id: cron:clickhouse-review-self-slot-58:20260929-191300

@groeneai

groeneai commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. CREATE TABLE mem (c0 Nullable(UInt8)) ENGINE = Memory; INSERT INTO mem VALUES (5), (NULL); ALTER TABLE mem RENAME COLUMN c0 TO c1; SELECT c1 FROM mem returns \N, \N on every run on master, 26.3.33.24 and 26.9.1.1629.
b Root cause explained? Memory reads the columns of its stored blocks by name, and StorageMemory::alter applied RENAME COLUMN / DROP COLUMN to the metadata only; an INSERT or RESTORE that captured the metadata before the ALTER also commits blocks under the old names.
c Fix matches root cause? Yes. alter renames/drops the stored columns (replaying the commands as the metadata is changed) under the insert commit lock, before alterTable commits; late writers convert on commit; a read pairing older metadata with converted blocks fails with UNFINISHED.
d Test intent preserved / new tests added? New 05295 (each affected shape, incl. Nested, UPDATE, compress = 1, temporary tables, mixed ALTERs, blocks left without stored columns, BACKUP/RESTORE of column kinds) and 05296 (INSERT, RESTORE and BACKUP across the ALTER, incl. a type change and a materialized view, deterministic via pipe back-pressure and fail points). Both fail on master.
e Both directions demonstrated? Yes, same-commit binaries: master fails both tests, the fix passes them, 50/50 randomized runs green. Mutation checks (each conversion step, the fill column and its compression, the restore drop, the mixed-ALTER settings, the emptiness checks, BACKUP's definition and type checks) redden the matching test lines.
f Fix is general across code paths? Yes. Every writer of the stored blocks (ALTER incl. the settings eviction, INSERT commit, RESTORE, mutations, TRUNCATE) and every reader (read step incl. PREWHERE and subcolumns, system.columns sizes, BACKUP, UPDATE) is handled or unaffected; internal Memory tables are never altered.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. The rename moves the column pointer, so it is type-agnostic: checked with Nullable, LowCardinality(Nullable), Array(Nullable), Map, named Tuple, Variant, Dynamic, JSON and their subcolumns, Nested, IF EXISTS, and an empty table.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or persisted state changes, and backups written by master restore, now also with a column added or retyped between inserts, unless a view's inner table renamed a view column on its own. Restored columns the table lacks are dropped; a mixed ALTER applies its MODIFY SETTING to the running table; emptiness is checked by rows; new errors: the retryable INCONSISTENT_METADATA_FOR_BACKUP (a BACKUP across a column-changing ALTER, or on a lagging Replicated replica) and UNFINISHED (a read straddling a rename/drop), and CANNOT_RESTORE_TABLE when the backup's column names cannot be mapped because a column was renamed or dropped (allow_different_table_def restores by name).
i Invariants and contracts preserved? A stored column named X holds the data of the current column X and every block keeps its row count; lock order is unchanged; nothing is published before alterTable succeeds, data before metadata, and a reader checks the pair.

Session id: cron:clickhouse-impl-self-slot-57:20260929-173500

@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [dffc4a4]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_binary, s3 storage, DBReplicated, parallel, 1/2) FAIL
05295_memory_alter_rename_drop_stored_columns FAIL cidb
Stateless tests (arm_asan_ubsan, azure, sequential) ERROR

AI Review

Summary

This PR fixes a real cluster of Memory-engine ALTER / backup / restore bugs, and the overall direction looks right, but I still see two blocker-level correctness holes in the current head: one in the path that fills a block after a rename/drop removes every stored column, and one in the new backup-side consistency check for delegated inner Memory tables.

Findings

❌ Blockers

  • [src/Storages/StorageMemory.cpp:593] The contract here is that when a rename/drop empties an old block, the replacement rows must still produce every surviving physical column exactly as a normal INSERT without those columns would. setFillColumn only switches to addMissingDefaults when all surviving physical columns have DEFAULT / MATERIALIZED expressions. In a mixed schema, that still returns wrong results. A concrete repro is CREATE TABLE t (x UInt8) ENGINE = Memory; INSERT INTO t VALUES (5); ALTER TABLE t ADD COLUMN a UInt8, ADD COLUMN b UInt8 DEFAULT a + 1; ALTER TABLE t DROP COLUMN x; SELECT a, b FROM t;: the pre-existing row still reads (0, 0) instead of (0, 1). The same hole exists in RESTORE after stripping unknown backup columns. Suggested fix: keep fill_with_defaults whenever any surviving physical column has a DEFAULT or MATERIALIZED expression, and add ALTER + RESTORE coverage for the mixed-schema case.
  • [src/Backups/BackupEntriesCollector.cpp:897] The new definition-vs-data backup gate is still keyed only by table_info.storage, so delegated backups of inner StorageMemory tables still skip it entirely (getTableCreateQuery(*this) == nullptr). StorageMaterializedView is a concrete repro: after directly MODIFY COLUMN-ing the hidden target table, or while such an ALTER races BACKUP TABLE mv, the backup still succeeds even though the view definition no longer matches the Memory data being written. That violates the PR's new “fail early with INCONSISTENT_METADATA_FOR_BACKUP” contract and defers the inconsistency to RESTORE (or lets it through if the name-only path can cast it). Suggested fix: plumb the defining schema into delegated StorageMemory::backupData calls and validate the shared columns / types there without regressing the intended materialized-view case where backup-only extra columns are dropped by name on restore.
Final Verdict

❌ Changes requested — the two blockers above still need to be fixed before this is merge-ready.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 29, 2026
Comment thread src/Storages/StorageMemory.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-simple-engines Lightweight single-node table engines: Log/StripeLog (append-only logs), Buffer (async batching),... label Sep 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing dffc4a4a7 with master e1d921be0 (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.

Object file sizes

19 object files changed (+98.35 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/StorageMemory.cpp.o 654.77 KiB 741.56 KiB +86.79 KiB (+13.25%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Median compile-time ratio to the baselines is ×0.95 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -10.0 s (-3%) in total before that adjustment.

Job report

groeneai and others added 2 commits September 29, 2026 22:54
…amed

A RENAME COLUMN on the inner table of a materialized view alone (the view follows it only at MODIFY QUERY) leaves a
backup whose blocks store the column under its new name, while RESTORE creates the inner table with the columns of
the view. The restore dropped the stored column as one the table lacks and read the view's column as default values:
`SELECT x` with `x` renamed to `y` in `.inner_id.*` restored 4 rows with sum(x) = 0 instead of 6. Master restores 6
only because its RENAME leaves the blocks under the old name.

When the table has a column that the backup's columns.txt lacks, a stored column that columns.txt lists but the table
lacks now fails the RESTORE with CANNOT_RESTORE_TABLE instead of being dropped; allow_different_table_def restores by
name as before. A mismatch in one direction still restores: a column added to the inner table is dropped (the view
does not have it) and a column dropped from it is restored as default values. The check looks at the stored blocks,
so backups written by releases, whose blocks keep the names from before a concurrent RENAME, still restore.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RESTORE read data.bin with one NativeReader, which takes its header from the first block of the index and converts
every later block to it: a column the first block lacks is skipped and a type that differs throws. The blocks of a
Memory table differ whenever an ALTER ran between inserts, so on 26.3 and 26.8 a column added between two inserts
restored as default values (sum 5 -> 0) and a MODIFY COLUMN between them made RESTORE fail with TYPE_MISMATCH. With the
renamed blocks of this PR it also dropped the rows a materialized view inserted after `RENAME COLUMN x TO y, ADD COLUMN x`
on its inner table (x = [0,0,0,4] restored as [0,0,0,0]), and the check for a possibly renamed column saw only the
first block's names. Each block now gets its own reader over its index entry.

The Memory-specific tests are tagged memory-engine: the stress runner replaces Memory with MergeTree in a share of its
runs, and tagged tests are skipped there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Storages/StorageMemory.cpp Resolved
When a DROP COLUMN leaves a stored block with no columns, the block keeps its rows through a fill column filled with
the type's default. If every remaining physical column had a DEFAULT or MATERIALIZED expression, that is not what
reading the rows means: `CREATE TABLE t (a UInt8) ENGINE = Memory; INSERT 1; ADD COLUMN b UInt8 DEFAULT 7; DROP COLUMN a`
stored and read b = 0. The same fill is used for the blocks of an INSERT that commits after such an ALTER and for a
RESTORE whose stored columns are all unknown to the table.

In that case the block now gets all physical columns, computed with `addMissingDefaults` as an INSERT that omits them
computes them, so b = 7, and the stored columns agree with each other (`t DEFAULT tuple(3)`, `m MATERIALIZED t.x + 4`
store t.x = 3, m = 7; storing only one of them read the other as its type's default). The actions are built once per
ALTER, commit or restore and only when a block needs them, so a default that cannot be computed fails only an ALTER
that needs it, before anything is changed. Non-deterministic defaults (`now()`, `rand()`) get the values of that
computation, as in an INSERT. If a physical column without a default expression exists, only it is stored, with the
type's default, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
const auto physical_columns = columns.getAllPhysical();
auto fill_column = std::find_if(physical_columns.begin(), physical_columns.end(),
[&](const auto & column) { return !columns.hasDefault(column.name); });
if (fill_column != physical_columns.end())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setFillColumn only switches to addMissingDefaults when every surviving physical column has a default or materialized expression. That still leaves wrong results for mixed schemas where one remaining column has no default and another depends on it. A concrete repro is:

CREATE TABLE t (x UInt8) ENGINE = Memory;
INSERT INTO t VALUES (5);
ALTER TABLE t ADD COLUMN a UInt8, ADD COLUMN b UInt8 DEFAULT a + 1;
ALTER TABLE t DROP COLUMN x;
SELECT a, b FROM t;

For the pre-existing row, this path stores only a = 0; ReadFromMemoryStorageStep does not evaluate b's default later, so the row reads back as (0, 0) instead of (0, 1). The same hole exists in the restore path when dropping unknown backup columns empties a block. addMissingDefaults can already fill missing non-default columns with type defaults before computing dependent defaults, so this needs to keep the full ColumnsDescription whenever any surviving physical column has a default/materialized expression, not only when all of them do.

@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 31 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 4256f3a2-1a73-4262-aad3-72e3016bda85
  • MIRAI run: d0fe16d5-f065-458b-8641-c2a97576ddc0
  • PR check IDs:
    • clickbench_770644_1791665045
    • clickbench_770657_1791665046
    • clickbench_770663_1791665045
    • tpch_adapted_1_official_770674_1791665045
    • tpch_adapted_1_official_770688_1791665045
    • tpch_adapted_1_official_770715_1791665045

@jkartseva

Copy link
Copy Markdown
Member

@groeneai merge master

…-drop-stored-columns

# Conflicts:
#	src/Storages/StorageMemory.cpp
@groeneai

groeneai commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

Merged master in 00874cf. The only conflict was in StorageMemory.cpp: this PR's new publication points now use master's setData. 05295 and 05296 pass locally.

The master style rule failpoint_tests_are_isolated requires every stateless
test that enables a fail point to be tagged both no-parallel and no-fasttest.
05296 arms restore_pause_before_data_restore_tasks and
backup_pause_before_collecting_table_data and was tagged no-parallel only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
const String & metadata_path_in_backup = table_info.metadata_path_in_backup;
backup_entries.emplace_back(metadata_path_in_backup, std::make_shared<BackupEntryFromMemory>(new_create_query->formatWithSecretsOneLine()));
if (table_info.storage)
create_table_queries_by_storage[table_info.storage.get()] = new_create_query;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_table_queries_by_storage is only populated for table_info.storage, i.e. the outer StorageMaterializedView object. But StorageMaterializedView::backupData delegates to its inner StorageMemory, so the delegated call reaches StorageMemory::backupData with getTableCreateQuery(*this) == nullptr and skips the new definition-vs-data consistency check entirely.

That still leaves a broken backup path for materialized views whose inner Memory table was altered directly. For example, after ALTER TABLE \` MODIFY COLUMN x Nullable(UInt64), BACKUP TABLE mvwritescolumns.txt/data.binfor the inner schema whileRESTORE TABLE mvrecreates the inner table from the view definition.restoreDataFromBackuponly compares names, not types, so this path can still reintroduce the mismatched-type restore bug that the newDataTypeFactorycheck fixed for ordinaryMemorytables. The same hole also means an inner-tableALTERracing the backup is rejected only later at restore time, not with the retryableINCONSISTENT_METADATA_FOR_BACKUP` promised here.

Please either key the collector map by the delegated inner storage as well, or plumb the view's create-query down explicitly when delegating the backup, and add a regression around backing up a materialized view after changing an inner Memory column type.

clickgapai pushed a commit to clickgapai/ClickHouse that referenced this pull request Oct 3, 2026
The insert branch of updateBlockData is removed: a column that a stored
block lacks can be stored there only once ClickHouse#122954 removes dropped and
renamed columns from the stored blocks. DROP COLUMN and RENAME COLUMN
leave the stored data of a Memory table in place, so a value stored for
an added column would come back after DROP COLUMN and a new ADD COLUMN
of the same name. Until then, such an UPDATE is rejected with
NOT_FOUND_COLUMN_IN_BLOCK, as on master.

The test is renamed to 05301_memory_update_after_modify_column, loses
the ADD COLUMN arms and gains a MATERIALIZE COLUMN arm on a MATERIALIZED
column.

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

PedroTadim commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

@alexey-milovidov this one is too large for me to review

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-simple-engines Lightweight single-node table engines: Log/StripeLog (append-only logs), Buffer (async batching),... groeneai-origin-self PR origin: self-found defect (impact-bar validated) pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants