Purpose
This statement is used to create a table group.
Table groups are primarily used to create a set of tables with the same distribution characteristics. When tables with the same distribution characteristics are joined, the join can be performed locally, avoiding the need for cross-node data requests.
Syntax
CREATE TABLEGROUP tablegroup_name [ tablegroup_options ]
tablegroup_option:
SHARDING = 'NONE' | 'PARTITION' | 'ADAPTIVE'
Parameters
| Parameter | Description |
|---|---|
| tablegroup_name | The name of the table group, which can be up to 64 characters long. It must start with a letter or underscore and can only contain uppercase and lowercase letters, numbers, and underscores. It cannot be a keyword of OceanBase Database. If a table group with the same name already exists and the IF NOT EXISTS clause is not specified, an error will occur. |
| SHARDING | The attribute of the table group. If the SHARDING attribute is not specified, the default value is ADAPTIVE. The value of SHARDING can be one of the following:
|
Examples
Create a table group named
myTableGroup1and add the non-partitioned tablesmyt1andmyt2to it.obclient> CREATE TABLEGROUP myTableGroup1; obclient> CREATE TABLE MYT1 (c1 NUMBER, c2 NUMBER) TABLEGROUP = myTableGroup1; obclient> CREATE TABLE MYT2 (c1 NUMBER, c2 NUMBER) TABLEGROUP = myTableGroup1;Create a table group named
tblgroup1with theSHARDINGattribute set toNONE, and add the non-partitioned tabletbl1, the primary partitioned tabletbl2, and the subpartitioned tabletbl3to it.obclient> CREATE TABLEGROUP tblgroup1 SHARDING = 'NONE'; obclient> CREATE TABLE tbl1 (col NUMBER) TABLEGROUP = tblgroup1; obclient> CREATE TABLE tbl2 (col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup1 PARTITION BY LIST(col1) (PARTITION p0 VALUES ('01'), PARTITION p1 VALUES ('02') ); obclient> CREATE TABLE tbl3(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') );Create a table group named
tblgroup2with theSHARDINGattribute set toPARTITION, and add the partitioned tablestbl4andtbl5to it, ensuring their partitioning methods are consistent.obclient> CREATE TABLEGROUP tblgroup2 SHARDING = 'PARTITION'; obclient> CREATE TABLE tbl4 (col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup2 PARTITION BY LIST(col1) (PARTITION p0 VALUES ('01'), PARTITION p1 VALUES ('02') ); obclient> CREATE TABLE tbl5 (col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup2 PARTITION BY LIST(col1) (PARTITION p0 VALUES ('01'), PARTITION p1 VALUES ('02') );Create a table group named
tblgroup3with theSHARDINGattribute set toPARTITION, and attempt to add the non-partitioned tabletbl6and the partitioned tabletbl7to it.obclient> CREATE TABLEGROUP tblgroup3 SHARDING = 'PARTITION'; obclient> CREATE TABLE tbl6 (col INT) TABLEGROUP = tblgroup3; obclient> CREATE TABLE tbl7 (col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup3 PARTITION BY LIST(col1) (PARTITION p0 VALUES ('01'), PARTITION p1 VALUES ('02') );Expected return result:
OBE-00600: internal error code, arguments: -4179, not all tables are non-partitioned or partitioned, add table to tablegroup not allowedCreate a table group named
tblgroup4with theSHARDINGattribute set toPARTITION, and attempt to add the partitioned tablestbl8andtbl9to it, which have inconsistent partition values.obclient> CREATE TABLEGROUP tblgroup4 SHARDING = 'PARTITION'; obclient> CREATE TABLE tbl8 (col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup4 PARTITION BY LIST(col1) (PARTITION p0 VALUES ('01'), PARTITION p1 VALUES ('02') ); obclient> CREATE TABLE tbl9 (col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup4 PARTITION BY LIST(col1) (PARTITION p0 VALUES ('01'), PARTITION p1 VALUES ('02'), PARTITION p2 VALUES ('03') );Expected return result:
OBE-00600: internal error code, arguments: -4179, partition num not equal, add table to tablegroup not allowedCreate a table group named
tblgroup5with theSHARDINGattribute set toADAPTIVE, and add the partitioned tablestbl10andtbl11to it, ensuring their partitioning methods are consistent.obclient> CREATE TABLEGROUP tblgroup5 SHARDING = 'ADAPTIVE'; obclient> CREATE TABLE tbl10(col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup5 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') ); obclient> CREATE TABLE tbl11(col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup5 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') );Create a table group named
tblgroup6with theSHARDINGattribute set toADAPTIVE, and attempt to add the non-partitioned tabletbl12and the partitioned tabletbl13to it.obclient> CREATE TABLEGROUP tblgroup6 SHARDING = 'ADAPTIVE'; obclient> CREATE TABLE tbl12 (col INT) TABLEGROUP = tblgroup6; obclient> CREATE TABLE tbl13(col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup6 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') ); Expected return result:OBE-00600: internal error code, arguments: -4179, not all tables are non-partitioned or partitioned, add table to tablegroup not allowed
Create a table group named
tblgroup7with theSHARDINGattribute set toADAPTIVE, and attempt to add the partitioned tablestbl14andtbl15to it. The primary partitions oftbl14andtbl15have the same partition type, but the subpartitions have different types (different number of subpartitions).obclient> CREATE TABLEGROUP tblgroup7 SHARDING = 'ADAPTIVE'; obclient> CREATE TABLE tbl14(col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup7 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') ); obclient> CREATE TABLE tbl15(col1 NUMBER,col2 VARCHAR2(50)) TABLEGROUP = tblgroup7 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') );Expected return result:
OBE-00600: internal error code, arguments: -4179, subpartition num not matched, add table to tablegroup not allowed