Purpose
This statement is used to create a table group.
A table group is mainly used to create a group of tables with the same distribution characteristics. When tables with the same distribution characteristics are joined, the join can be performed locally, avoiding data requests across nodes.
To create a table group, the current user must have the global CREATE (*.*) privilege.
Syntax
CREATE TABLEGROUP [ IF NOT EXISTS ] tablegroup_name [tablegroup_option_list];
tablegroup_option_list:
tablegroup_option [, tablegroup_option ...]
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 an underscore and can only contain uppercase and lowercase letters, digits, 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 be returned. |
| IF NOT EXISTS | If a table group with the same name already exists and the IF NOT EXISTS clause is specified, no error will be returned, and no new table group will be created. |
| SHARDING | The attribute of the table group. If the SHARDING attribute is not specified, the default value is ADAPTIVE. Valid values of SHARDING:
|
Examples
Create a table group named
myTableGroup1and add the non-partitioned tablesmyt1andmyt2to it.obclient> CREATE TABLEGROUP myTableGroup1; obclient> CREATE TABLE myt1 (c1 INT, c2 INT ) TABLEGROUP = myTableGroup1; obclient> CREATE TABLE myt2 (c1 INT, c2 INT ) TABLEGROUP = myTableGroup1;Create a table group named
order_tg_nonewith theSHARDINGattribute set toNONE, and add the non-partitioned tableuser_table, the primary partitioned tableorder_table, and the secondary partitioned tableorder_item_tableto it.obclient> CREATE TABLEGROUP order_tg_none SHARDING = 'NONE'; obclient> CREATE TABLE user_table (col INT) TABLEGROUP = order_tg_none; obclient> CREATE TABLE order_table (col1 BIGINT PRIMARY KEY,col2 VARCHAR(50)) TABLEGROUP = order_tg_none PARTITION BY LIST(col1) (PARTITION p0 VALUES IN (1, 2, 3), PARTITION p1 VALUES IN (5, 6), PARTITION p2 VALUES IN (DEFAULT) ); obclient> CREATE TABLE order_item_table(col1 INT,col2 varchar(50)) TABLEGROUP = order_tg_none 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')) );Create a table group named
product_tg_partitionwith theSHARDINGattribute set toPARTITION, and add the partitioned tablesproduct_tableandcategory_tableto it, ensuring their partitioning methods are consistent.obclient> CREATE TABLEGROUP product_tg_partition SHARDING = 'PARTITION'; obclient> CREATE TABLE product_table (col1 BIGINT PRIMARY KEY,col2 VARCHAR(50)) TABLEGROUP = product_tg_partition PARTITION BY LIST(col1) (PARTITION p0 VALUES IN (1, 2, 3), PARTITION p1 VALUES IN (5, 6), PARTITION p2 VALUES IN (DEFAULT) ); obclient> CREATE TABLE category_table (col1 BIGINT PRIMARY KEY,col2 VARCHAR(50)) TABLEGROUP = product_tg_partition PARTITION BY LIST(col1) (PARTITION p0 VALUES IN (1, 2, 3), PARTITION p1 VALUES IN (5, 6), PARTITION p2 VALUES IN (DEFAULT) );Create a table group named
mixed_tg_partitionwith theSHARDINGattribute set toPARTITION, and add the non-partitioned tableuser_table_npand the partitioned tableorder_table_pto it. However, they cannot be added to the same table group.obclient> CREATE TABLEGROUP mixed_tg_partition SHARDING = 'PARTITION'; obclient> CREATE TABLE user_table_np (col INT) TABLEGROUP = mixed_tg_partition; obclient> CREATE TABLE order_table_p (col1 BIGINT PRIMARY KEY,col2 VARCHAR(50)) TABLEGROUP = mixed_tg_partition PARTITION BY LIST(col1) (PARTITION p0 VALUES IN (1, 2, 3), PARTITION p1 VALUES IN (5, 6), PARTITION p2 VALUES IN (DEFAULT) ); ERROR 4179 (HY000): not all tables are non-partitioned or partitioned, add table to tablegroup not allowedCreate a table group named
product_tg_partition2with theSHARDINGattribute set toPARTITION, and add the partitioned tablesproduct_table2andcategory_table2to it. However, their partition values are inconsistent, so they cannot be added to the same table group.obclient> CREATE TABLEGROUP product_tg_partition2 SHARDING = 'PARTITION'; obclient> CREATE TABLE product_table2 (col1 BIGINT PRIMARY KEY,col2 VARCHAR(50)) TABLEGROUP = product_tg_partition2 PARTITION BY LIST(col1) (PARTITION p0 VALUES IN (1, 2, 3), PARTITION p1 VALUES IN (5, 6), PARTITION p2 VALUES IN (DEFAULT) ); obclient> CREATE TABLE category_table2 (col1 BIGINT PRIMARY KEY,col2 VARCHAR(50)) TABLEGROUP = product_tg_partition2 PARTITION BY LIST(col1) (PARTITION p0 VALUES IN (1, 2, 3), PARTITION p1 VALUES IN (5, 7), PARTITION p2 VALUES IN (DEFAULT) ); ERROR 4179 (HY000): list_part partition value not equal, add table to tablegroup not allowedCreate a table group named
order_tg_adaptivewith theSHARDINGattribute set toADAPTIVE, and add the partitioned tablesorder_detail_tableandorder_item_detail_tableto it, ensuring their partitioning methods are consistent.obclient> CREATE TABLEGROUP order_tg_adaptive SHARDING = 'ADAPTIVE'; obclient> CREATE TABLE order_detail_table(col1 INT,col2 VARCHAR(50)) TABLEGROUP = order_tg_adaptive 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')) ); obclient> CREATE TABLE order_item_detail_table(col1 INT,col2 VARCHAR(50)) TABLEGROUP = order_tg_adaptive 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')) );Create a table group named
mixed_tg_adaptivewith theSHARDINGattribute set toADAPTIVE, and add the non-partitioned tableuser_table_np2and the partitioned tableorder_detail_table2to it. However, they cannot be added to the same table group.obclient> CREATE TABLEGROUP mixed_tg_adaptive SHARDING = 'ADAPTIVE'; obclient> CREATE TABLE user_table_np2 (col int) TABLEGROUP = mixed_tg_adaptive; obclient> CREATE TABLE order_detail_table2(col1 INT,col2 VARCHAR(50)) TABLEGROUP = mixed_tg_adaptive 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')) ); ERROR 4179 (HY000): not all tables are non-partitioned or partitioned, add table to tablegroup not allowedCreate a table group named
order_tg_adaptive2with theSHARDINGattribute set toADAPTIVE, and add the partitioned tablesorder_detail_table3andorder_item_detail_table2to it. However, their primary partitions have the same partitioning type, but their secondary partitions have different partitioning types (different number of secondary partitions), so they cannot be added to the same table group.obclient> CREATE TABLEGROUP order_tg_adaptive2 SHARDING = 'ADAPTIVE'; obclient> CREATE TABLE order_detail_table3(col1 INT,col2 VARCHAR(50)) TABLEGROUP = order_tg_adaptive2 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')) ); obclient> CREATE TABLE order_item_detail_table2(col1 INT,col2 VARCHAR(50)) TABLEGROUP = order_tg_adaptive2 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')) ); ERROR 4179 (HY000): subpartition num not matched, add table to tablegroup not allowed
