And if I can, any reason (performance/stability) why I shouldn't?
2 Answers
Note that if your table is using the InnoDB Plugin storage engine (which I highly recommend), if it's a secondary index (almost surely the case), you can still read from the table (i.e. it's non-blocking to SELECT
statements).
-
2MySQL 5.6 update (feb 2013): you can now read and write to the table with online DDL - dev.mysql.com/doc/refman/5.6/en/… Dec 18, 2013 at 4:55
-
@MorganTocker several years later, but your link is now broken... Jun 28, 2021 at 15:35
Yes you can. It will lock the table you're adding an index to while it's being created. If the table is large, it may take awhile as it has to read each row while building the index.
-
1Facebook has a solution for doing this online. Haven't tried it out myself: facebook.com/notes/mysql-at-facebook/…– esilverOct 13, 2011 at 22:34