Fails to rename column when alter renames + re-adds new column with prev name

未关闭
#1,273 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 10 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
go, mysql
领域
database

调研方向

首先在 MySQL 中重现报告的 ALTER 语句,并将其结果与 gh-ost 的结果进行比较。然后跟踪 gh-ost 对重命名并重新添加列的 ALTER 语句的处理过程。完成的标准是,重命名后的 n1 列保留原始值,而新添加的 c1 列为 NULL,这与 MySQL 的常规行为一致。

由索引模型根据 Issue 内容生成。

描述

When renaming a column and then re-creating it within the same ALTER statement, gh-ost deletes the entiretity of the name-changed column.

Example:

-- regular alter table (expected behaviour)
CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY auto_increment, c1 VARCHAR(100), c2 VARCHAR(100));
INSERT INTO t1 (c1, c2) VALUES ('a', 'b'), ('c', 'd'), ('e', 'f');
ALTER TABLE t1 RENAME COLUMN c1 TO n1, ADD COLUMN c1 varchar(100);
SELECT * FROM t1;
+----+------+------+------+
| id | n1   | c2   | c1   |
+----+------+------+------+
|  1 | a    | b    | NULL |
|  2 | c    | d    | NULL |
|  3 | e    | f    | NULL |
+----+------+------+------+

Using gh-ost:

go run . \
--max-load=Threads_running=25 \
--critical-load=Threads_running=1000 \
--chunk-size=1000 \
--user="[REDACTED]" \
--password="[REDACTED]" \
--host="127.0.0.1" \
--port=8030 \
--allow-on-master \
--database="test" \
--table="t1" \
--verbose \
--initially-drop-old-table \
--ok-to-drop-table \
--execute  --initially-drop-ghost-table --alter="RENAME COLUMN c1 TO n1, ADD COLUMN c1 varchar(100)"

Result:

+----+------+------+------+
| id | n1   | c2   | c1   |
+----+------+------+------+
|  1 | NULL | b    | a    |
|  2 | NULL | d    | c    |
|  3 | NULL | f    | e    |
+----+------+------+------+
主要语言
Go
星标
13.6k
派生
1.4k
平均合并
9 天 19 小时
30 天内合并 PR
1

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/gh-ost 的其他 Issue

查看 github/gh-ost 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。