创建shard表 本文为您介绍如何创建shard表。 不指定shard key 建表方式 不指定shard key 建表方法,系统默认使用第一个字段作为表的 shard key。 plaintext teledb create table test(id int, name varchar, birth date); CREATE TABLE teledb d+ test Table "public.test" Column Type Collation Nullable Default Storage Stats target Description +++++++ id integer plain name character varying extended birth timestamp(0) without time zone plain Distribute By: SHARD(id) Location Nodes: ALL DATANODES 分布键选择原则: 分布键只能选择一个字段。 如果有主键,则选择主键做分布键。 如果主键是复合字段组合,则选择字段值选择性多的字段做分布键。 也可以把复合字段拼接成一个新的字段来做分布键。 没有主键的可以使用UUID 来做分布键。 总之一定要让数据尽可能的分布得足够散。 指定shard key 建表方式 plaintext teledb create table testshard(id serial not null, name text) distribute by shard(name) to group defaultgroup; CREATE TABLE teledb d+ testshard Table "public.testshard" Column Type Collation Nullable Default Storage Stats target Description +++++++ id integer not null nextval('testshardidseq'::regclass) plain name text extended Distribute By: SHARD(name) Location Nodes: ALL DATANODES distribute by shard(x) 用于指定分布键,数据分布于那个节点就是根据这个字段值来计算分片。 to group xxx 用于指定存储组(每个存储组可以有多个节点)。 分布键字段值不能修改,字段长度不能修改,字段类型不能修改