暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

AntDB用户手册——建表之创建分片表

gyz 2023-06-19
226

注意:仅在分布式版本中可以创建分片表

AntDB支持多种分片方式,默认为hash分片。

创建如下测试表,可以看出分片键选择的默认行为。

create table test1
(
    id int,
    name text
);
create table test2
(
    id int,
    name text,
    primary key (name)
);
create table test3
(
    id int,
    name text
) distribute by hash(name);
create table test4
(
    id int,
    name text,
    constraint c_name unique(name)
);
create table test5
(
    id int,
    name text
) distribute by replication;

adb中通过\d+ tablename命令可以看到表分片方式:

antdb=> \d+ test1
                                    Table "user1.test1"
 Column |  Type   | Collation | Nullable | Default | Storage  | Stats target | Description 
--------+---------+-----------+----------+---------+----------+--------------+-------------
 id     | integer |           |          |         | plain    |              | 
 name   | text    |           |          |         | extended |              | 
Distribute By: HASH(id)
Location Nodes: ALL DATANODES

antdb=> \d+ test5
                                    Table "user1.test5"
 Column |  Type   | Collation | Nullable | Default | Storage  | Stats target | Description 
--------+---------+-----------+----------+---------+----------+--------------+-------------
 id     | integer |           |          |         | plain    |              | 
 name   | text    |           |          |         | extended |              | 
Distribute By: REPLICATION
Location Nodes: ALL DATANODES

可以看到test1test5 有不同的分片方式。

在AntDB中也提供了不同分片方式之间的转换。

复制表修改为分片表:

alter table test5 distribute by hash(id);

分片表修改为复制表:

alter table test5 distribute by replication;

修改分片字段:

alter table test5 distribute by hash(name);
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论