1、先来看看多次删除插入操作后的表索引情况
mysql> SHOW INDEX FROM `tbl_name`;
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table    | Non_unique | Key_name   | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| tbl_name |          0 | PRIMARY    |            1 | StepID      | A         |           1 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | FlowID     |            1 | FlowID      | A         |           1 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerCount |            1 | WagerCount  | A         |           1 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerID_3  |            1 | WagerID     | A         |           1 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerID_3  |            2 | StepType    | A         |           1 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerID_3  |            3 | ParamResult | A         |           1 |      255 | NULL   |      | BTREE      |         |
| tbl_name |          1 | StepType_2 |            1 | StepType    | A         |           1 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | StepType_2 |            2 | ParamResult | A         |           1 |      255 | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerID_2  |            1 | WagerID     | A         |           1 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerID_2  |            2 | StepType    | A         |           1 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerID_2  |            3 | ParamResult | A         |           1 |      255 | NULL   |      | BTREE      |         |
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
11 rows in set (0.01 sec)
2、优化表
mysql> optimize table tbl_name;
+---------------+----------+----------+----------+
| Table         | Op       | Msg_type | Msg_text |
+---------------+----------+----------+----------+
| test.tbl_name | optimize | status   | OK       |
+---------------+----------+----------+----------+
1 row in set (40.60 sec)
3、再来看看优化后的效果
mysql> SHOW INDEX FROM `tbl_name`;
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table    | Non_unique | Key_name   | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| tbl_name |          0 | PRIMARY    |            1 | StepID      | A         |      172462 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | FlowID     |            1 | FlowID      | A         |       86231 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerCount |            1 | WagerCount  | A         |        4311 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerID_3  |            1 | WagerID     | A         |       86231 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerID_3  |            2 | StepType    | A         |      172462 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerID_3  |            3 | ParamResult | A         |      172462 |      255 | NULL   |      | BTREE      |         |
| tbl_name |          1 | StepType_2 |            1 | StepType    | A         |           9 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | StepType_2 |            2 | ParamResult | A         |       86231 |      255 | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerID_2  |            1 | WagerID     | A         |       86231 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerID_2  |            2 | StepType    | A         |      172462 |     NULL | NULL   |      | BTREE      |         |
| tbl_name |          1 | WagerID_2  |            3 | ParamResult | A         |      172462 |      255 | NULL   |      | BTREE      |         |
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
最后,来看看手册中关于 OPTIMIZE 的描述: