Files
oceanbase/docs/docs-cn/10.sql-reference/5.sql-statement/8.alter-tablegroup.md
2022-02-10 14:51:49 +08:00

3.3 KiB

ALTER TABLEGROUP

描述

该语句用来执行以下操作:

  • 对一个表组增加多张表。

  • 修改表组的分区规则。

  • 修改表组的 locality 和 primary zone。

格式

  • 对一个表组增加多张表。
ALTER TABLEGROUP tablegroupname ADD [TABLE] tblname [, tblname...]
  • 修改表组的分区规则。
ALTER TABLEGROUP tablegroupname alter_tg_partition_option
alter_tg_partition_option:
DROP PARTITION '(' name_list ')'
| ADD PARTITION opt_range_partition_list
| modify_tg_partition_info
  • 修改表组的 locality 和 primary zone。
ALTER TABLEGROUP tablegroupname alter_tablegroup_actions
alter_tablegroup_actions:
alter_tablegroup_action
| alter_tablegroup_action, alter_tablegroup_action
alter_tablegroup_action:
SET LOCALITY [=] locality_name
|SET PRIMARY_ZONE [=] primary_zone_name

参数解释

参数 描述
tablegroupname 指定表组。
tblname 表名。对一个表组增加多张表时,表与表之间以逗号(',')分隔。 当添加多个表时,允许表名重复。如果待添加的表已经属于 tablegroupname 的表格组,系统不报错。
modify_tg_partition_info 修改表组的分区规则。
LOCALITY locality_name 指定表组的 locality。
PRIMARY_ZONE primary_zone_name 指定表组的主Zone。

示例

创建表组 tgh 和两张关系表 ttgh 和 ttgh2 ,并将表组的 locality 修改为 F@z1。

OceanBase(admin@test)> create tablegroup tgh locality='F,R{ALL_SERVER}@z1' partition by hash partitions 10;
Query OK, 0 rows affected (0.09 sec)

OceanBase(admin@test)> create table ttgh(c1 int, c2 int) tablegroup = tgh locality='F,R{ALL_SERVER}@z1';
Query OK, 0 rows affected (0.55 sec)

OceanBase(admin@test)> create table ttgh2(c1 int, c2 int) tablegroup = tgh locality='F,R{ALL_SERVER}@z1';
Query OK, 0 rows affected (0.39 sec)

OceanBase(admin@test)> alter tablegroup tgh set locality ='F@z1';
Query OK, 0 rows affected (0.09 sec)

OceanBase(admin@test)> select locality from oceanbase.__all_tablegroup where tablegroup_name ='tgh';
+------------+
| locality   |
+------------+
| FULL{1}@z1 |
+------------+
1 row in set (0.05 sec)

OceanBase(admin@test)> select locality from oceanbase.__all_table where tablegroup_id=(select tablegroup_id from oceanbase.__all_tablegroup where tablegroup_name ='tgh');
+------------+
| locality   |
+------------+
| FULL{1}@z1 |
| FULL{1}@z1 |
+------------+
2 rows in set (0.04 sec)