OceanBase Database allows you to predefine automatic partitioning rules, enabling the system to automatically split partitions when data grows to a certain threshold. This feature ensures that tables can scale automatically as data increases, avoiding issues such as unbalanced loads and degraded performance caused by oversized partitions.
Supported scenarios
The current version supports automatic partition splitting only for primary key tables with partitions partitioned by RANGE or RANGE COLUMNS.
Limitations and considerations
- Automatic partition splitting is not supported for tables partitioned by LIST or HASH.
- Automatic partition splitting is not supported for tables with subpartitions.
- Automatic partition splitting is not supported if the partition key of the table being automatically split does not match the prefix of the primary key.
- Automatic partition splitting is not supported for tables without a primary key.
- Automatic partition splitting is not supported for columnstore tables.
- Automatic partition splitting is not supported for columnstore replicas.
- If the table is in a
TABLEGROUP(table group) that contains multiple tables, automatic partition splitting is not supported. However, if theTABLEGROUPcontains only this table, automatic partition splitting is supported. - Automatic partition splitting is not supported for materialized views.
- Automatic partition splitting is not supported for full-text indexes.
- Automatic partition splitting is not supported for GIS indexes.
- Automatic partition splitting is not supported for vector indexes.
- Starting from OceanBase Database V4.3.5 BP2, the global_index_auto_split_policy parameter is supported. This parameter is used to control whether the automatic partitioning feature is enabled for newly created global indexes. If automatic partitioning is enabled for a newly created global index, the partitioning rules will be regenerated based on the data volume, that is, pre-splitting will occur.
Automatic partition splitting at the table level
You can configure automatic partitioning at the table level by using the SIZE clause when creating a table.
Syntax for creating a table with automatic partition splitting
CREATE TABLE table_name (column_definition_list, PRIMARY KEY(column_name_list))
PARTITION BY RANGE [COLUMNS]([column_name_list]) [SIZE('size_value')]
[(range_partition_list)];
column_definition_list:
column_definition[, column_definition ...]
column_name_list:
column_name[, column_name ...]
range_partition_list:
PARTITION partition_name VALUES LESS THAN (value_list)[, PARTITION partition_name VALUES LESS THAN (value_list) ...]
value_list:
value[, value ...]
Parameters
| Parameter | Description |
|---|---|
| table_name | The name of the table. |
| column_definition_list | The list of column definitions, including column names, data types, and constraints. For more information, see CREATE TABLE. |
| PRIMARY KEY | The primary key of the table. |
| PARTITION BY RANGE [COLUMNS]([column_name_list]) | The pre-partitioning key. When automatic partition splitting is triggered, the specified pre-partitioning key is used as the actual partitioning key (if column_name_list is not specified, the primary key is used as the partitioning key).
Notice
|
| SIZE('size_value') | (Optional) The threshold for partition splitting. If the SIZE() clause is not specified, the value of the auto_split_tablet_size parameter at the tenant level is used as the default value. size_value can be set to unlimited, which indicates that partition splitting is not triggered and no new automatic partition splitting task is scheduled. |
| range_partition_list | (Optional) Predefined partitioning positions (partitioning rules).
NoticeIf you specify predefined partitioning positions, you must specify the pre-partitioning key. Otherwise, an error is returned. |
Syntax for modifying automatic partition splitting attributes
ALTER TABLE table_name
PARTITION BY RANGE [COLUMNS]([column_name_list]) [SIZE('size_value')]
[(range_partition_list)];
column_name_list:
column_name[, column_name ...]
range_partition_list:
PARTITION partition_name VALUES LESS THAN (value_list)[, PARTITION partition_name VALUES LESS THAN (value_list) ...]
value_list:
value[, value ...]
Note
If you execute the ALTER TABLE ... PARTITION BY ... statement without specifying a partitioning rule, the automatic partition splitting attributes of the table are modified in online DDL mode, which does not affect the existing partitioning definitions.
Parameters
| Parameter | Description |
|---|---|
| column_name_list | The pre-partitioning key of a non-partitioned table. When you execute the ALTER TABLE statement to modify the automatic partition splitting attributes of a non-partitioned table, if the pre-partitioning key is specified in the RANGE() clause, the corresponding records in the schema are modified; otherwise, the original settings are retained.
NoticeIf you specify multiple columns as the pre-partitioning key, you must use |
| SIZE('size_value') | (Optional) The threshold for partition splitting. When size_value is set to unlimited, partition splitting is not triggered, and no new automatic partition splitting task is scheduled. |
| range_partition_list | (Optional) The partitioning rules. If you do not specify the SIZE clause but specify partitioning definitions, only the partitioning rules are modified, and the existing automatic partition splitting definitions are retained. |
Automatic partition splitting at the tenant level
You can configure the enable_auto_split and auto_split_tablet_size parameters at the tenant level to control automatic partition splitting for tables that meet the criteria within a tenant. If the SIZE clause is omitted when creating a table, the system determines whether the table will use automatic partitioning based on the following tenant-level parameters (by default, the primary key column is used as the partitioning key):
- enable_auto_split: A tenant-level parameter. The value specifies whether to enable automatic partition splitting for the tenant. The default value is
false. - auto_split_tablet_size: A tenant-level parameter. The value specifies the threshold for triggering automatic partition splitting after automatic partition splitting is enabled for the tenant. The default value is 128 MB.
If you do not specify the SIZE clause and set enable_auto_split to true, automatic partition splitting is enabled for only tables that meet the partitioning criteria. For example, when you create a subpartitioned table, a table without a primary key, or a table whose partitioning key is different from the primary key prefix, the table is created as a non-automatic partitioned table (if you manually specify special DDL statements for automatic partition splitting, an error is returned).
Note
You can query the automatic partition splitting attributes of a table by using the information_schema.TABLES view or the oceanbase.CDB_TABLES view in the system tenant.
Automatic partition splitting behavior
DDL operations for automatic partition splitting
- Modify partitioning rules: Only changes to partitioning rules that use range partitioning by primary key are supported. Other partitioning rule modifications are not allowed.
- Modify the primary key: The primary key can only be modified if the automatic subpartitioning key remains a prefix of the primary key.
- Column operations: Limitations on pre-partitioning keys are the same as those on partitioning keys.
Note
The limitations on other DDL operations are the same as those on non-automatic partitioned tables.
DML behavior
During partition splitting, the source and destination schemas coexist, and DML operations on both partitions are treated as operating on the same dataset. Specifically, writes and queries on the source partition are redirected to the corresponding destination partition, while writes and queries on the destination partition account for forwarded writes from the source partition. The following table outlines the behavior of DML operations in different scenarios.
| Scenario | DML on the source partition (INSERT INTO t1 PARTITION(p0) ...) | DML involving the source partition (SELECT * FROM t1) | DML on the destination partition | DML involving the destination partition |
|---|---|---|---|---|
| Before the partition splitting transaction is committed | Normal | Normal | Error. The behavior is the same as that for operations on non-existent partitions. | Not applicable. |
| During partition splitting | May result in an error. The behavior is the same as that for operations on non-existent partitions. | No error. The system retries write and query statements that fail due to stream switching. | Normal | Normal |
| After the partition splitting transaction is committed | Error. The behavior is the same as that for operations on non-existent partitions. | Not applicable. | Normal | Normal |
Examples
Example 1: Create an automatically partitioned table
Disable automatic partitioning.
AlTER SYSTEM SET enable_auto_split = FALSE;Note
You can execute
SHOW PARAMETERS LIKE 'enable_auto_split';to check whether automatic partitioning is enabled.Create an automatically partitioned table named
test1_tbl1without specifying a prepartitioning key and set the split threshold to 10 GB.CREATE TABLE test1_tbl1 (col1 INT, col2 INT, col3 VARCHAR(30), PRIMARY KEY(col1, col2)) PARTITION BY RANGE() SIZE('10GB');Create an automatically partitioned table named
test1_tbl2with a prepartitioning key ofcol1and a split threshold of 10 GB.CREATE TABLE test1_tbl2 (col1 INT, col2 INT, col3 VARCHAR(30), PRIMARY KEY(col1, col2)) PARTITION BY RANGE(col1) SIZE('10GB');Create an automatically partitioned table named
test1_tbl3without specifying a prepartitioning key or a split threshold (the split threshold will use the value ofauto_split_tablet_sizeby default).CREATE TABLE test1_tbl3 (col1 INT, col2 INT, col3 VARCHAR(30), PRIMARY KEY(col1, col2)) PARTITION BY RANGE();Create an automatically partitioned table named
test1_tbl4with prepartitioning keys ofcol1andcol2, a split threshold of 10 GB, and partitioning points ofP0,P1,P2, andP3.CREATE TABLE test1_tbl4 (col1 INT, col2 INT, col3 VARCHAR(30), PRIMARY KEY(col1, col2)) PARTITION BY RANGE COLUMNS(col1, col2) SIZE('10GB') (PARTITION P0 VALUES LESS THAN (100, MAXVALUE), PARTITION P1 VALUES LESS THAN (500, MAXVALUE), PARTITION P2 VALUES LESS THAN (800, MAXVALUE), PARTITION P3 VALUES LESS THAN (MAXVALUE, MAXVALUE));View the automatic partitioning attributes of the table.
SELECT TABLE_SCHEMA, TABLE_NAME, AUTO_SPLIT, AUTO_SPLIT_TABLET_SIZE FROM information_schema.TABLES WHERE TABLE_NAME LIKE "test1%" ORDER BY TABLE_NAME;The return result is as follows:
+--------------+------------+------------+------------------------+ | TABLE_SCHEMA | TABLE_NAME | AUTO_SPLIT | AUTO_SPLIT_TABLET_SIZE | +--------------+------------+------------+------------------------+ | db_test | test1_tbl1 | TRUE | 10737418240 | | db_test | test1_tbl2 | TRUE | 10737418240 | | db_test | test1_tbl3 | TRUE | 134217728 | | db_test | test1_tbl4 | TRUE | 10737418240 | +--------------+------------+------------+------------------------+ 4 rows in set
Example 2: Modify the automatic partitioning attributes of a table
Create an automatically partitioned table named
test2_tbl1with a prepartitioning key ofcol1and a split threshold of 10 GB.CREATE TABLE test2_tbl1 (col1 INT, col2 INT, col3 VARCHAR(30), PRIMARY KEY(col1, col2)) PARTITION BY RANGE(col1) SIZE('10GB');Modify the split threshold of the
test2_tbl1table to 1 GB.ALTER TABLE test2_tbl1 PARTITION BY RANGE() SIZE('1GB');Or
ALTER TABLE test2_tbl1 PARTITION BY RANGE(col1) SIZE('1GB');Create an automatically partitioned table named
test2_tbl2with a prepartitioning key ofcol1, a split threshold of 10 GB, and partitioning points ofp0(rows with values less than 100),p1(rows with values greater than or equal to 100 and less than 200), andp_max(rows with values greater than or equal to 200).CREATE TABLE test2_tbl2 (col1 INT, col2 INT, col3 VARCHAR(30), PRIMARY KEY(col1, col2)) PARTITION BY RANGE(col1) SIZE('10GB') (PARTITION p0 VALUES LESS THAN(100), PARTITION p1 VALUES LESS THAN(200), PARTITION p_max VALUES LESS THAN (MAXVALUE));Modify the split threshold of the
test2_tbl2table to 5 GB and change the partitioning points top0(rows with values less than 300) andp_max(rows with values greater than or equal to 300).ALTER TABLE test2_tbl2 PARTITION BY RANGE(col1) SIZE('5GB') (PARTITION p0 VALUES LESS THAN(300), PARTITION p_max VALUES LESS THAN (MAXVALUE));Create an automatically partitioned table named
test2_tbl3with a prepartitioning key ofcol1and a split threshold of 10 GB.CREATE TABLE test2_tbl3 (col1 INT, col2 INT, col3 VARCHAR(30), PRIMARY KEY(col1, col2)) PARTITION BY RANGE(col1) SIZE('10GB');Disable automatic partitioning for the
test2_tbl3table. This change does not affect existing partitions, and no new automatic partitioning splits will be scheduled.ALTER TABLE test2_tbl3 PARTITION BY RANGE() SIZE('unlimited');Create an automatically partitioned table named
test2_tbl4with a prepartitioning key ofcol1and a split threshold of 10 GB.CREATE TABLE test2_tbl4 (col1 INT, col2 INT, col3 VARCHAR(30), PRIMARY KEY(col1, col2)) PARTITION BY RANGE(col1) SIZE('10GB');Change the prepartitioning key of the
test2_tbl4table fromcol1tocol1,col2.ALTER TABLE test2_tbl4 PARTITION BY RANGE COLUMNS(col1,col2) SIZE('10GB');Create a non-partitioned table named
test2_tbl5.CREATE TABLE test2_tbl5 (col1 INT, col2 INT, col3 VARCHAR(30), PRIMARY KEY(col1, col2));Execute the
ALTER TABLEstatement without theSIZEclause to convert thetest2_tbl5table to an automatically partitioned table. The split threshold will use the value ofauto_split_tablet_sizeby default.ALTER TABLE test2_tbl5 PARTITION BY RANGE COLUMNS(col1);View the automatic partitioning attributes of the table.
SELECT TABLE_SCHEMA, TABLE_NAME, AUTO_SPLIT, AUTO_SPLIT_TABLET_SIZE FROM information_schema.TABLES WHERE TABLE_NAME LIKE "test2%" ORDER BY TABLE_NAME;The return result is as follows:
+--------------+------------+------------+------------------------+ | TABLE_SCHEMA | TABLE_NAME | AUTO_SPLIT | AUTO_SPLIT_TABLET_SIZE | +--------------+------------+------------+------------------------+ | db_test | test2_tbl1 | TRUE | 1073741824 | | db_test | test2_tbl2 | TRUE | 5368709120 | | db_test | test2_tbl3 | FALSE | 0 | | db_test | test2_tbl4 | TRUE | 10737418240 | | db_test | test2_tbl5 | TRUE | 134217728 | +--------------+------------+------------+------------------------+ 5 rows in set
Example 3: Create a table after automatic partitioning is enabled
Enable automatic partitioning.
AlTER SYSTEM SET enable_auto_split = TRUE;Create a non-partitioned table named
test3_tbl1. Because all non-partitioned tables in the tenant are automatically partitioned by using theSIZEpartitioning method, the following normal table creation statement will automatically partition the table. The tenant-level configuration item (128 MB by default) will be used as the split threshold.CREATE TABLE test3_tbl1 (col1 INT, col2 INT, PRIMARY KEY(col1));Create a non-partitioned table named
test3_tbl2for automatic partitioning. Because no partitioning key is specified, the primary key will be used as the partitioning key. The split threshold will use the value ofauto_split_tablet_sizeby default.CREATE TABLE test3_tbl2 (col1 INT, col2 INT, PRIMARY KEY(col1)) PARTITION BY RANGE ();Create a non-partitioned table named
test3_tbl3for automatic partitioning. The split threshold will use the value ofauto_split_tablet_sizeby default.CREATE TABLE test3_tbl3 (col1 INT, col2 INT, PRIMARY KEY(col1)) PARTITION BY RANGE () SIZE('1024MB');Create a non-partitioned table named
test3_tbl4.CREATE TABLE test3_tbl4 (col1 INT, col2 INT, PRIMARY KEY(col1)) PARTITION BY RANGE () SIZE('unlimited');A table without a primary key does not meet the requirements for automatic partitioning. Even if
enable_auto_split = true, automatic partitioning will not be enabled.CREATE TABLE test3_tbl5 (col1 INT, col2 INT);A table without a primary key does not meet the requirements for automatic partitioning. The automatic partitioning feature cannot be manually enabled for such a table.
CREATE TABLE test3_tbl6 (col1 INT, col2 INT) PARTITION BY RANGE ();The return result is as follows:
ERROR 1235 (0A000): auto partitioned table without primary key is not supportedView the automatic partitioning attributes of the table.
SELECT TABLE_SCHEMA, TABLE_NAME, AUTO_SPLIT, AUTO_SPLIT_TABLET_SIZE FROM information_schema.TABLES WHERE TABLE_NAME LIKE "test3%" ORDER BY TABLE_NAME;The return result is as follows:
+--------------+------------+------------+------------------------+ | TABLE_SCHEMA | TABLE_NAME | AUTO_SPLIT | AUTO_SPLIT_TABLET_SIZE | +--------------+------------+------------+------------------------+ | db_test | test3_tbl1 | TRUE | 134217728 | | db_test | test3_tbl2 | TRUE | 134217728 | | db_test | test3_tbl3 | TRUE | 1073741824 | | db_test | test3_tbl4 | FALSE | 0 | | db_test | test3_tbl5 | FALSE | 0 | +--------------+------------+------------+------------------------+ 5 rows in set
Example 4: Enable automatic partitioning for global indexes
Note
For tables with automatic partitioning enabled, global indexes created on them will be automatically partitioned, even if the global_index_auto_split_policy parameter is not enabled.
Create an automatically partitioned table
test4_tbl1(with a split threshold of 1024 MB, using user configuration).CREATE TABLE test4_tbl1 (col1 INT, col2 INT, col3 INT, PRIMARY KEY(col1)) PARTITION BY RANGE () SIZE('1024MB');Create a global index
idx1_test4_tbl1on the tabletest4_tbl1.CREATE INDEX idx1_test4_tbl1 ON test4_tbl1 (col2) GLOBAL;Enable the automatic partitioning feature for newly created global indexes.
ALTER SYSTEM SET global_index_auto_split_policy = 'ALL';Create a partitioned table
test4_tbl2without automatic partitioning.CREATE TABLE test4_tbl2(col1 INT, col2 INT, col3 INT, PRIMARY KEY(col1)) PARTITION BY RANGE(col1) (PARTITION p0 VALUES LESS THAN(100), PARTITION p1 VALUES LESS THAN(200), PARTITION p2 VALUES LESS THAN(300));Create a global index
idx1_test4_tbl2on the tabletest4_tbl2.CREATE INDEX idx1_test4_tbl2 ON test4_tbl2 (col2) GLOBAL;