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 SHARDING attribute of the table group. If you do not specify the SHARDING attribute, an ADAPTIVE table group is created by default. Valid values:
|
Examples
Create a table group named
tblgroup1with theSHARDINGattribute set toNONE, and add the partitioned tablestbl1andtbl2to the table group.obclient> CREATE TABLEGROUP tblgroup1 SHARDING = 'NONE'; Query OK, 0 rows affected obclient> CREATE TABLE tbl1(col1 NUMBER,col2 VARCHAR2(50)) PARTITION BY LIST(col1) SUBPARTITION BY LIST (col2) SUBPARTITION TEMPLATE (SUBPARTITION mp0 VALUES ('01'), SUBPARTITION mp1 VALUES ('02'), SUBPARTITION mp2 VALUES ('03') ) (PARTITION p0 VALUES('01'), PARTITION p1 VALUES('02') ); Query OK, 0 rows affected obclient> CREATE TABLE tbl2(col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup1 PARTITION BY LIST(col1) SUBPARTITION BY LIST(col2) SUBPARTITION TEMPLATE (SUBPARTITION mp0 VALUES('01'), SUBPARTITION mp1 VALUES('02'), SUBPARTITION mp2 VALUES('03') ) (PARTITION p0 VALUES('01'), PARTITION p1 VALUES('02') ); Query OK, 0 rows affected obclient> ALTER TABLEGROUP tblgroup1 ADD tbl1,tbl2; Query OK, 0 rows affectedThe partitioning methods of
tbl1andtbl2are the same. Therefore, 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 theSHARDINGattribute set toNONE, and add the non-partitioned tabletbl1and partitioned tabletbl2to 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 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup2 PARTITION BY LIST(col1) SUBPARTITION BY LIST(col2) SUBPARTITION TEMPLATE (SUBPARTITION mp0 VALUES('01'), SUBPARTITION mp1 VALUES('02'), SUBPARTITION mp2 VALUES('03') ) (PARTITION p0 VALUES('01'), PARTITION p1 VALUES('02') ); Query OK, 0 rows affected obclient> ALTER TABLEGROUP tblgroup2 ADD tbl1,tbl2; Query OK, 0 rows affectedThe table group
tblgroup2contains both a non-partitioned table and a partitioned table. Therefore, theSHARDINGattribute cannot be set toPARTITIONorADAPTIVE.obclient> ALTER TABLEGROUP tblgroup2 SHARDING = 'PARTITION'; OBE-00600: internal error code, arguments: -4179, not all tables are non-partitioned or partitioned, modify tablegroup sharding attribute not allowed obclient> ALTER TABLEGROUP tblgroup2 SHARDING = 'ADAPTIVE'; OBE-00600: internal error code, arguments: -4179, not all tables are non-partitioned or partitioned, modify tablegroup sharding attribute not allowedCreate a table group named
tblgroup3with theSHARDINGattribute set toNONE, and add the partitioned tablestbl1andtbl2to the table group.obclient> CREATE TABLEGROUP tblgroup3 SHARDING = 'NONE'; Query OK, 0 rows affected obclient> CREATE TABLE tbl1(col1 NUMBER,col2 VARCHAR2(50)) PARTITION BY LIST(col1) SUBPARTITION BY LIST (col2) SUBPARTITION TEMPLATE (SUBPARTITION mp0 VALUES ('01'), SUBPARTITION mp1 VALUES ('02') ) (PARTITION p0 VALUES('01'), PARTITION p1 VALUES('02') ); Query OK, 0 rows affected obclient> CREATE TABLE tbl2(col1 NUMBER,col2 VARCHAR2(50)) PARTITION BY LIST(col1) SUBPARTITION BY LIST(col2) SUBPARTITION TEMPLATE (SUBPARTITION mp0 VALUES('01'), SUBPARTITION mp1 VALUES('02'), SUBPARTITION mp2 VALUES('03') ) (PARTITION p0 VALUES('01'), PARTITION p1 VALUES('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'; OBE-00600: internal error code, arguments: -4179, subpartition num not matched, modify tablegroup sharding attribute not allowedCreate a table group named
tblgroup4with theSHARDINGattribute set toADAPTIVE, and modify the number of partitions for thetbl1andtbl2tables in the table group. Then, 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(2021), SUBPARTITION mp1 VALUES LESS THAN(2022), SUBPARTITION mp2 VALUES LESS THAN(2023) ) (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(2021), SUBPARTITION mp1 VALUES LESS THAN(2022), SUBPARTITION mp2 VALUES LESS THAN(2023) ) (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 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(2021), SUBPARTITION mp1 VALUES LESS THAN(2022), SUBPARTITION mp2 VALUES LESS THAN(2023) ) (PARTITION p0 VALUES LESS THAN(100), PARTITION p1 VALUES LESS THAN(200) ); Query OK, 0 rows affected obclient> ALTER TABLEGROUP tblgroup4 ADD tbl3; OBE-00600: internal error code, arguments: -4179, partition num not equal, add table to tablegroup not allowed