OceanBase CREATE TABLEGROUP

2021-06-28 15:15 更新

描述

該語(yǔ)句用來(lái)創(chuàng)建表組。

說(shuō)明 
只有租戶下的管理員權(quán)限才可以創(chuàng)建表組。

格式

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 
 HASH COLUMN_NUM [tg_subpartition_option] PARTITIONS INTNUM
| RANGE COLUMNS COLUMN_NUM [tg_subpartition_option] {PARTITION partition_name VALUES LESS THAN range_partition_expr, ...}
| LIST COLUMNS COLUMN_NUM [tg_subpartition_option] {PARTITION partition_name VALUES in list_partition_expr, ...}

tg_subpartition_option:
SUBPARTITION BY 
RANGE COLUMN_NUM SUBPARTITION TEMPLATE {SUBPARTITION partition_name VALUES LESS THAN range_partition_expr, ...}
| HASH COLUMN_NUM [SUBPARTITIONS INTNUM]
| LIST COLUMN_NUM SUBPARTITION TEMPLATE {SUBPARTITION partition_name VALUES in list_partition_expr, ...}

參數(shù)解釋

參數(shù)

描述

tablegroupname

表組名稱,最長(zhǎng) 64 個(gè)字符,字符只能有大小寫(xiě)英文字母,數(shù)字和下劃線,而且必須以字母或下劃線開(kāi)頭,并且不能使用 OceanBase 的關(guān)鍵字。

如果要?jiǎng)?chuàng)建的表組名稱已存在,并且沒(méi)有指定 IF NOT EXISTS,則會(huì)出現(xiàn)錯(cuò)誤。

opt_tablegroup_option_list

表組的分區(qū)方式、locality、primary zone 必須和組內(nèi)的表完全一致。

組內(nèi)的表信息不能獨(dú)立變更某一項(xiàng),只可以通過(guò)操作表組進(jìn)行批量操作。

相同的 locality:副本類(lèi)型、個(gè)數(shù)、位置要完全一致

相同的 primary zone:leader 位置及其優(yōu)先級(jí)要完全一致

相同的分區(qū)方式:

  • 分區(qū)類(lèi)型相同(例如,都是 hash+range 分區(qū))。

  • 如果是 hash 分區(qū),要求引用的列數(shù)相同,且分區(qū)個(gè)數(shù)相同。

  • 如果是 range 分區(qū),要求引用的列數(shù)相同,且分區(qū)數(shù)相同,且 range 分割點(diǎn)相同。

  • 對(duì)于二級(jí)分區(qū),根據(jù)分區(qū)類(lèi)型,要求和上述一致

opt_tg_partition_option

表組的分區(qū)規(guī)則定義,與 CREATE TABLE 使用同樣的分區(qū)方式。

表組沒(méi)有具體的列定義,所以 HASH、RANGE、LIST 不需要寫(xiě)出具體的列,只需要指定列個(gè)數(shù)(COLUMN_NUM)。

示例

  • 創(chuàng)建名為 myTableGroup1 的表組。

OceanBase(admin@test)> CREATE TABLEGROUP myTableGroup1;
Query OK, 0 rows affected (0.07 sec)

OceanBase(admin@test)> create table myt1 (c1 int, c2 int ) tablegroup = myTableGroup1;
Query OK, 0 rows affected (0.28 sec)

OceanBase(admin@test)> create table myt2 (c1 int, c2 int ) tablegroup = myTableGroup1;
Query OK, 0 rows affected (0.26 sec)
  • 創(chuàng)建 hash 分區(qū)的表組 tgh,同時(shí)創(chuàng)建 hash 分區(qū)的表 ttgh,且分區(qū)個(gè)數(shù)相同。

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) locality='F,R{ALL_SERVER}@z1' partition by hash(c1) partitions 10;
Query OK, 0 rows affected (0.55 sec)

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


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)