Commit 59c80787 authored by Robert Haas's avatar Robert Haas

Fix uninitialized memory reference.

Without this, when partdesc->nparts == 0, we end up calling
ExecBuildSlotPartitionKeyDescription without initializing values
and isnull.

Reported by Coverity via Michael Paquier.  Patch by Michael Paquier,
reviewed and revised by Amit Langote.

Discussion: http://postgr.es/m/CAB7nPqQ3mwkdMoPY-ocgTpPnjd8TKOadMxdTtMLvEzF8480Zfg@mail.gmail.com
parent 86ab28fb
...@@ -206,13 +206,6 @@ ExecFindPartition(ResultRelInfo *resultRelInfo, PartitionDispatch *pd, ...@@ -206,13 +206,6 @@ ExecFindPartition(ResultRelInfo *resultRelInfo, PartitionDispatch *pd,
slot = myslot; slot = myslot;
} }
/* Quick exit */
if (partdesc->nparts == 0)
{
result = -1;
break;
}
/* /*
* Extract partition key from tuple. Expression evaluation machinery * Extract partition key from tuple. Expression evaluation machinery
* that FormPartitionKeyDatum() invokes expects ecxt_scantuple to * that FormPartitionKeyDatum() invokes expects ecxt_scantuple to
...@@ -223,6 +216,17 @@ ExecFindPartition(ResultRelInfo *resultRelInfo, PartitionDispatch *pd, ...@@ -223,6 +216,17 @@ ExecFindPartition(ResultRelInfo *resultRelInfo, PartitionDispatch *pd,
*/ */
ecxt->ecxt_scantuple = slot; ecxt->ecxt_scantuple = slot;
FormPartitionKeyDatum(parent, slot, estate, values, isnull); FormPartitionKeyDatum(parent, slot, estate, values, isnull);
/*
* Nothing for get_partition_for_tuple() to do if there are no
* partitions to begin with.
*/
if (partdesc->nparts == 0)
{
result = -1;
break;
}
cur_index = get_partition_for_tuple(rel, values, isnull); cur_index = get_partition_for_tuple(rel, values, isnull);
/* /*
......
...@@ -165,6 +165,10 @@ create table range_parted ( ...@@ -165,6 +165,10 @@ create table range_parted (
a text, a text,
b int b int
) partition by range (a, (b+0)); ) partition by range (a, (b+0));
-- no partitions, so fail
insert into range_parted values ('a', 11);
ERROR: no partition of relation "range_parted" found for row
DETAIL: Partition key of the failing row contains (a, (b + 0)) = (a, 11).
create table part1 partition of range_parted for values from ('a', 1) to ('a', 10); create table part1 partition of range_parted for values from ('a', 1) to ('a', 10);
create table part2 partition of range_parted for values from ('a', 10) to ('a', 20); create table part2 partition of range_parted for values from ('a', 10) to ('a', 20);
create table part3 partition of range_parted for values from ('b', 1) to ('b', 10); create table part3 partition of range_parted for values from ('b', 1) to ('b', 10);
......
...@@ -90,6 +90,10 @@ create table range_parted ( ...@@ -90,6 +90,10 @@ create table range_parted (
a text, a text,
b int b int
) partition by range (a, (b+0)); ) partition by range (a, (b+0));
-- no partitions, so fail
insert into range_parted values ('a', 11);
create table part1 partition of range_parted for values from ('a', 1) to ('a', 10); create table part1 partition of range_parted for values from ('a', 1) to ('a', 10);
create table part2 partition of range_parted for values from ('a', 10) to ('a', 20); create table part2 partition of range_parted for values from ('a', 10) to ('a', 20);
create table part3 partition of range_parted for values from ('b', 1) to ('b', 10); create table part3 partition of range_parted for values from ('b', 1) to ('b', 10);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment