Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
casassg opened this issue Apr 24, 2023 · 0 comments

Comments

@casassg
Copy link

casassg commented Apr 24, 2023

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    |
+----+------+------+------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant