The main reason for optimizing your table is to reclaim unused space and to defragment the data file. You should optimize a table 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 have VARCHAR, BLOB, or TEXT columns). Deleted records are maintained in a linked list and subsequent INSERT operations reuse old row positions.
Hint: Just simply right-click the table and select Maintain Tables -> Optimize Tables.
Currently, MySQL supports optimizing only for MyISAM, InnoDB and BDB tables.
For MyISAM tables, 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.
Related topics:
Analyze Tables
Check Tables
Repair Tables