You can modify the SHARDING attribute of a table group based on business adjustments.
Limitations
Do not use the ALTER TABLEGROUP statement to modify the SHARDING attribute during the upgrade of OceanBase Database.
Rules
Before you modify the SHARDING attribute, check whether the table group contains tables and the partition information of the tables. For more information, see View table group information.
If the table group does not contain tables, you can modify the SHARDING attribute as needed. If the table group contains tables, the following rules apply:
If you want to set the
SHARDINGattribute toNONE, you can do so without considering the partition definitions of the tables in the table group.If you want to set the
SHARDINGattribute toPARTITION, the following rules apply:If all tables in the table group are non-partitioned tables, you can modify the attribute.
If the table group contains both partitioned and non-partitioned tables, you cannot modify the attribute.
If the table group contains only partitioned tables at the first or second level, all first-level tables must have the same partitioning type, the same number of partitions, and the same partition values.
If you want to set the
SHARDINGattribute toADAPTIVE, the following rules apply:If all tables in the table group are non-partitioned tables, you can modify the attribute.
If the table group contains both partitioned and non-partitioned tables, you cannot modify the attribute.
If the table group contains both first- and second-level partitioned tables, you cannot modify the attribute.
If all tables in the table group are first-level partitioned tables, all first-level partitioned tables must have the same partitioning type, the same number of partitions, and the same partition values.
If all tables in the table group are second-level partitioned tables, all first-level and second-level partitioned tables must have the same partitioning type, the same number of partitions, and the same partition values.
Modify the SHARDING attribute of a table group
The SQL statement to modify the SHARDING attribute of a table group is as follows:
ALTER TABLEGROUP tablegroup_name tablegroup_option;
tablegroup_option:
SHARDING = 'NONE'
SHARDING = 'PARTITION'
SHARDING = 'ADAPTIVE'
The statement parameters are described as follows:
Make sure that you have the global
ALTERprivilege before you execute the statement.tablegroup_name: the name of the table group whoseSHARDINGattribute is to be modified.SHARDING: the table group attribute. When you modify the attribute, observe the modification rules.
Here is an example of modifying the table group attribute:
Create a table group named
tblgroup1with theSHARDINGattribute set toPARTITION.CREATE TABLEGROUP tblgroup1 SHARDING = 'PARTITION';Create two partitioned tables named
tbl1andtbl2with the same partitions, and add them to thetblgroup1table group.CREATE TABLE tbl1 (col1 BIGINT PRIMARY KEY,col2 VARCHAR(50)) TABLEGROUP = tblgroup1 PARTITION BY LIST(col1) (PARTITION p0 VALUES IN (1, 2, 3), PARTITION p1 VALUES IN (5, 6), PARTITION p2 VALUES IN (DEFAULT) );CREATE TABLE tbl2 (col1 BIGINT PRIMARY KEY,col2 VARCHAR(50)) TABLEGROUP = tblgroup1 PARTITION BY LIST(col1) (PARTITION p0 VALUES IN (1, 2, 3), PARTITION p1 VALUES IN (5, 6), PARTITION p2 VALUES IN (DEFAULT) );Change the
SHARDINGattribute of thetblgroup1table group toADAPTIVE.ALTER TABLEGROUP tblgroup1 SHARDING = "ADAPTIVE";View the table group attribute.
SHOW TABLEGROUPS WHERE tablegroup_name = 'tblgroup1';The result is as follows:
+-----------------+------------+---------------+----------+ | Tablegroup_name | Table_name | Database_name | Sharding | +-----------------+------------+---------------+----------+ | tblgroup1 | tbl1 | test | ADAPTIVE | | tblgroup1 | tbl2 | test | ADAPTIVE | +-----------------+------------+---------------+----------+ 2 rows in setThe
tbl1andtbl2tables in the table group are all first-level partitioned tables, and they have the same partitioning type, the same number of partitions, and the same partition values, which meets the modification rules. TheSHARDINGattribute is successfully modified.
