This is a follow-up of Can I use pt-online-schema-change to change a primary key?.
Goal: I'd like to ALTER a table's primary key using pt-online-schema-change. Specifically I want migrate from single-column primary key (a) to a composite primary key (a,b) (where a is the same column in both cases).
Idea: I understand pt-online-schema-change generally doesn't work when both primary key and unique key is missing. My plan is therefor to do the following:
- Add a unique key:
pt-online-schema-change --alter "ADD UNIQUE tmp_unique_key(a)" D=mydb,t=mytable,u=root --execute - Modify the primary key:
pt-online-schema-change --alter "DROP PRIMARY KEY, ADD PRIMARY KEY (a, b)" D=mydb,t=mytable,u=root --execute --check-alter. (--check-alteris needed to ignore theDROP PRIMARY KEYerror) - Modify the unique key:
pt-online-schema-change --alter "DROP KEY tmp_unique_key" D=mydb,t=mytable,u=root --execute.
Implementation: I've tested the above on a tiny local table and it worked without a glitch.
Question: Assuming I have the disk space to hold the temporary unique primary key and can handle the load etc., are there any problems running this on a large table?