Skip to content

Commit 59c8078

Browse files
committed
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
1 parent 86ab28f commit 59c8078

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/backend/executor/execPartition.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,6 @@ ExecFindPartition(ResultRelInfo *resultRelInfo, PartitionDispatch *pd,
206206
slot = myslot;
207207
}
208208

209-
/* Quick exit */
210-
if (partdesc->nparts == 0)
211-
{
212-
result = -1;
213-
break;
214-
}
215-
216209
/*
217210
* Extract partition key from tuple. Expression evaluation machinery
218211
* that FormPartitionKeyDatum() invokes expects ecxt_scantuple to
@@ -223,6 +216,17 @@ ExecFindPartition(ResultRelInfo *resultRelInfo, PartitionDispatch *pd,
223216
*/
224217
ecxt->ecxt_scantuple = slot;
225218
FormPartitionKeyDatum(parent, slot, estate, values, isnull);
219+
220+
/*
221+
* Nothing for get_partition_for_tuple() to do if there are no
222+
* partitions to begin with.
223+
*/
224+
if (partdesc->nparts == 0)
225+
{
226+
result = -1;
227+
break;
228+
}
229+
226230
cur_index = get_partition_for_tuple(rel, values, isnull);
227231

228232
/*

src/test/regress/expected/insert.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ create table range_parted (
165165
a text,
166166
b int
167167
) partition by range (a, (b+0));
168+
-- no partitions, so fail
169+
insert into range_parted values ('a', 11);
170+
ERROR: no partition of relation "range_parted" found for row
171+
DETAIL: Partition key of the failing row contains (a, (b + 0)) = (a, 11).
168172
create table part1 partition of range_parted for values from ('a', 1) to ('a', 10);
169173
create table part2 partition of range_parted for values from ('a', 10) to ('a', 20);
170174
create table part3 partition of range_parted for values from ('b', 1) to ('b', 10);

src/test/regress/sql/insert.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ create table range_parted (
9090
a text,
9191
b int
9292
) partition by range (a, (b+0));
93+
94+
-- no partitions, so fail
95+
insert into range_parted values ('a', 11);
96+
9397
create table part1 partition of range_parted for values from ('a', 1) to ('a', 10);
9498
create table part2 partition of range_parted for values from ('a', 10) to ('a', 20);
9599
create table part3 partition of range_parted for values from ('b', 1) to ('b', 10);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy