You can use the ALTER TABLE statement to add a table to or remove a table from a table group. You can also modify the TABLEGROUP property of the table. After you modify the TABLEGROUP property, RootService migrates the replicas in the background. It migrates the replicas that belong to the same partition group to the same node, and runs a command to include these partitions in the same replication group.
Create a table group
The following example creates Table Group grp1.
obclient> CREATE TABLEGROUP grp1;
Remove a table from a table group
The following example removes Table t1 from its table group.
obclient> ALTER TABLE t1 SET TABLEGROUP '';
Add a table to a table group
The following example adds Table t1 to Table Group grp1.
obclient> ALTER TABLE t1 SET TABLEGROUP grp1;
Move a table from one table group to another
The following example moves Table t1 from Table Group grp1 to Table Group grp2.
obclient> ALTER TABLE t1 SET TABLEGROUP grp2;
Delete a table group
You can execute the following statement to delete a table group, but you cannot delete a table group that is referenced by the TABLEGROUP property of a table.
obclient> DROP TABLEGROUP grp1;
Change the partitioning method
For a table in a table group, you cannot use the ALTER TABLE statement to change its partitioning method, locality, or primary zone. You must use the ALTER TABLEGROUP statement.
When you change the partitioning method, locality, or primary zone of a table group, the same property is changed for every table in the table group.
Change the locality
The following example changes the locality of all tables in Table Group grp1 to F@z1,F@z3.
obclient> ALTER TABLEGROUP grp1 SET locality = 'F@z1,F@z3';
Change the primary zone
The following example changes the primary zone of all tables in Table Group grp1 to z1,z2.
obclient> ALTER TABLEGROUP grp1 SET primary_zone = 'z1,z2';
Drop partitions
The following example drops Partitions p0 and p1 from all tables in Table Group grp1. This operation is applicable only to range partitions.
In this statement, p0 and p1 are partition names specified for range partitions when the table group was created, not the partition name in each table. The system can find the corresponding partitions in each table based on the range split point.
obclient> ALTER TABLEGROUP grp1 DROP PARTITION (p0,p1);
Add partitions
The following example adds Partition p4 for all tables in Table Group grp1. This operation is applicable only to range partitions.
obclient> ALTER TABLEGROUP grp1 ADD PARTITION (PARTITION p4 VALUES LESS THAN (200));