Repository navigation
Fix column loss when a column dropped and re-added with IF NOT EXISTS in the same ALTER statement - #117825
Fix column loss when a column dropped and re-added with IF NOT EXISTS in the same ALTER statement#117825zoomxi wants to merge 53 commits into
Conversation
This comment was marked as low quality.
This comment was marked as low quality.
|
Workflow [PR], commit [7439188] Summary: ❌
AI ReviewSummaryAt Findings❌ Blockers — previously reported data correctness bugs, deferred from this PR
Missing context / blind spots
Final VerdictStatus: Link follow-up issues for the four untracked deferred cases and record the relationship to #127897. These can remain separate fixes. The conditional rename finding is resolved; no duplicate inline comments or new review batch were posted. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes57 object files changed (+294.18 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units498 translation units recompiled, 3685 s compile time in total, 498 of them have a recent master baseline. |
…t stores. The wide path already remapped via the source-part name, but compact/non-wide mutations still tested `part_columns.has(command.column_name)` and then replayed the rename as `READ_COLUMN`, so stale values survived a same-statement or pending `RENAME` plus `DROP`/`CLEAR`. Share that lookup and skip the rename replay for dropped or cleared sources. https: //github.com/ClickHouse/pull/117825 Co-authored-by: Cursor <[email protected]>
…me name. `nameStoredInPart` fell back to the finished `AlterConversions` map, so `DROP a, RENAME b TO a` dropped `b`'s files and left `a`'s data in place. That broke `01281_alter_rename_and_other_renames`, `03526_columns_substreams_in_wide_parts`, and `03990_alter_rename_column_swap_different_types` in Fast test. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117825&sha=51ce014581e7d1eec9aab9b29fa497324a2a412e&name_0=PR&name_1=Fast%20test ClickHouse#117825
…d files. `prepare` treated a Nested parent as present for every command, so `MODIFY COLUMN IF EXISTS n` threw instead of no-op'ing. The wide-part DROP path also expanded `hasNested` without `share_nested_offsets`, so `DROP COLUMN n` deleted independent `n.a` files on parts written before `n` existed. ClickHouse#117825
`hasNested` matches any dotted prefix, so a UNIQUE KEY table with only an `ALIAS` column `` `n.x` `` rejected `CLEAR COLUMN IF EXISTS n` with `SUPPORT_IS_DISABLED` while `prepare`/`validate`/`getMutationStageDecision` treated it as a no-op. Use `hasColumnOrNested` with `AllPhysical` for the nested arm. ClickHouse#117825
|
Confirmed, and the fix is in flight. Both PRs you found are mine and still open:
One extra data point: on Nothing to change on your side. Re-running that single job is usually enough to clear it, along with the |
`DROP_COLUMN` dropped `auto_minmax_index_<column>` before the `clear` / `partition` guard, so `CLEAR COLUMN x` and `CLEAR COLUMN x IN PARTITION` removed the index even though the column definition stayed. Move the exact-index removal onto the full metadata-drop path. ClickHouse#117825
`hasColumnOrNested` previously inspected only the first `n.*` match, so a UNIQUE KEY table with `` `n.x` UInt32 ALIAS id, `n.y` UInt32 `` treated `CLEAR COLUMN n` as a no-op while `n.y` remained stored. ClickHouse#117825
…nt `RENAME COLUMN`. The guard used pre-ALTER names, so `RENAME COLUMN a TO b, CLEAR COLUMN b` skipped the reject path while the mutation still rewrote stored `a` and dropped `unique_key_index.sst`. ClickHouse#117825
…xists-zero-column
| { | ||
| if (!command.clear) /// CLEAR column is Ok even if there are dependencies. | ||
| /// `CLEAR` and `IN PARTITION` keep the column for later commands in this ALTER. | ||
| if (!command.clear && !command.partition) |
There was a problem hiding this comment.
[Major] Keep conditional parent no-ops out of the validation snapshot
prepare and apply deliberately preserve n.* for DROP COLUMN IF EXISTS n when there is no exact n, but this branch still removes the children from all_columns. Reproduced with this head's Fast test binary:
CREATE TABLE t (id UInt8, n Nested(a UInt8))
ENGINE = MergeTree ORDER BY id;
ALTER TABLE t DROP COLUMN IF EXISTS n, COMMENT COLUMN `n.a` 'retained';This fails with NOT_FOUND_COLUMN_IN_BLOCK for n.a, although the drop is a no-op and commenting the retained child is valid. Apply the same exact-name IF EXISTS no-op predicate here before dependency checking, removing columns, or retiring pending defaults. Add a regression with an unconditional command on the retained child after the no-op.
…izes. A replacement default that reads a subcolumn of a column recreated in the same `ALTER` was stored with zero rows. A cleared or missing `Nested` member was filled as an empty array instead of the sibling's sizes.
`CLEAR COLUMN ... IN PARTITION` was applied to a lightweight-update patch in another partition, so that update was lost on read and after a later mutation.
…aves. `prepare` ignored a subcolumn codec after a type change in the same statement. `DROP COLUMN IF EXISTS` of a `Nested` parent that is not an exact column removed the children during validation. `CLEAR` of an alias-only parent was emitted as a mutation and rejected on `UNIQUE KEY` tables.
Use `COMMENT COLUMN` to verify that the retained child remains available after a no-op parent drop, and remove the `StorageMemory` diagnostics reported by `clang-tidy`. Related: ClickHouse#117825
The previous commit replaced the rename assertion with `COMMENT COLUMN` without updating the expected output. Related: ClickHouse#117825
Keep untouched missing columns at their read defaults when the last stored column is dropped. Evaluate defaults only for replaced or newly added identities, and establish the saved row count before constant alias evaluation. Related: ClickHouse#117825
…o fix-re-add-if-not-exists-zero-column # Conflicts: # src/Storages/StorageMemory.cpp
Use `getSettingsChanges` to reconstruct the settings AST after `StorageInMemoryMetadata` switched to serialized settings. Related: ClickHouse#117825
…o fix-re-add-if-not-exists-zero-column
- Evaluate default dependencies through aliases and subcolumns recursively. - Respect flatten_nested when tracking added physical columns. - Replace unbounded rewrite history with a short exclusive publication phase. - Evaluate expressions before taking the lock so dictionary self-reads do not deadlock. Related: ClickHouse#117825
Resolve explicitly declared dotted columns before tuple subcolumns. Extract required subcolumns before conversion and avoid converting unused tuple members. Related: ClickHouse#117825
Convert a parent before extraction when its old type lacks the requested subcolumn, and use scalar defaults instead of sibling array offsets for missing scalar dependencies. Skip tests in Replicated database and ParallelReplicas configurations that reject the tested SQL or table plan. Related: ClickHouse#117825
|
|
||
| /// The checks above read the column as the previous commands left it. Record this command's | ||
| /// own properties so the next command, and the final default check, see them too. | ||
| all_columns.modify(column_name, [&](ColumnDescription & column) |
There was a problem hiding this comment.
[Major] Advance the subcolumn codec state in validation too
The new property replay only reaches ordinary columns. The subcolumn branch at AlterCommands.cpp:2496-2498 validates a codec and immediately continues without updating the parent's subcolumn_codecs, so later commands still see the old state.
Reproduced with this head's Fast test binary:
SET enable_subcolumn_codecs = 1;
CREATE TABLE t (a Tuple(v UInt64)) ENGINE = MergeTree ORDER BY tuple();
ALTER TABLE t
MODIFY COLUMN a Tuple(v UInt64, w UInt64),
MODIFY COLUMN a.w CODEC(ZSTD),
MODIFY COLUMN a.w REMOVE CODEC;This throws BAD_ARGUMENTS: Subcolumn a.w doesn't have CODEC, cannot remove it. Running the modifications separately succeeds. The earlier type change is now visible, but the codec installed by the next command is absent from the validation snapshot.
Apply each validated subcolumn codec change to all_columns before that branch continues, and cover setting/removing a codec on a subcolumn introduced earlier in the same statement.
…o fix-re-add-if-not-exists-zero-column # Conflicts: # src/Common/FailPoint.cpp # src/Storages/MutationCommands.cpp
| columns.remove(command.column_name); | ||
| } | ||
| else if (command.type == AlterCommand::RENAME_COLUMN && columns.has(command.column_name)) | ||
| columns.rename(command.column_name, command.rename_to); |
There was a problem hiding this comment.
[Blocker] Hide the renamed source from a replacement using its old name
Making the replacement add effective exposes the old part column through both names while the rename mutation is pending. AlterConversions maps x_old back to the stored x, but the reader also finds that same stored x for the newly created column. Reproduced with this head's Fast test binary:
CREATE TABLE t (id UInt8, x UInt8) ENGINE = MergeTree ORDER BY id
SETTINGS min_rows_for_wide_part = 0, min_bytes_for_wide_part = 0;
INSERT INTO t VALUES (1, 7);
SYSTEM STOP MERGES t;
ALTER TABLE t RENAME COLUMN x TO x_old,
ADD COLUMN IF NOT EXISTS x UInt8 DEFAULT 9
SETTINGS alter_sync = 0;
SELECT x_old, x FROM t;
SYSTEM START MERGES t;The read returns (7, 7), rather than (7, 9); after mutation completion it changes to (7, 9) without another write. Preserve column identity in pending-read conversions so the rename destination retains the old data and the recreated source reads its default. Please cover both pending and completed reads.
There was a problem hiding this comment.
Not a regression. This is an existing bug on master and should be fixed in a separate PR.
A single ALTER statement that drops a column and re-adds it under the same name with
ADD COLUMN IF NOT EXISTSsilently drops the column for good. The re-added column never comes back, so a table whose columns are all re-added this way ends up with an empty column list; any later ALTER on it then aborts withCannot alter table ... metadata doesn't have structure(LOGICAL_ERROR).Closes: #117824
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix re-adding a column with
ADD COLUMN IF NOT EXISTSafter it was dropped in the same ALTER statement.Workflow [PR]
Sync PR [sync-upstream/pr/117825]