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.5.
You can use a number of extensions to
TABLE for 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;
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,
TEXT columns), you can use
TABLE ... OPTIMIZE PARTITION to reclaim any
unused space and to defragment the partition data file.
ALTER TABLE t1 OPTIMIZE PARTITION p0, p1;
OPTIMIZE PARTITION on a given
partition is equivalent to running
REPAIR PARTITION on that partition.
Some MySQL storage engines, including
InnoDB, do not support
per-partition optimization; in these cases,
TABLE ... OPTIMIZE PARTITION rebuilds the entire
table. In MySQL 5.5.30 and later, running this statement on
such a table causes the entire table to rebuilt and
analyzed, and an appropriate warning to be issued. (Bug
#11751825, Bug #42822) Use
ALTER TABLE ... REBUILD
ALTER TABLE ... ANALYZE
PARTITION instead, to avoid this issue.
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;
You can check partitions for errors in much the same way
that you can use
TABLE with nonpartitioned tables.
ALTER TABLE trb3 CHECK PARTITION p1;
This command will tell you if the data or indexes in
p1 of table
t1 are corrupted. If this is the case,
TABLE ... REPAIR PARTITION to repair the
Each of the statements in the list just shown also supports the
ALL in place of the list of partition
ALL causes the statement to act
on all partitions in the table.
Beginning with MySQL 5.5.0, you can also truncate partitions
TABLE ... TRUNCATE PARTITION. This statement can be
used to delete all rows from one or more partitions in much the
same way that
deletes all rows from a table.
ALTER TABLE ... TRUNCATE PARTITION ALL
truncates all partitions in the table.
operations are not supported for subpartitions.
Copyright © 1997, 2014, Oracle and/or its affiliates. All rights reserved. Legal Notices