13.1.9.1 ALTER TABLE Partition Operations分区操作

Partitioning-related clauses for ALTER TABLE can be used with partitioned tables for repartitioning, to add, drop, discard, import, merge, and split partitions, and to perform partitioning maintenance.ALTER TABLE的分区相关子句可以与分区表一起使用,用于重新分区、添加、删除、放弃、导入、合并和拆分分区,以及执行分区维护。

It is possible for an ALTER TABLE statement to contain a PARTITION BY or REMOVE PARTITIONING clause in an addition to other alter specifications, but the PARTITION BY or REMOVE PARTITIONING clause must be specified last after any other specifications.ALTER TABLE语句可以在其他alter规范文档之外包含PARTITION BY子句或REMOVE PARTITIONING子句,但PARTITION BY子句或REMOVE PARTITIONING子句必须在任何其他规范文档之后最后指定。

The ADD PARTITION, DROP PARTITION, COALESCE PARTITION, REORGANIZE PARTITION, ANALYZE PARTITION, CHECK PARTITION, and REPAIR PARTITION options cannot be combined with other alter specifications in a single ALTER TABLE, since the options just listed act on individual partitions. ADD PARTITION(添加分区)、DROP PARTITION(删除分区)、COALESCE PARTITION(合并分区)、REORGANIZE PARTITION(重新组织分区)、ANALYZE PARTITION(分析分区)、CHECK PARTITION(检查分区)和REPAIR PARTITION(修复分区)选项不能与单个ALTER TABLE中的其他alter规范文档组合,因为刚才列出的选项作用于各个分区。For more information, see Section 13.1.9.1, “ALTER TABLE Partition Operations”.有关更多信息,请参阅第13.1.9.1节,“更改表分区操作”

Only a single instance of any one of the following options can be used in a given ALTER TABLE statement: PARTITION BY, ADD PARTITION, DROP PARTITION, TRUNCATE PARTITION, EXCHANGE PARTITION, REORGANIZE PARTITION, or COALESCE PARTITION, ANALYZE PARTITION, CHECK PARTITION, OPTIMIZE PARTITION, REBUILD PARTITION, REMOVE PARTITIONING.在给定的ALTER TABLE语句中只能使用以下任一选项的单个实例:PARTITION BYADD PARTITIONDROP PARTITIONTRUNCATE PARTITIONEXCHANGE PARTITIONREORGANIZE PARTITIONCOALESCE PARTITIONANALYZE PARTITIONCHECK PARTITIONOPTIMIZE PARTITIONREBUILD PARTITIONREMOVE PARTITIONING

For example, the following two statements are invalid:例如,以下两条语句无效:

ALTER TABLE t1 ANALYZE PARTITION p1, ANALYZE PARTITION p2;
ALTER TABLE t1 ANALYZE PARTITION p1, CHECK PARTITION p2;

In the first case, you can analyze partitions p1 and p2 of table t1 concurrently using a single statement with a single ANALYZE PARTITION option that lists both of the partitions to be analyzed, like this:在第一种情况下,您可以使用一条语句和一个ANALYZE PARTITION选项同时分析表t1的分区p1p2,该选项列出了要分析的两个分区,如下所示:

ALTER TABLE t1 ANALYZE PARTITION p1, p2;

In the second case, it is not possible to perform ANALYZE and CHECK operations on different partitions of the same table concurrently. 在第二种情况下,不可能同时对同一表的不同分区执行ANALYZECHECK操作。Instead, you must issue two separate statements, like this:相反,您必须发布两个单独的声明,如下所示:

ALTER TABLE t1 ANALYZE PARTITION p1;
ALTER TABLE t1 CHECK PARTITION p2;

REBUILD operations are currently unsupported for subpartitions. 子分区当前不支持REBUILD操作。The REBUILD keyword is expressly disallowed with subpartitions, and causes ALTER TABLE to fail with an error if so used.子分区明确禁止使用REBUILD关键字,如果使用REBUILD关键字,会导致ALTER TABLE失败并出现错误。

CHECK PARTITION and REPAIR PARTITION operations fail when the partition to be checked or repaired contains any duplicate key errors.当要检查或修复的分区包含任何重复的密钥错误时,CHECK PARTITIONREPAIR PARTITION操作失败。

For more information about these statements, see Section 24.3.4, “Maintenance of Partitions”.有关这些语句的更多信息,请参阅第24.3.4节,“分区的维护”