Addressing Hot Schema Changes in MySQL
As ones data model evolves changing the database schema becomes painful, especially for big databases where the table must be taken offline. Fortunately, Tokutek introduced online schema changes starting in TokuDB v5.0.
A typical schema change involves adding or deleting a column from a table. These operations usually require the table to be rebuilt offline since the row format is different. In contrast to other storage engines however, column addition or deletion with TokuDB just inserts a broadcast update message into the fractal tree data structure, rather than rebuilding the table. This message defers changing rows from the old format to the new format and is executed after the alter table operation is long gone. The trick is to allow the storage engine to determine that the column addition or deletion does not require a full table rebuild.
Many customers have found that as their business evolves, new queries need a new index on the table to get good performance. Now, adding an index usually requires the index to be built with the table offline. In contrast to other storage engines, adding an index to a TokuDB table occurs while other transactions can read and modify the table. Here, the trick is to allow the storage engine to change the table’s metadata lock for the alter table operation, which allows other transactions to read and write the table while the hot index is being constructed. These other transactions will not see the new index until it has been built.
We got all of this to work (and made a lot of customers happy) and to do it we patched MySQL 5.1 with the online alter table implementation found in MySQL cluster server. This patch is quite large and can be a challenge to maintain. Therefore, we’re excited to see online schema changes on the MySQL 5.6 roadmap.
Currently, the MySQL 5.6.6 Labs release has added the infrastructure for inplace and online schema changes. Given this, porting the TokuDB hot schema feature to MySQL 5.6.6 was easy. We were able to get TokuDB’s hot schema features working in MySQL 5.6.6 in about a week. We look forward to hopefully seeing the online alter table make the GA of MySQL 5.6.