Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b609c5f

Browse files
committed
Fix nasty bug in select_partition_for_insert().
Many thanks to @arssher.
1 parent b3eac64 commit b609c5f

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/include/partition_filter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void fini_result_parts_storage(ResultPartsStorage *parts_storage);
167167
ResultRelInfoHolder * scan_result_parts_storage(ResultPartsStorage *storage, Oid partid);
168168

169169
/* Refresh PartRelationInfo in storage */
170-
void refresh_result_parts_storage(ResultPartsStorage *parts_storage, Oid partid);
170+
PartRelationInfo * refresh_result_parts_storage(ResultPartsStorage *parts_storage, Oid partid);
171171

172172
TupleConversionMap * build_part_tuple_map(Relation parent_rel, Relation child_rel);
173173

src/partition_filter.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,16 @@ scan_result_parts_storage(ResultPartsStorage *parts_storage, Oid partid)
381381
}
382382

383383
/* Refresh PartRelationInfo for the partition in storage */
384-
void
384+
PartRelationInfo *
385385
refresh_result_parts_storage(ResultPartsStorage *parts_storage, Oid partid)
386386
{
387387
if (partid == PrelParentRelid(parts_storage->prel))
388388
{
389389
close_pathman_relation_info(parts_storage->prel);
390390
parts_storage->prel = get_pathman_relation_info(partid);
391391
shout_if_prel_is_invalid(partid, parts_storage->prel, PT_ANY);
392+
393+
return parts_storage->prel;
392394
}
393395
else
394396
{
@@ -398,12 +400,14 @@ refresh_result_parts_storage(ResultPartsStorage *parts_storage, Oid partid)
398400
(const void *) &partid,
399401
HASH_FIND, NULL);
400402

401-
if (rri_holder && rri_holder->prel)
402-
{
403-
close_pathman_relation_info(rri_holder->prel);
404-
rri_holder->prel = get_pathman_relation_info(partid);
405-
shout_if_prel_is_invalid(partid, rri_holder->prel, PT_ANY);
406-
}
403+
/* We must have entry (since we got 'prel' from it) */
404+
Assert(rri_holder && rri_holder->prel);
405+
406+
close_pathman_relation_info(rri_holder->prel);
407+
rri_holder->prel = get_pathman_relation_info(partid);
408+
shout_if_prel_is_invalid(partid, rri_holder->prel, PT_ANY);
409+
410+
return rri_holder->prel;
407411
}
408412
}
409413

@@ -543,7 +547,7 @@ select_partition_for_insert(ResultPartsStorage *parts_storage,
543547
if ((nparts == 0 || result == NULL) && !PrelIsFresh(prel))
544548
{
545549
/* Try building a new 'prel' for this relation */
546-
refresh_result_parts_storage(parts_storage, parent_relid);
550+
prel = refresh_result_parts_storage(parts_storage, parent_relid);
547551
}
548552

549553
/* This partition is a parent itself */
@@ -557,6 +561,8 @@ select_partition_for_insert(ResultPartsStorage *parts_storage,
557561
/* Repeat with a new dispatch */
558562
result = NULL;
559563
}
564+
565+
Assert(prel);
560566
}
561567
/* Loop until we get some result */
562568
while (result == NULL);

0 commit comments

Comments
 (0)