我正在使用带有 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 已经分片。