Not the answer you need?
Register and ask your own question!

How to add new column in a big table

xsaucexsauce EntrantCurrent User Role Participant
I am working on finding the fastest way to add new column in a big table. The big table has about 30 millions rows and 30 columns, and another three big tables refers to its primary key. Our database is Percona 5.6.28. Engine is Innodb, I know this is a hard work in MySQL.
The current way I thought after some tests:
1. set sql_log_bin = 0
2. Create new table with new column and no second indexes.
3. Insert into old table select new table. It takes about 1 hours 30 minutes.
4. Add 7 indexes same as old table's ones to new table once, It takes about 5 hours 30 minutes.
5. set FOREIGN_KEY_CHECKS=0, drop old table, It takes 3 seconds.
6. Rename new table name to old table name

The process cost about 7 hours.
step 4,5 is same as pt-online-schema-change tools -drop swap.

Until now, I don't know how to improve the process. I want to short time to 4 hours. Is it possible?
Sign In or Register to comment.

MySQL, InnoDB, MariaDB and MongoDB are trademarks of their respective owners.
Copyright ©2005 - 2020 Percona LLC. All rights reserved.