ClickHouse / ClickHouse/ClickHouse
Can't rename column synchronously
- Dominant language
- C++
- Stars
- 49.9k
- Forks
- 9k
- Avg merge
- 21h 32m
- Merged PRs (30d)
- 515
Description
**Does it reproduce on recent release?**
Checked on versions from 20.8 to 21.5.6.6
**How to reproduce**
Suppose there are 1 shard, 2 replicas, cluster name is _replicated_.
Checked both on _Atomic_ and _Ordinary_ databases
```
CREATE DATABASE repl ON CLUSTER replicated;
CREATE TABLE repl.t ON CLUSTER replicated
(
`a` UInt64,
`b` Enum8('' = -128, '0' = 0, '1' = 1, '2' = 2)
)
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/repl/t', '{replica}')
ORDER BY a;
INSERT INTO repl.t SELECT number, toInt8(abs(number % 3)) FROM system.numbers LIMIT 5000000000
```
To execute next queries immediately one after another I use _clickhouse-client_ :
```
clickhouse-client -m -n --query " \
SET mutations_sync = 2; \
SET replication_alter_partitions_sync = 2; \
ALTER TABLE repl.t ON CLUSTER replicated RENAME COLUMN b TO b_old; \
ALTER TABLE repl.t ON CLUSTER replicated ADD COLUMN b Enum8('' = -128, '0' = 0, '2' = 1, '1' = 2); \
ALTER TABLE repl.t ON CLUSTER replicated UPDATE b = CAST(CAST(b_old AS Int8) AS Enum8('' = -128, '0' = 0, '2' = 1, '1' = 2)) WHERE 1; \
ALTER TABLE repl.t ON CLUSTER replicated DROP COLUMN b_old; "
```
Here I get an error:
```
9000 341 Code: 341, e.displayText() = DB::Exception: Exception happened during execution of mutations \'0000000001, 0000000002\' with part \'all_4529_4664_3_4769\' reason: \'Code: 47, e.displayText() = DB::Exception: Missing columns: \'b_old\' while processing query: \'CAST(CAST(CAST(CAST(b_old, \'Int8\'), \'Enum8(\\\'\\\' = -128, \\\'0\\\' = 0, \\\'2\\\' = 1, \\\'1\\\' = 2)\'), \'Enum8(\\\'\\\' = -128, \\\'0\\\' = 0, \\\'2\\\' = 1, \\\'1\\\' = 2)\'), \'Enum8(\\\'\\\' = -128, \\\'0\\\' = 0, \\\'2\\\' = 1, \\\'1\\\' = 2)\'), b\', required columns: \'b_old\' \'b\' (version 21.5.6.6 (official build))\'. This error maybe retryable or not. In case of unretryable error, mutation can be killed with KILL MUTATION query (version 21.5.6.6 (official build))
```
**Expected behavior**
I expected _ALTER_ queries to be synchronous
Contributor guide
Assessment
This issue has not been assessed yet.