
# CREATE SLICEGROUP
#### 功能描述
创建一组rangebucket表使用的分布规则，持久化在系统表gs_slicegroup中。
#### 注意事项
- 不支持多个SLICE分片分布在同一个bucket上，创建SLICEGROUP时指定的bucketcnt需要大于等于SLICE分片数。
- 不支持单个SLICE分片分布在多个DN上，创建SLICEGROUP时单个SLICE只能指定一个DN。
- 单个SLICEGROUP申请的bucketcnt不能超过1024，SLICEGROUP是库级别的概念，同一数据库下所有SLICEGROUP申请的bucket总数不超过4096。
- 创建SLICEGROUP时，分布列类型不支持自定义类型，不支持指定字符集。
- SLICE分片定义只支持less than语法，不支持start end和reference语法。
- rangebucket表使用gs_dump导出、gs_restore导入时需要在导入前手动创建SLICEGROUP，开启审计功能时可通过审计日志查找创建语句。
 
#### 语法格式
```
CREATE SLICEGROUP slicegroup_name 
    DISTRIBUTE BY RANGE ( column_type [, ...] )
    ( slice_less_than_item [, ...] ) BUCKETCNT bucket_cnt;
```
![](https://support.huaweicloud.com/distributed-devg-v8-gaussdb/figure/zh-cn_image_0000002526896918.png "点击放大")
#### 参数说明
- **slicegroup_name**
  将要创建的分布规则的名称，同一数据库下名称不能重复，不能与NODEGROUP名相同。
  取值范围：字符串，支持字符集为小写字母（a-z）、大写字母(A-Z)、下划线（_）、数字（0\~9）或美元符号（$），且必须以字母或下划线开头。
  
- **c** **olumn_type**
  分布列类型，最多支持4个分布列。
  
- **slice_less_than_item**
  使用less than语法的slice分片定义。
  ```
  slice_less_than_item为：
  SLICE name VALUES LESS THAN ({ expression | MAXVALUE } [, ...]) [ DATANODE datanode_name ]
  ```
  name 取值范围：字符串，支持字符集为小写字母（a-z）、大写字母(A-Z)、下划线（_）、数字（0\~9）或美元符号（$），且必须以字母或下划线开头。
  
- **bucket_cnt**
  要创建的分布规则申请维护的bucket总数。
  取值范围：\[1,1024\]
  
 
#### 示例
```
--创建SLICEGROUP。
gaussdb=# CREATE SLICEGROUP sg DISTRIBUTE BY RANGE(INT,CHAR(5),TIMESTAMP,TEXT)
(SLICE s1 VALUES LESS THAN (1000,'3700x','2012-5-5 10:52:12','customer') DATANODE datanode3,
 SLICE s2 VALUES LESS THAN (1000,'3701x','2012-5-5 10:52:12','customer'),
 SLICE s3 VALUES LESS THAN (1000,'3702x','2012-5-5 10:52:12','customer')) bucketcnt 3;
--查询SLICEGROUP。
gaussdb=# SELECT * FROM gs_slicegroup;
 slicename | type | strategy | bucketgroup | bucketcnt | sgroupoid | sindex | nodeid | redis_nodeid | bucket | slicecnt | contained | specified | sliceorder |                boundaries
     | bucketversion | bucketcsn | bucketxid | distributetype
-----------+------+----------+-------------+-----------+-----------+--------+--------+--------------+--------+----------+-----------+-----------+------------+--------------------------------------
-----+---------------+-----------+-----------+-----------------
 sg        | t    | r        |           1 |         3 |     16394 |      0 |     -1 |           -1 |     -1 |        3 | f         | f         |         -1 |
     |               |           |           | 23 1042 1114 25
 s1        | s    | r        |           1 |         1 |     16394 |      0 |      2 |           -1 |   2048 |       -1 | f         | t         |          0 | {1000,3700x,"2012-5-5 10:52:12",custo
mer} |               |           |           |
 s2        | s    | r        |           1 |         1 |     16394 |      0 |      0 |           -1 |   2049 |       -1 | f         | f         |          1 | {1000,3701x,"2012-5-5 10:52:12",custo
mer} |               |           |           |
 s3        | s    | r        |           1 |         1 |     16394 |      0 |      1 |           -1 |   2050 |       -1 | f         | f         |          2 | {1000,3702x,"2012-5-5 10:52:12",custo
mer} |               |           |           |
(4 rows)
--删除SLICEGROUP。
gaussdb=# DROP SLICEGROUP sg;
```
#### 相关链接
[DROP SLICEGROUP](https://support.huaweicloud.com/distributed-devg-v8-gaussdb/gaussdb-12-1872.html#ZH-CN_TOPIC_0000002559105939)
