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 for
InnoDB, and (as of
OPTIMIZE TABLE does
not work for tables created using any other
storage engine and returns a result indicating this lack of
support. You can make
TABLE work for other storage engines by starting
mysqld with the
option. In this case,
TABLE is just mapped to
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.
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.
By default, the server writes
TABLE statements to the binary log so that they
replicate to replication slaves. To suppress logging, specify
NO_WRITE_TO_BINLOG keyword or
OPTIMIZE TABLE does not sort
R-tree indexes, such as spatial indexes on
POINT columns. (Bug #23578)