The OPTIMIZE TABLE statement provides allows MySQL DBAs to
reorganize physical table storage in order to achieve two main
goals:
- Improve IO efficiency for reads/writes against the table,
- Reclaim unused storage space.
For InnoDB tables, OPTIMIZE is implemented via ALTER TABLE
operation. This is true in all MySQL versions, however MySQL
5.7.4 introduced a change that may catch many users off guard and
is therefore worth highlighting. Theory The InnoDB storage engine
does not directly support OPTIMIZE. Instead, when a DBA invokes
OPTIMIZE TABLE x, InnoDB executes ALTER TABE x FORCE. In
MySQL versions prior to 5.7.4, OPTIMIZE is not an online
operation i.e. the table is locked and DML operations against the
table are not allowed until OPTIMIZE finishes.
MySQL 5.7.4 introduces a significant change around OPTIMIZE,
namely the ALTER TABLE operation now uses …