[TOC] # 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 ~~~ ## 参数解释 <table data-tag="table" id="table-47n-rtr-2g4" class="table"><colgroup width="249" span="1" data-tag="col" id="col-yer-9sh-1op" colwidth="1*" colnum="1" colname="col1" style="width:50%" class="col"></colgroup><colgroup width="423" span="1" data-tag="col" id="col-zas-nch-y2j" colwidth="1*" colnum="2" colname="col2" style="width:50%" class="col"></colgroup><thead id="thead-rtc-1le-s2l" class="thead"><tr id="tr-eda-xkx-ifa"><th id="td-m6u-3mm-fz8"><p id="p-78a-pl8-xuh"><b>参数</b></p></th><th id="td-paz-sos-dvf"><p id="p-vyf-jsa-yd2"><b>描述</b></p></th></tr></thead><tbody data-tag="tbody" id="tbody-xv7-fvp-n24" class="tbody"><tr data-tag="tr" id="tr-d7j-h5z-d54" class="tr"><td data-tag="td" id="td-w8k-g8n-orh" class="td"><p data-tag="p" id="p-o9g-tao-d2f" class="p">tablegroupname</p></td><td data-tag="td" id="td-93u-tt0-nt3" class="td"><p data-tag="p" id="p-frz-s2k-48c" class="p">指定表组。</p></td></tr><tr data-tag="tr" id="tr-pox-ai3-r6r" class="tr"><td data-tag="td" id="td-9qs-434-fe3" class="td"><p data-tag="p" id="p-q36-jml-ckz" class="p">tblname</p></td><td data-tag="td" id="td-d71-kp4-mrp" class="td"><p data-tag="p" id="p-okk-g6t-zvn" class="p">表名。对一个表组增加多张表时,表与表之间以逗号(‘,’)分隔。</p><p data-tag="p" id="p-jfb-cz6-7tg" class="p">当添加多个表时,允许表名重复。如果待添加的表已经属于 </p><p data-tag="p" id="p-jfb-cz6-7tg" class="p"><span data-mce-style="font-size: 11px" data-tag="span" id="span-h1q-vlb-iyr" class="span"><em data-tag="em" id="em-wy3-zpr-kqp" class="em">tablegroupname </em></span><span data-mce-style="font-size: 11px" data-tag="span" id="span-h1q-vlb-iyr" class="span">的表格组,系统不报错。</span></p></td></tr><tr data-tag="tr" id="tr-obw-wsj-10b" class="tr"><td data-tag="td" id="td-sao-b82-ne7" class="td"><p data-tag="p" id="p-9a4-af4-un1" class="p">modify_tg_partition_info</p></td><td data-tag="td" id="td-r93-9gz-60i" class="td"><p data-tag="p" id="p-x05-5b6-7em" class="p">修改表组的分区规则。</p></td></tr><tr data-tag="tr" id="tr-bui-v1a-k63" class="tr"><td data-tag="td" id="td-j6o-q02-n9a" class="td"><p data-tag="p" id="p-yca-cbz-z3l" class="p">LOCALITY locality_name</p></td><td data-tag="td" id="td-ixz-se2-wt7" class="td"><p data-tag="p" id="p-bxt-55d-md4" class="p">指定表组的 locality。</p></td></tr><tr data-tag="tr" id="tr-0ai-skv-g8k" class="tr"><td data-tag="td" id="td-hq5-0ya-sou" class="td"><p data-tag="p" id="p-5zh-ggq-ea6" class="p">PRIMARY_ZONE primary_zone_name</p></td><td data-tag="td" id="td-jtc-2bz-v5b" class="td"><p data-tag="p" id="p-fbd-5w9-cvt" class="p">指定表组的主Zone。</p></td></tr></tbody></table> ## 示例 创建表组 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) ~~~