Description
You can use this statement to create a table group. Note
Only an administrator under a tenant can create a table group.
Syntax
CREATE TABLEGROUP [IF NOT EXISTS] tablegroupname [opt_tablegroup_option_list] [opt_tg_partition_option]
opt_tablegroup_option_list:
tablegroup_option [tablegroup_option]
tablegroup_option:
LOCALITY [=] locality_name
| PRIMARY_ZONE [=] primary_zone_name
opt_tg_partition_option:
PARTITION BY
KEY COLUMN_NUM [tg_subpartition_option] PARTITIONS INTNUM
| HASH [tg_subpartition_option] PARTITIONS INTNUM
| RANGE [tg_subpartition_option] {PARTITION partition_name VALUES LESS THAN range_partition_expr, ...}
| RANGE COLUMNS COLUMN_NUM [tg_subpartition_option] {PARTITION partition_name VALUES LESS THAN range_partition_expr, ...}
| LIST [tg_subpartition_option] {PARTITION partition_name VALUES in list_partition_expr, ...}
| LIST COLUMNS COLUMN_NUM [tg_subpartition_option] {PARTITION partition_name VALUES in list_partition_expr, ...}
tg_subpartition_option:
SUBPARTITION BY
RANGE SUBPARTITION TEMPLATE {SUBPARTITION partition_name VALUES LESS THAN range_partition_expr, ...}
| RANGE COLUMNS COLUMN_NUM SUBPARTITION TEMPLATE {SUBPARTITION partition_name VALUES LESS THAN range_partition_expr, ...}
| HASH [SUBPARTITIONS INTNUM]
| KEY COLUMN_NUM [SUBPARTITIONS INTNUM]
| LIST SUBPARTITION TEMPLATE {SUBPARTITION partition_name VALUES in list_partition_expr, ...}
| LIST COLUMNS COLUMN_NUM SUBPARTITION TEMPLATE {SUBPARTITION partition_name VALUES in list_partition_expr, ...}
Parameters
| Parameter | Description |
|---|---|
| tablegroupname | The table group name, which contains a maximum of 64 characters. It consists of uppercase and lowercase letters, digits, and underscores (). The table group name must start with a letter or underscore (), and cannot contain the OceanBase keyword. If the table group name already exists and IF NOT EXISTS is not specified, an error is returned. |
| opt_tablegroup_option_list | The partitioning mode, locality, and primary zone of the table group must be the same as those of the tables in the table group. You cannot modify a single information item but perform batch operations on the entire table group. Identical locality: The replica type, quantity, and location must be consistent. Identical primary zone: The locality and priority of the leader must be consistent. Identical partitioning method: * The partition types are the same, for example, hash+range partitions. * KEY-partitioned tables must have the same number of referenced columns and the same number of partitions. * HASH-partitioned tables must have the same number of partitions. * RANGE COLUMNS-partitioned tables must have the same number of partitions, the same number of referenced columns, and the same range definitions. * RANGE-partitioned tables must have the same number of partitions and the same range definitions. * Subpartitions in a table group must meet the preceding requirements. |
| opt_tg_partition_option | The definition of partitioning rules of the table group. The same partitioning method as CREATE TABLE is used. Columns are not defined for the table group. Therefore, you do not need to specify the KEY, RANGE COLUMNS, and LIST COLUMNS columns, but only specify the column quantity (CLUMN_NUM). |
Examples
- Create a table group named myTableGroup1.
obclient> CREATE TABLEGROUP myTableGroup1;
Query OK, 0 rows affected (0.07 sec)
obclient> create table myt1 (c1 int, c2 int ) tablegroup = myTableGroup1;
Query OK, 0 rows affected (0.28 sec)
obclient> create table myt2 (c1 int, c2 int ) tablegroup = myTableGroup1;
Query OK, 0 rows affected (0.26 sec)
- Create a HASH-partitioned table group named tgh and a HASH-partitioned table named ttgh, and ensure that the number of partitions is the same.
obclient> create tablegroup tgh partition by hash partitions 10;
Query OK, 0 rows affected (0.09 sec)
obclient> create table ttgh(c1 int, c2 int) partition by hash(c1) partitions 10;
Query OK, 0 rows affected (0.55 sec)
obclient> create table ttgh2(c1 int, c2 int) partition by hash(c2) partitions 10;
Query OK, 0 rows affected (0.39 sec)