From 983c950ec26ef88127c1c349f6fa34f754a239f0 Mon Sep 17 00:00:00 2001 From: Amul Sul Date: Tue, 27 Oct 2020 00:45:35 -0400 Subject: [PATCH] Fix assertion. --- src/backend/partitioning/partbounds.c | 10 +++------- src/test/regress/expected/create_table.out | 4 ++++ src/test/regress/sql/create_table.sql | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c index 66c42b58986..c8a42b4970d 100644 --- a/src/backend/partitioning/partbounds.c +++ b/src/backend/partitioning/partbounds.c @@ -3061,7 +3061,7 @@ check_new_partition_bound(char *relname, Relation parent, * datums list. */ PartitionRangeDatum *datum = - list_nth(spec->upperdatums, -cmpval - 1); + list_nth(spec->upperdatums, Abs(cmpval) - 1); /* * The new partition overlaps with the @@ -3084,14 +3084,10 @@ check_new_partition_bound(char *relname, Relation parent, /* * Fetch the problematic key from the lower datums - * list. Given the way partition_range_bsearch() - * works, the new lower bound is certainly >= the - * bound at offset. If the bound matches exactly, we - * flag the 1st key. + * list. */ - Assert(cmpval >= 0); datum = cmpval == 0 ? linitial(spec->lowerdatums) : - list_nth(spec->lowerdatums, cmpval - 1); + list_nth(spec->lowerdatums, Abs(cmpval) - 1); overlap = true; overlap_location = datum->location; with = boundinfo->indexes[offset + 1]; diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out index 1fc266dd65c..ed8c01b8dec 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -856,6 +856,10 @@ ERROR: partition "fail_part" would overlap partition "part0" LINE 1: ..._part PARTITION OF range_parted2 FOR VALUES FROM (minvalue) ... ^ CREATE TABLE part1 PARTITION OF range_parted2 FOR VALUES FROM (1) TO (10); +CREATE TABLE fail_part PARTITION OF range_parted2 FOR VALUES FROM (-1) TO (1); +ERROR: partition "fail_part" would overlap partition "part0" +LINE 1: ..._part PARTITION OF range_parted2 FOR VALUES FROM (-1) TO (1)... + ^ CREATE TABLE fail_part PARTITION OF range_parted2 FOR VALUES FROM (9) TO (maxvalue); ERROR: partition "fail_part" would overlap partition "part1" LINE 1: ..._part PARTITION OF range_parted2 FOR VALUES FROM (9) TO (max... diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/create_table.sql index cee822aa8b6..d257679ba68 100644 --- a/src/test/regress/sql/create_table.sql +++ b/src/test/regress/sql/create_table.sql @@ -687,6 +687,7 @@ CREATE TABLE fail_part PARTITION OF range_parted2 FOR VALUES FROM (1) TO (1); CREATE TABLE part0 PARTITION OF range_parted2 FOR VALUES FROM (minvalue) TO (1); CREATE TABLE fail_part PARTITION OF range_parted2 FOR VALUES FROM (minvalue) TO (2); CREATE TABLE part1 PARTITION OF range_parted2 FOR VALUES FROM (1) TO (10); +CREATE TABLE fail_part PARTITION OF range_parted2 FOR VALUES FROM (-1) TO (1); CREATE TABLE fail_part PARTITION OF range_parted2 FOR VALUES FROM (9) TO (maxvalue); CREATE TABLE part2 PARTITION OF range_parted2 FOR VALUES FROM (20) TO (30); CREATE TABLE part3 PARTITION OF range_parted2 FOR VALUES FROM (30) TO (40); -- 2.18.0