Skip to content

Commit 2d7950f

Browse files
committed
If a range-partitioned table has no default partition, reject null keys.
Commit 4e5fe9a introduced this problem. Also add a test so it doesn't get broken again. Report by Rushabh Lathia. Fix by Amit Langote. Reviewed by Rushabh Lathia and Amul Sul. Tweaked by me. Discussion: http://postgr.es/m/CAGPqQf0Y1iJyk4QJBdMf=pS9i6Q0JUMM_h5-qkR3OMJ-e04PyA@mail.gmail.com
1 parent 62546b4 commit 2d7950f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/backend/catalog/partition.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,11 +2553,10 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
25532553
*/
25542554
for (i = 0; i < key->partnatts; i++)
25552555
{
2556-
if (isnull[i] &&
2557-
partition_bound_has_default(partdesc->boundinfo))
2556+
if (isnull[i])
25582557
{
25592558
range_partkey_has_null = true;
2560-
part_index = partdesc->boundinfo->default_index;
2559+
break;
25612560
}
25622561
}
25632562

src/test/regress/expected/insert.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,10 @@ create table mcrparted2 partition of mcrparted for values from (10, 6, minvalue)
659659
create table mcrparted3 partition of mcrparted for values from (11, 1, 1) to (20, 10, 10);
660660
create table mcrparted4 partition of mcrparted for values from (21, minvalue, minvalue) to (30, 20, maxvalue);
661661
create table mcrparted5 partition of mcrparted for values from (30, 21, 20) to (maxvalue, maxvalue, maxvalue);
662+
-- null not allowed in range partition
663+
insert into mcrparted values (null, null, null);
664+
ERROR: no partition of relation "mcrparted" found for row
665+
DETAIL: Partition key of the failing row contains (a, abs(b), c) = (null, null, null).
662666
-- routed to mcrparted0
663667
insert into mcrparted values (0, 1, 1);
664668
insert into mcrparted0 values (0, 1, 1);

src/test/regress/sql/insert.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ create table mcrparted3 partition of mcrparted for values from (11, 1, 1) to (20
421421
create table mcrparted4 partition of mcrparted for values from (21, minvalue, minvalue) to (30, 20, maxvalue);
422422
create table mcrparted5 partition of mcrparted for values from (30, 21, 20) to (maxvalue, maxvalue, maxvalue);
423423

424+
-- null not allowed in range partition
425+
insert into mcrparted values (null, null, null);
426+
424427
-- routed to mcrparted0
425428
insert into mcrparted values (0, 1, 1);
426429
insert into mcrparted0 values (0, 1, 1);

0 commit comments

Comments
 (0)