Purpose
You can use this statement to add multiple tables to a table group and modify the SHARDING attribute of the table group.
Syntax
Add multiple tables to a table group.
ALTER TABLEGROUP tablegroup_name ADD [TABLE] table_name [, table_name...];Modify the partitioning rules of a table group.
ALTER TABLEGROUP tablegroup_name tablegroup_option; tablegroup_option: SHARDING = 'NONE' | 'PARTITION' | 'ADAPTIVE'
Parameters
| Parameter | Description |
|---|---|
| tablegroup_name | The name of the table group. If multiple tables are added, separate the tables with a comma (,). When multiple tables are added, the table names can be duplicate. If a table to be added already exists in the table group, OceanBase Database does not return an error. |
| SHARDING | The attribute of the table group. If you do not specify the SHARDING attribute, an ADAPTIVE table group is created by default. Valid values of SHARDING:
|
Examples
Create a table group named
tblgroup1with theSHARDINGattributeNONE, and add the partitioned tablestbl1andtbl2to the table group.obclient> CREATE TABLEGROUP tblgroup1 SHARDING = 'NONE'; Query OK, 0 rows affected obclient> CREATE TABLE tbl1(col1 INT,col2 VARCHAR(50)) PARTITION BY LIST(col1) SUBPARTITION BY LIST COLUMNS(col2) (PARTITION p0 VALUES in (01) (SUBPARTITION mp0 VALUES in ('01'), SUBPARTITION mp1 VALUES in ('02')), PARTITION p1 VALUES in (02) (SUBPARTITION mp3 VALUES in ('01'), SUBPARTITION mp4 VALUES in ('02')) ); Query OK, 0 rows affected obclient> CREATE TABLE tbl2(col1 INT,col2 VARCHAR(50)) PARTITION BY LIST(col1) SUBPARTITION BY LIST COLUMNS(col2) (PARTITION p0 VALUES in (01) (SUBPARTITION mp0 VALUES in ('01'), SUBPARTITION mp1 VALUES in ('02')), PARTITION p1 VALUES in (02) (SUBPARTITION mp3 VALUES in ('01'), SUBPARTITION mp4 VALUES in ('02')) ); Query OK, 0 rows affected obclient> ALTER TABLEGROUP tblgroup1 ADD tbl1,tbl2; Query OK, 0 rows affectedBecause the partitioning methods of
tbl1andtbl2are the same, theSHARDINGattribute can be set toPARTITIONorADAPTIVE.obclient> ALTER TABLEGROUP tblgroup1 SHARDING = 'PARTITION'; Query OK, 0 rows affected obclient> ALTER TABLEGROUP tblgroup1 SHARDING = 'ADAPTIVE'; Query OK, 0 rows affectedCreate a table group named
tblgroup2with theSHARDINGattributeNONE, and add a non-partitioned table namedtbl1and a partitioned table namedtbl2to the table group.obclient> CREATE TABLEGROUP tblgroup2 SHARDING = 'NONE'; Query OK, 0 rows affected obclient> CREATE TABLE tbl1 (col INT); Query OK, 0 rows affected obclient> CREATE TABLE tbl2 (col1 BIGINT PRIMARY KEY,col2 VARCHAR(50)) PARTITION BY LIST(col1) (PARTITION p0 VALUES IN (1, 2, 3), PARTITION p1 VALUES IN (5, 6), PARTITION p2 VALUES IN (DEFAULT) ); Query OK, 0 rows affected obclient> ALTER TABLEGROUP tblgroup2 ADD tbl1,tbl2; Query OK, 0 rows affectedBecause the table group
tblgroup2contains both a non-partitioned table and a partitioned table, theSHARDINGattribute cannot be set toPARTITIONorADAPTIVE.obclient> ALTER TABLEGROUP tblgroup2 SHARDING = 'PARTITION'; ERROR 4179 (HY000): not all tables are non-partitioned or partitioned, modify tablegroup sharding attribute not allowed obclient> ALTER TABLEGROUP tblgroup2 SHARDING = 'ADAPTIVE'; ERROR 4179 (HY000): not all tables are non-partitioned or partitioned, modify tablegroup sharding attribute not allowedCreate a table group named
tblgroup3with theSHARDINGattributeNONE, and add partitioned tablestbl1andtbl2to the table group.obclient> CREATE TABLEGROUP tblgroup3 SHARDING = 'NONE'; Query OK, 0 rows affected obclient> CREATE TABLE tbl1(col1 INT,col2 VARCHAR(50)) PARTITION BY LIST(col1) SUBPARTITION BY LIST COLUMNS(col2) (PARTITION p0 VALUES in (01) (SUBPARTITION mp0 VALUES in ('01'), SUBPARTITION mp1 VALUES in ('02'), SUBPARTITION mp2 VALUES in ('03') ), PARTITION p1 VALUES in (02) (SUBPARTITION mp3 VALUES in ('01'), SUBPARTITION mp4 VALUES in ('02'), SUBPARTITION mp5 VALUES in ('03')) ); Query OK, 0 rows affected obclient> CREATE TABLE tbl2(col1 INT,col2 VARCHAR(50)) PARTITION BY LIST(col1) SUBPARTITION BY LIST COLUMNS(col2) (PARTITION p0 VALUES in (01) (SUBPARTITION mp0 VALUES in ('01'), SUBPARTITION mp1 VALUES in ('02')), PARTITION p1 VALUES in (02) (SUBPARTITION mp3 VALUES in ('01'), SUBPARTITION mp4 VALUES in ('02')) ); Query OK, 0 rows affected obclient> ALTER TABLEGROUP tblgroup3 ADD tbl1,tbl2; Query OK, 0 rows affectedThe partitioning types of the
tbl1andtbl2tables in the table grouptblgroup3are the same, while their subpartitioning types are different (with different numbers of subpartitions). Therefore, theSHARDINGattribute can be set toPARTITION, but notADAPTIVE.obclient> ALTER TABLEGROUP tblgroup3 SHARDING = 'PARTITION'; Query OK, 0 rows affected obclient> ALTER TABLEGROUP tblgroup3 SHARDING = 'ADAPTIVE'; ERROR 4179 (HY000): subpartition num not matched, modify tablegroup sharding attribute not allowedCreate a table group named
tblgroup4with theSHARDINGattributeADAPTIVE, and modify the number of partitions for the tablestbl1andtbl2in the table group. Then, all tables in the table group are partitioned differently. The new tabletbl3cannot be added to the table group.obclient> CREATE TABLEGROUP tblgroup4 SHARDING = 'ADAPTIVE'; Query OK, 0 rows affected obclient> CREATE TABLE tbl1(col1 INT,col2 INT) PARTITION BY RANGE(col1) SUBPARTITION BY RANGE(col2) SUBPARTITION TEMPLATE (SUBPARTITION mp0 VALUES LESS THAN(2020), SUBPARTITION mp1 VALUES LESS THAN(2021), SUBPARTITION mp2 VALUES LESS THAN(2022)) (PARTITION p0 VALUES LESS THAN(100), PARTITION p1 VALUES LESS THAN(200)); Query OK, 0 rows affected obclient> CREATE TABLE tbl2(col1 INT,col2 INT) PARTITION BY RANGE(col1) SUBPARTITION BY RANGE(col2) SUBPARTITION TEMPLATE (SUBPARTITION mp0 VALUES LESS THAN(2020), SUBPARTITION mp1 VALUES LESS THAN(2021), SUBPARTITION mp2 VALUES LESS THAN(2022)) (PARTITION p0 VALUES LESS THAN(100), PARTITION p1 VALUES LESS THAN(200)); Query OK, 0 rows affected obclient> ALTER TABLEGROUP tblgroup4 ADD tbl1,tbl2; Query OK, 0 rows affected obclient> ALTER TABLE tbl1 ADD PARTITION (PARTITION p3 VALUES LESS THAN(400), PARTITION p4 VALUES LESS THAN(500)); Query OK, 0 rows affected obclient> ALTER TABLE tbl2 DROP SUBPARTITION p0smp0,p0smp1; Query OK, 0 rows affected obclient> CREATE TABLE tbl3(col1 INT,col2 INT) PARTITION BY RANGE(col1) SUBPARTITION BY RANGE(col2) SUBPARTITION TEMPLATE (SUBPARTITION mp0 VALUES LESS THAN(2020), SUBPARTITION mp1 VALUES LESS THAN(2021), SUBPARTITION mp2 VALUES LESS THAN(2022)) (PARTITION p0 VALUES LESS THAN(100), PARTITION p1 VALUES LESS THAN(200)); Query OK, 0 rows affected obclient> ALTER TABLEGROUP tblgroup4 ADD tbl3; ERROR 4179 (HY000): partition num not equal, add table to tablegroup not allowed