This topic describes how to specify a table group when you create a data table in OceanBase Database in MySQL mode.
Prerequisites and usage notes
Observe the following notes if you specify a table group when creating a table:
To specify a partitioned table to an existing partitioned table group when you create the table, ensure that this partitioned table is of the same partitioning method and has the same number of partitions as this table group.
If the locality and primary zone information is specified for the partitioned table and table group, this information must be consistent between the table and table group.
Ensure that you have the
CREATE TABLEprivilege on the target table and table group.
Examples
Example 1
Create a non-partitioned table group and specify this table group when you create a table.
Create a table group named
myTableGroup1.obclient> CREATE TABLEGROUP myTableGroup1; Query OK, 0 rows affectedCreate a table named
myt1and add it to themyTableGroup1table group.obclient> CREATE TABLE myt1 (c1 int, c2 int ) TABLEGROUP = myTableGroup1; Query OK, 0 rows affectedCreate a table named
myt2and add it to themyTableGroup1table group.obclient> CREATE TABLE myt2 (c1 int, c2 int ) TABLEGROUP = myTableGroup1; Query OK, 0 rows affectedView the
myt1andmyt2tables added to themyTableGroup1table group.obclient> SHOW TABLEGROUPS WHERE Tablegroup_name='myTableGroup1'; +-----------------+------------+---------------+ | Tablegroup_name | Table_name | Database_name | +-----------------+------------+---------------+ | myTableGroup1 | myt1 | test | | myTableGroup1 | myt2 | test | +-----------------+------------+---------------+ 2 rows in set7
Example 2
Create a partitioned table group and specify this table group when you create a table.
Create a partitioned table group named
tgh.obclient> CREATE TABLEGROUP tgh PARTITION BY HASH PARTITIONS 10; Query OK, 0 rows affectedCreate a table named
ttghand add it to thetghtable group.obclient>CREATE TABLE ttgh(c1 INT, c2 INT) TABLEGROUP=tgh PARTITION BY HASH(c1) PARTITIONS 10; Query OK, 0 rows affectedCreate a table named
ttgh2and add it to thetghtable group.obclient> CREATE TABLE ttgh2(c1 INT, c2 INT) TABLEGROUP=tgh PARTITION BY HASH(c1) PARTITIONS 10; Query OK, 0 rows affectedView the
ttghandttgh2tables added to thetghtable group.obclient> SHOW TABLEGROUPS WHERE Tablegroup_name='tgh'; +-----------------+------------+---------------+ | Tablegroup_name | Table_name | Database_name | +-----------------+------------+---------------+ | tgh | ttgh | test | | tgh | ttgh2 | test | +-----------------+------------+---------------+ 2 rows in set
Example 3
Add a template-based or non-template-based subpartitioned table to a table group.
Create a partitioned table group named
tg2_f_rr.obclient> CREATE TABLEGROUP tg2_f_rr PARTITION BY RANGE COLUMNS 1 SUBPARTITION BY RANGE COLUMNS 1 (PARTITION p0 VALUES LESS THAN (100) (SUBPARTITION sp1 VALUES LESS THAN (2019), SUBPARTITION sp2 VALUES LESS THAN (2020), SUBPARTITION sp3 VALUES LESS THAN (2021) ), PARTITION p1 VALUES LESS THAN (200) (SUBPARTITION sp5 VALUES LESS THAN (2019), SUBPARTITION sp6 VALUES LESS THAN (2020), SUBPARTITION sp7 VALUES LESS THAN (2021) ) ); Query OK, 0 rows affectedCreate a subpartitioned table named
t2_f_rrwithout using a template and specify a table grouptg2_f_rr.obclient> CREATE TABLE t2_f_rr(col1 int, col2 int) TABLEGROUP = tg2_f_rr PARTITION BY RANGE COLUMNS(col1) SUBPARTITION BY RANGE COLUMNS(col2) (PARTITION p0 VALUES LESS THAN(100) (SUBPARTITION p0_r1 VALUES LESS THAN(2019), SUBPARTITION p0_r2 VALUES LESS THAN(2020), SUBPARTITION p0_r3 VALUES LESS THAN(2021) ), PARTITION p1 VALUES LESS THAN(200) (SUBPARTITION p1_r1 VALUES LESS THAN(2019), SUBPARTITION p1_r2 VALUES LESS THAN(2020), SUBPARTITION p1_r3 VALUES LESS THAN(2021) ) ); Query OK, 0 rows affectedView the
t2_f_rrtable added to thetg2_f_rrtable group.obclient> SHOW TABLEGROUPS WHERE Tablegroup_name='tg2_f_rr'; +-----------------+------------+---------------+ | Tablegroup_name | Table_name | Database_name | +-----------------+------------+---------------+ | tg2_f_rr | t2_f_rr | test | +-----------------+------------+---------------+ 1 row in set