其他
具有全局唯一索引的跨分区唯一性保证
01
02
create table globalidxpart (a int, b int, c text) partition by range (a);
CREATE TABLE
create table globalidxpart1 partition of globalidxpart for values from (0) to (100000);
CREATE TABLE
create table globalidxpart2 partition of globalidxpart for values from (100001) to (200000);
CREATE TABLE
create table globalidxpart3 partition of globalidxpart for values from (200001) to (300000);
CREATE TABLE
create table globalidxpart4 partition of globalidxpart for values from (300001) to (400000);
CREATE TABLE
create table globalidxpart5 partition of globalidxpart for values from (400001) to (500000);
CREATE TABLE
create table globalidxpart6 partition of globalidxpart for values from (500001) to (600000);
CREATE TABLE
insert into globalidxpart (a, b, c) values (42, 572814, 'inserted first on globalidxpart1');
INSERT 0 1
insert into globalidxpart (a, b, c) values (150000, 572814, 'inserted duplicate b on globalidxpart2');
INSERT 0 1
insert into globalidxpart (a, b, c) values (550000, 572814, 'inserted duplicate b on globalidxpart6');
INSERT 0 1
create unique index on globalidxpart (b) global;
ERROR: could not create unique index "globalidxpart1_b_idx"
DETAIL: Key (b)=(572814) is duplicated.
delete from globalidxpart where a = 150000 and b = 572814;
DELETE 1
create unique index on globalidxpart (b) global;
ERROR: could not create unique index "globalidxpart1_b_idx"
DETAIL: Key (b)=(572814) is duplicated.
delete from globalidxpart where a = 42 and b = 572814;
DELETE 1
create unique index on globalidxpart (b) global;
CREATE INDEX
03