A number of table and partition maintenance tasks can be carried out using SQL statements intended for such purposes on partitioned tables in MySQL 5.1.
Table maintenance of partitioned tables can be accomplished using the statements
ANALYZE TABLE, and
REPAIR TABLE, which are supported for partitioned tables as of MySQL 5.1.27.
Also beginning with MySQL 5.1.27, you can use a number of extensions to
ALTER TABLEfor performing operations of this type on one or more partitions directly, as described in the following list:
Rebuilding partitions. Rebuilds the partition; this has the same effect as dropping all records stored in the partition, then reinserting them. This can be useful for purposes of defragmentation.
ALTER TABLE t1 REBUILD PARTITION p0, p1;
Optimizing partitions. If you have deleted a large number of rows from a partition or if you have made many changes to a partitioned table with variable-length rows (that is, having
TEXTcolumns), you can use
ALTER TABLE ... OPTIMIZE PARTITIONto reclaim any unused space and to defragment the partition data file.
ALTER TABLE t1 OPTIMIZE PARTITION p0, p1;
OPTIMIZE PARTITIONon a given partition is equivalent to running
ANALYZE PARTITION, and
REPAIR PARTITIONon that partition.
Analyzing partitions. This reads and stores the key distributions for partitions.
ALTER TABLE t1 ANALYZE PARTITION p3;
Repairing partitions. This repairs corrupted partitions.
ALTER TABLE t1 REPAIR PARTITION p0,p1;
Checking partitions. You can check partitions for errors in much the same way that you can use
CHECK TABLEwith nonpartitioned tables.
ALTER TABLE trb3 CHECK PARTITION p1;
This command will tell you if the data or indexes in partition
t1are corrupted. If this is the case, use
ALTER TABLE ... REPAIR PARTITIONto repair the partition.
Each of the statements in the list just shown also supports the keyword
ALLin place of the list of partition names. Using
ALLcauses the statement to act on all partitions in the table.
ALTER TABLE ... ANALYZE PARTITION,
ALTER TABLE ... CHECK PARTITION,
ALTER TABLE ... OPTIMIZE PARTITION, and
ALTER TABLE ... REPAIR PARTITIONwere originally introduced in MySQL 5.1.5, but did not work properly and were disabled in MySQL 5.1.24. They were re-introduced in MySQL 5.1.27. (Bug#20129) The use of these partitioning-specific
ALTER TABLEstatements with tables which are not partitioned is not supported; beginning with MySQL 5.1.31, it is expressly disallowed. (Bug#39434)
ALTER TABLE ... REBUILD PARTITIONwas also introduced in MySQL 5.1.5.