Skip to main content
This topic describes how to use the temporary partition feature. You can create temporary partitions on a partitioned table that already has defined partitioning rules and define new data distribution strategies for these temporary partitions. Temporary partitions can serve as temporary data carriers when you atomically overwrite data in a partition or when you adjust partitioning and bucketing strategies. For temporary partitions, you can reset data distribution strategies such as partition ranges, number of buckets, and properties such as the number of replicas, and the storage medium, to meet specific requirements. You can use the temporary partition feature in the following scenarios:
  • Atomic overwrite operation If you need to rewrite the data in a partition while ensuring that the data can be queried during the rewriting process, you can first create a temporary partition based on the original formal partition, and load the new data into the temporary partition. Then you can use the replace operation to atomically replace the original formal partition with the temporary partition. For atomic overwrite operations on non-partitioned tables, see ALTER TABLE - SWAP.
  • Adjust partition data query concurrency If you need to modify the number of buckets for a partition, you can first create a temporary partition with the same partition range as the original formal partition and specify the new number of buckets. Then, you can use the INSERT INTO command to load the data of the original formal partition into the temporary partition. Finally, you can use the replace operation to atomically replace the original formal partition with the temporary partition.
  • Modify partitioning rules If you want to modify a partitioning strategy, such as merging partitions or splitting a large partition into multiple smaller partitions, you can first create temporary partitions with the expected merged or split ranges. Then, you can use the INSERT INTO command to load the data of the original formal partitions into the temporary partitions. Finally, you can use the replace operation to atomically replace the original formal partitions with the temporary partitions.

Create temporary partitions

You can create one or more partitions at a time by using the ALTER TABLE command.

Syntax

Create a single temporary partition

Create multiple partitions at a time

Parameters

partition_desc: specifies the number of buckets and properties for temporary partitions, such as the number of replicas and the storage medium.

Examples

Create a temporary partition tp1 in the table site_access and specify its range as [2020-01-01, 2020-02-01) by using the VALUES [(...), (...)] syntax.
Create a temporary partition tp2 in the table site_access and specify its upper bound as 2020-03-01 by using the VALUES LESS THAN (...) syntax. The database uses the upper bound of the previous temporary partition as the lower bound of this temporary partition, generating a temporary partition with the left-closed and right-open range of [2020-02-01, 2020-03-01).
Create a temporary partition tp3 in the table site_access, specify its upper bound as 2020-04-01 by using the VALUES LESS THAN (...) syntax, and specify the number of replicas as 1.
Create multiple partitions at a time in the table site_access by using the START (...) END (...) EVERY (...) syntax, and specify the range of these partitions as [2020-04-01, 2021-01-01) with a monthly partition granularity.

Usage notes

  • The partition column for a temporary partition must be the same as the partition column for the original formal partition based on which you create the temporary partition and cannot be changed.
  • The name of a temporary partition cannot be the same as the name of any formal partition or other temporary partition.
  • The ranges of all temporary partitions in a table cannot overlap, but the ranges of a temporary partition and a formal partition can overlap.

Show temporary partitions

You can view the temporary partitions by using the SHOW TEMPORARY PARTITIONS command.

Load data into temporary partitions

You can load data into one or more temporary partitions by using the INSERT INTO command, STREAM LOAD, or BROKER LOAD.

Load data by using INSERT INTO command

Example:
For detailed syntax and parameter descriptions, see INSERT INTO.

Load data by using STREAM LOAD

Example:
For detailed syntax and parameter descriptions, see STREAM LOAD.

Load data by using BROKER LOAD

Example:
Note that StorageCredentialParams represents a group of authentication parameters which vary depending on the authentication method you choose. For detailed syntax and parameter descriptions, see Broker Load.

Load data by using ROUTINE LOAD

Example:
For detailed syntax and parameter descriptions, see CREATE ROUTINE LOAD.

Query data in temporary partitions

You can use the SELECT statement to query data in specified temporary partitions.
You can use the JOIN clause to query data in temporary partitions from two tables.

Replace original formal partitions with temporary partitions

You can use the ALTER TABLE statement to replace the original formal partition with a temporary partition, thereby creating a new formal partition.
NOTE The original formal partition and temporary partition that you operated in the ALTER TABLE statement are deleted and cannot be recovered.

Syntax

Parameters

  • strict_range Default value: true. When this parameter is set to true, the unions of ranges of all original formal partitions must be exactly the same as the unions of ranges of the temporary partitions that are used for replacement. When this parameter is set to false, you only need to make sure that the ranges of the new formal partitions do not overlap with other formal partitions after replacement.
    • Example 1: In the following example, the unions of the original formal partitions p1, p2, and p3 are the same as the unions of the temporary partitions tp1 and tp2, and you can use tp1 and tp2 to replace p1, p2, and p3.
    • Example 2: In the following example, the union of ranges of the original formal partition differs from the union of ranges of the temporary partitions. If the value of the parameter strict_range is set to true, the temporary partitions tp1 and tp2 cannot replace the original formal partition p1. If the value is set to false, and the ranges [10, 30) and [40, 50) of the temporary partitions do not overlap with other formal partitions, the temporary partitions can replace the original formal partition.
  • use_temp_partition_name Default value: false. If the number of original formal partitions is the same as the number of temporary partitions used for replacement, the names of the new formal partitions remain unchanged after replacement when this parameter is set to false. When this parameter is set to true, the names of the temporary partitions are used as the names of the new formal partitions after replacement. In the following example, the partition name of the new formal partition remains p1 after replacement when this parameter is set to false. However, its related data and properties are replaced with the data and properties of the temporary partition tp1. When this parameter is set to true, the partition name of the new formal partition is changed to tp1 after replacement. The original formal partition p1 no longer exists.
    If the number of formal partitions to be replaced is different from the number of temporary partitions used for replacement, and this parameter remains the default value false, the value false of this parameter is invalid. In the following example, after replacement, the name for the new formal partition is changed to tp1, and the original formal partitions p1 and p2 no longer exist.

Examples

Replace the original formal partition p1 with the temporary partition tp1.
Replace the original formal partitions p2 and p3 with the temporary partitions tp2 and tp3.
Replace the original formal partitions p4 and p5 with the temporary partitions tp4 and tp5, and specify the parameters strict_range as false and use_temp_partition_name as true.

Usage notes

  • When a table has temporary partitions, you cannot use the ALTER command to perform Schema Change operations on the table.
  • When performing Schema Change operations on a table, you cannot add temporary partitions to the table.

Delete temporary partitions

Use the following command to delete the temporary partition tp1.
Take note of the following limits:
  • If you use the DROP command to directly delete a database or table, you can recover the database or table within a limited time period by using the RECOVER command. However, temporary partitions cannot be recovered.
  • After using the ALTER command to delete a formal partition, you can recover it within a limited time period by using the RECOVER command. Temporary partitions are not bound with formal partitions, so operations on temporary partitions do not affect formal partitions.
  • After using the ALTER command to delete a temporary partition, you cannot recover it by using the RECOVER command.
  • When using the TRUNCATE command to delete data in a table, the temporary partitions of the table are deleted and cannot be recovered.
  • When using the TRUNCATE command to delete data in a formal partition, the temporary partitions are not affected.
  • The TRUNCATE command cannot be used to delete data in a temporary partition.