Introduction
Range partitioning is appropriate for frequently queried data based on continuous date/numerical ranges. Additionally, it can be applied in some special cases where historical data needs to be partitioned by month, and recent data needs to be partitioned by day. You need to explicitly define the data partitioning columns and establish the mapping relationship between partitions and ranges of partitioning column values. During data loading, the database assigns the data to the corresponding partitions based on the ranges to which the data partitioning column values belong. As for the data type of the partitioning columns, before v3.3.0, range partitioning only supports partitioning columns of date and integer types. Since v3.3.0, three specific time functions can be used as partition columns. When explicitly defining the mapping relationship between partitions and ranges of partitioning column values, you need to first use a specific time function to convert partitioning column values of timestamps or strings into date values, and then divide the partitions based on the converted date values. Info- If the partitioning column value is a timestamp, you need to use the from_unixtime or from_unixtime_ms function to convert a timestamp to a date value when dividing the partitions. When the from_unixtime function is used, the partitioning column only supports INT and BIGINT types. When the from_unixtime_ms function is used, the partitioning column only supports BIGINT type.
- If the partitioning column value is a string (STRING, VARCHAR, or CHAR type), you need to use the str2date function to convert the string to a date value when dividing the partitions.
Usage
Syntax
Parameters
Example
-
Create partitions by manually defining value ranges based on date type partitioing column.
-
Create partitions by manually defining value ranges based on integer type partitioing column.
-
Create multiple partition with the same date interval.
-
Create multiple partition with different date intervals.
-
Create multiple partition with the same integer interval.
-
Create multiple partition with different integer intervals.
-
Use from_unixtime to transform timestamp (string) type partition column into date type.
-
Use str2date to transform string type partition column into date type.
Dynamic partitioning
The database supports dynamic partitioning, which can automatically manage the time to life (TTL) of partitions, such as partitioning new input data in tables and deleting expired partitions. This feature significantly reduces maintenance costs.Enable dynamic partitioning
Take tablesite_access as an example. To enable dynamic partitioning, you need to configure the PROPERTIES parameter. For information about the configuration items, see CREATE TABLE.
PROPERTIES:
Note
When the partition column is the INT type, its format must be
yyyyMMdd, regardless of the partition time granularity.
FE configuration:
dynamic_partition_check_interval_seconds: the interval for scheduling dynamic partitioning. The default value is 600s, which means that the partition situation is checked every 10 minutes to see whether the partitions meet the dynamic partitioning conditions specified in PROPERTIES. If not, the partitions will be created and deleted automatically.
View dynamic partitions
After you enable dynamic partitions for a table, the input data is continuously and automatically partitioned. You can view the current partitions by using the following statement. For example, if the current date is 2020-03-25, you can only see partitions in the time range from 2020-03-25 to 2020-03-28.dynamic_partition.history_partition_num to define the number of historical partitions to be created. For example, if you set dynamic_partition.history_partition_num to 3 during table creation and the current date is 2020-03-25, you will only see partitions in the time range from 2020-03-22 to 2020-03-28.
Modify properties of dynamic partitioning
You can use the ALTER TABLE statement to modify properties of dynamic partitioning, such as disabling dynamic partitioning. Take the following statement as an example.- To check the properties of dynamic partitioning of a table, execute the SHOW CREATE TABLE statement.
- You can also use the ALTER TABLE statement to modify other properties of a table.