diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c index c81a329905..c6fffd1c89 100644 --- a/src/backend/catalog/partition.c +++ b/src/backend/catalog/partition.c @@ -628,7 +628,7 @@ RelationBuildPartitionDesc(Relation rel) /* * Now assign OIDs from the original array into mapped indexes of the * result array. Order of OIDs in the former is defined by the - * catalog scan that retrived them, whereas that in the latter is + * catalog scan that retrieved them, whereas that in the latter is * defined by canonicalized representation of the list values or the * range bounds. */ @@ -1431,7 +1431,7 @@ get_partition_operator(PartitionKey key, int col, StrategyNumber strategy, /* * If one doesn't exist, we must resort to using an operator in the same - * opreator family but with the operator class declared input type. It is + * operator family but with the operator class declared input type. It is * OK to do so, because the column's type is known to be binary-coercible * with the operator class input type (otherwise, the operator class in * question would not have been accepted as the partitioning operator @@ -1810,7 +1810,7 @@ get_range_nulltest(PartitionKey key) * partition keys. * * For default partition, it returns the negation of the constraints of all - * other partitions. + * the other partitions. * * If we end up with an empty result list, we return a single-member list * containing a constant TRUE, because callers expect a non-empty list. diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out index 8e332ebf62..bc5f9c6d62 100644 --- a/src/test/regress/expected/alter_table.out +++ b/src/test/regress/expected/alter_table.out @@ -3341,19 +3341,19 @@ CREATE TABLE part2 ( ); ALTER TABLE range_parted ATTACH PARTITION part2 FOR VALUES FROM (1, 10) TO (1, 20); INFO: partition constraint for table "part2" is implied by existing constraints --- default partition +-- Create default partition CREATE TABLE partr_def1 PARTITION OF range_parted DEFAULT; --- cannot attach 2nd default +-- Only one default partition is allowed, hence, following should give error CREATE TABLE partr_def2 (LIKE part1 INCLUDING CONSTRAINTS); ALTER TABLE range_parted ATTACH PARTITION partr_def2 DEFAULT; ERROR: partition "partr_def2" would overlap partition "partr_def1" --- cannot attach overlapping partition +-- Overlapping partitions cannot be attached, hence, following should give error INSERT INTO partr_def1 VALUES (2, 10); CREATE TABLE part3 (LIKE range_parted); ALTER TABLE range_parted ATTACH partition part3 FOR VALUES FROM (2, 10) TO (2, 20); ERROR: new default partition constraint is violated by some row DETAIL: Violating row contains (2, 10). --- ok if no overlapping rows +-- Attaching partitions should be successful when there are no overlapping rows ALTER TABLE range_parted ATTACH partition part3 FOR VALUES FROM (3, 10) TO (3, 20); -- check that leaf partitions are scanned when attaching a partitioned -- table diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out index 57b56df46c..02a8e22832 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -599,12 +599,12 @@ CREATE TABLE fail_part PARTITION OF range_parted2 FOR VALUES FROM (10) TO (30); ERROR: partition "fail_part" would overlap partition "part2" CREATE TABLE fail_part PARTITION OF range_parted2 FOR VALUES FROM (10) TO (50); ERROR: partition "fail_part" would overlap partition "part3" --- range default partition +-- Create a default partition for range partitioned table CREATE TABLE range2_default PARTITION OF range_parted2 DEFAULT; --- cannot allow 2 default partition +-- More than one default partition is not allowed, so this should give error CREATE TABLE fail_default_part PARTITION OF range_parted2 DEFAULT; ERROR: partition "fail_default_part" would overlap partition "range2_default" --- check default overlap +-- Check if the range for default partitions overlap INSERT INTO range_parted2 VALUES (85); CREATE TABLE fail_part PARTITION OF range_parted2 FOR VALUES FROM (80) TO (90); ERROR: new default partition constraint is violated by some row diff --git a/src/test/regress/expected/insert.out b/src/test/regress/expected/insert.out index 1885be70d6..61799ad7ec 100644 --- a/src/test/regress/expected/insert.out +++ b/src/test/regress/expected/insert.out @@ -274,11 +274,11 @@ ERROR: no partition of relation "range_parted" found for row DETAIL: Partition key of the failing row contains (a, (b + 0)) = (a, null). -- Check default partition create table part_def partition of range_parted default; --- fail +-- Following statement should fail insert into part_def values ('b', 10); ERROR: new row for relation "part_def" violates partition constraint DETAIL: Failing row contains (b, 10). --- ok +-- Following should complete successfully insert into part_def values ('c', 10); insert into range_parted values (null, null); select tableoid::regclass, * from range_parted; @@ -444,14 +444,14 @@ with ins (a, b, c) as mlparted4 | 1 | 30 | 39 (5 rows) --- check multi-level default partition +-- Check multi-level default partition create table mlparted_def partition of mlparted default partition by range(a); create table mlparted_def1 partition of mlparted_def for values from (40) to (50); create table mlparted_def2 partition of mlparted_def for values from (50) to (60); insert into mlparted values (40, 100); insert into mlparted_def1 values (42, 100); insert into mlparted_def2 values (54, 50); --- fail +-- Following statements should fail insert into mlparted values (70, 100); ERROR: no partition of relation "mlparted_def" found for row DETAIL: Partition key of the failing row contains (a) = (70). @@ -461,7 +461,7 @@ DETAIL: Failing row contains (52, 50). insert into mlparted_def2 values (34, 50); ERROR: new row for relation "mlparted_def2" violates partition constraint DETAIL: Failing row contains (34, 50). --- ok +-- Following statements should complete successfully create table mlparted_defd partition of mlparted_def default; insert into mlparted values (70, 100); select tableoid::regclass, * from mlparted_def; diff --git a/src/test/regress/expected/update.out b/src/test/regress/expected/update.out index 70f37488dd..488b622a03 100644 --- a/src/test/regress/expected/update.out +++ b/src/test/regress/expected/update.out @@ -218,12 +218,12 @@ ERROR: new row for relation "part_b_10_b_20" violates partition constraint DETAIL: Failing row contains (b, 9). -- ok update range_parted set b = b + 1 where b = 10; --- default +-- Creating default partition for range create table part_def partition of range_parted default; insert into range_parted values ('c', 9); --- ok +-- Following statements should complete successfully update part_def set a = 'd' where a = 'c'; --- fail +-- Following statements should fail update part_def set a = 'a' where a = 'd'; ERROR: new row for relation "part_def" violates partition constraint DETAIL: Failing row contains (a, 9). diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql index db9cc0ad30..99f8155953 100644 --- a/src/test/regress/sql/alter_table.sql +++ b/src/test/regress/sql/alter_table.sql @@ -2169,16 +2169,19 @@ CREATE TABLE part2 ( ); ALTER TABLE range_parted ATTACH PARTITION part2 FOR VALUES FROM (1, 10) TO (1, 20); --- default partition +-- Create default partition CREATE TABLE partr_def1 PARTITION OF range_parted DEFAULT; --- cannot attach 2nd default + +-- Only one default partition is allowed, hence, following should give error CREATE TABLE partr_def2 (LIKE part1 INCLUDING CONSTRAINTS); ALTER TABLE range_parted ATTACH PARTITION partr_def2 DEFAULT; --- cannot attach overlapping partition + +-- Overlapping partitions cannot be attached, hence, following should give error INSERT INTO partr_def1 VALUES (2, 10); CREATE TABLE part3 (LIKE range_parted); ALTER TABLE range_parted ATTACH partition part3 FOR VALUES FROM (2, 10) TO (2, 20); --- ok if no overlapping rows + +-- Attaching partitions should be successful when there are no overlapping rows ALTER TABLE range_parted ATTACH partition part3 FOR VALUES FROM (3, 10) TO (3, 20); -- check that leaf partitions are scanned when attaching a partitioned diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/create_table.sql index 556e2b88ce..2011cbf2c0 100644 --- a/src/test/regress/sql/create_table.sql +++ b/src/test/regress/sql/create_table.sql @@ -557,11 +557,13 @@ CREATE TABLE part3 PARTITION OF range_parted2 FOR VALUES FROM (30) TO (40); CREATE TABLE fail_part PARTITION OF range_parted2 FOR VALUES FROM (10) TO (30); CREATE TABLE fail_part PARTITION OF range_parted2 FOR VALUES FROM (10) TO (50); --- range default partition +-- Create a default partition for range partitioned table CREATE TABLE range2_default PARTITION OF range_parted2 DEFAULT; --- cannot allow 2 default partition + +-- More than one default partition is not allowed, so this should give error CREATE TABLE fail_default_part PARTITION OF range_parted2 DEFAULT; --- check default overlap + +-- Check if the range for default partitions overlap INSERT INTO range_parted2 VALUES (85); CREATE TABLE fail_part PARTITION OF range_parted2 FOR VALUES FROM (80) TO (90); CREATE TABLE part4 PARTITION OF range_parted2 FOR VALUES FROM (90) TO (100); diff --git a/src/test/regress/sql/insert.sql b/src/test/regress/sql/insert.sql index 7f040f4cc5..41ff17651d 100644 --- a/src/test/regress/sql/insert.sql +++ b/src/test/regress/sql/insert.sql @@ -172,9 +172,11 @@ insert into range_parted values ('a'); -- Check default partition create table part_def partition of range_parted default; --- fail + +-- Following statement should fail insert into part_def values ('b', 10); --- ok + +-- Following should complete successfully insert into part_def values ('c', 10); insert into range_parted values (null, null); @@ -286,18 +288,20 @@ with ins (a, b, c) as (insert into mlparted (b, a) select s.a, 1 from generate_series(2, 39) s(a) returning tableoid::regclass, *) select a, b, min(c), max(c) from ins group by a, b order by 1; --- check multi-level default partition +-- Check multi-level default partition create table mlparted_def partition of mlparted default partition by range(a); create table mlparted_def1 partition of mlparted_def for values from (40) to (50); create table mlparted_def2 partition of mlparted_def for values from (50) to (60); insert into mlparted values (40, 100); insert into mlparted_def1 values (42, 100); insert into mlparted_def2 values (54, 50); --- fail + +-- Following statements should fail insert into mlparted values (70, 100); insert into mlparted_def1 values (52, 50); insert into mlparted_def2 values (34, 50); --- ok + +-- Following statements should complete successfully create table mlparted_defd partition of mlparted_def default; insert into mlparted values (70, 100); diff --git a/src/test/regress/sql/update.sql b/src/test/regress/sql/update.sql index b2902ab83d..3ff61fea9b 100644 --- a/src/test/regress/sql/update.sql +++ b/src/test/regress/sql/update.sql @@ -125,12 +125,14 @@ update range_parted set b = b - 1 where b = 10; -- ok update range_parted set b = b + 1 where b = 10; --- default +-- Creating default partition for range create table part_def partition of range_parted default; insert into range_parted values ('c', 9); --- ok + +-- Following statements should complete successfully update part_def set a = 'd' where a = 'c'; --- fail + +-- Following statements should fail update part_def set a = 'a' where a = 'd'; create table list_parted (