我正在使用带有citus扩展名的Postgresql进行分片,并且无法像下面那样对表格进行分片。
下表有一个主键和2个唯一键。我试图对主键的列进行分片,即pid
。
注意:我不允许更改表格结构。这些表由工具创建。
CREATE TABLE person
(
pid bigint NOT NULL,
name character varying(100),
address_pid bigint NOT NULL,
address_type character varying(100),
CONSTRAINT id_pkey PRIMARY KEY (pid),
CONSTRAINT addr_id UNIQUE (address_pid),
CONSTRAINT addr_type_id UNIQUE (address_type, address_pid)
);
这是我的分片查询:
select create_distributed_table('person', 'pid');
抛出的错误是:
Error: Distributed relations cannot have UNIQUE, EXCLUDE, or PRIMARY KEY constraints that do not include the partition column
任何人都可以帮我分类这些表吗?
@CraigKerstiens除了这个问题:
当我们有多个像这样的外键时,如何处理分片。
CREATE TABLE table
(
pid bigint NOT NULL,
search_order integer NOT NULL,
resource_pid bigint NOT NULL,
search_pid bigint NOT NULL,
CONSTRAINT hfj_search_result_pkey PRIMARY KEY (pid),
CONSTRAINT idx_searchres_order UNIQUE (search_pid, search_order),
CONSTRAINT fk_searchres_res FOREIGN KEY (resource_pid)
REFERENCES public.table1 (res_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT fk_searchres_search FOREIGN KEY (search_pid)
REFERENCES public.table2 (pid) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
假设table1和table2已经分片。
答案 0 :(得分:1)
此时,在Citus中,您不能拥有一个不包含您要分区的列的唯一约束。在这种情况下,可以强制执行人员ID唯一的地址,但不是全局唯一的。要做到这一点,你可以:
CREATE TABLE person
(
pid bigint NOT NULL,
name character varying(100),
address_pid bigint NOT NULL,
address_type character varying(100),
CONSTRAINT id_pkey PRIMARY KEY (pid),
CONSTRAINT addr_id UNIQUE (pid, address_pid),
CONSTRAINT addr_type_id UNIQUE (pid, address_type, address_pid)
);