Comment 3 for bug 1062324

Revision history for this message
Ovais Tariq (ovais-tariq) wrote :

The workaround currently is to do the alter in two steps:

First add the new column, and optionally add an index if its an auto_increment column:
[root@ovaistariq-net msb_5_5_29]# pt-online-schema-change --alter "add column _id int unsigned not null auto_increment FIRST, add index (_id)" D=test,t=test,S=/tmp/mysql_sandbox5529.sock,u=msandbox,p=msandbox --execute
Altering `test`.`test`...
Creating new table...
Created new table test._test_new OK.
Altering new table...
Altered `test`.`_test_new` OK.
Creating triggers...
Created triggers OK.
Copying approximately 2 rows...
Copied rows OK.
Swapping tables...
Swapped original and new tables OK.
Dropping old table...
Dropped old table `test`.`_test_old` OK.
Dropping triggers...
Dropped triggers OK.
Successfully altered `test`.`test`.

Once the above finishes, drop the old primary key and the index added above, and then specify the new primary key:
[root@ovaistariq-net msb_5_5_29]# pt-online-schema-change --alter "drop primary key, add primary key (_id), drop index _id" D=test,t=test,S=/tmp/mysql_sandbox5529.sock,u=msandbox,p=msandbox --execute
Altering `test`.`test`...
Creating new table...
Created new table test._test_new OK.
Altering new table...
Altered `test`.`_test_new` OK.
Creating triggers...
Created triggers OK.
Copying approximately 2 rows...
Copied rows OK.
Swapping tables...
Swapped original and new tables OK.
Dropping old table...
Dropped old table `test`.`_test_old` OK.
Dropping triggers...
Dropped triggers OK.
Successfully altered `test`.`test`.