OPTIMIZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE
OPTIMIZE TABLE should be used if
you have deleted a large part of a table or if you have made
many changes to a table with variable-length rows (tables that
TEXT columns). Deleted rows are
maintained in a linked list and subsequent
INSERT operations reuse old row
positions. You can use
TABLE to reclaim the unused space and to defragment
the data file. After extensive changes to a table, this
statement may also improve performance of statements that use
the table, sometimes significantly.
OPTIMIZE TABLE works
InnoDB tables. It
does not work for tables created using any
other storage engine.
OPTIMIZE TABLE works as follows:
If the table has deleted or split rows, repair the table.
If the index pages are not sorted, sort them.
If the table's statistics are not up to date (and the repair could not be accomplished by sorting the index), update them.
That was also the case for
before MySQL 4.1.3. As of 4.1.3,
TABLE is mapped to
TABLE, which rebuilds the table to update index
statistics and free unused space in the clustered index.
OPTIMIZE TABLE returns a result
set with the following columns.
|The table name|
|An informational message|
Note that MySQL locks the table during the time
OPTIMIZE TABLE is running.
Before MySQL 4.1.1,
TABLE statements are not written to the binary log. As
of MySQL 4.1.1,
statements are written to the binary log so that they will be
replicated to replication slaves. Logging can be suppressed with
NO_WRITE_TO_BINLOG keyword or