一、创建外键
外键只是同一个节点内约束有效果,所以外键字段和对应主键字段必须都是表的分布键,否则由于数据分布于不同的节点内会导致更新失败。
二、删除外键
postgres=# \\d+ t_f Table "public.t_f" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description ——–+———+———–+———-+———+———+————–+————- f1 | integer | | not null | | plain | | f2 | integer | | | | plain | | Foreign-key constraints: "t_f_f1_fkey" FOREIGN KEY (f1) REFERENCES t_p(f1)Distribute By: SHARD(f1)Location Nodes: ALL DATANODESpostgres=# ALTER TABLE t_f drop constraint t_f_f1_fkey;ALTER TABLEpostgres=# \\d+ t_f Table "public.t_f" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description ——–+———+———–+———-+———+———+————–+————- f1 | integer | | not null | | plain | | f2 | integer | | | | plain | | Distribute By: SHARD(f1)Location Nodes: ALL DATANODES