Skip to content

Commit 4b3e379

Browse files
author
Etsuro Fujita
committed
Remove new structure member from ResultRelInfo.
In commit ffbb7e6, I added a ModifyTableState member to ResultRelInfo to save the owning ModifyTableState for use by nodeModifyTable.c when performing batch inserts, but as pointed out by Tom Lane, that changed the array stride of es_result_relations, and that would break any previously-compiled extension code that accesses that array. Fix by removing that member from ResultRelInfo and instead adding a List member at the end of EState to save such ModifyTableStates. Per report from Tom Lane. Back-patch to v14, like the previous commit; I chose to apply the patch to HEAD as well, to make back-patching easy. Discussion: http://postgr.es/m/4065383.1669395453%40sss.pgh.pa.us
1 parent d3b111e commit 4b3e379

File tree

5 files changed

+22
-29
lines changed

5 files changed

+22
-29
lines changed

src/backend/executor/execMain.c

-1
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,6 @@ InitResultRelInfo(ResultRelInfo *resultRelInfo,
12571257
resultRelInfo->ri_ChildToRootMap = NULL;
12581258
resultRelInfo->ri_ChildToRootMapValid = false;
12591259
resultRelInfo->ri_CopyMultiInsertBuffer = NULL;
1260-
resultRelInfo->ri_ModifyTableState = NULL;
12611260
}
12621261

12631262
/*

src/backend/executor/execPartition.c

-7
Original file line numberDiff line numberDiff line change
@@ -1029,13 +1029,6 @@ ExecInitRoutingInfo(ModifyTableState *mtstate,
10291029

10301030
Assert(partRelInfo->ri_BatchSize >= 1);
10311031

1032-
/*
1033-
* If doing batch insert, setup back-link so we can easily find the
1034-
* mtstate again.
1035-
*/
1036-
if (partRelInfo->ri_BatchSize > 1)
1037-
partRelInfo->ri_ModifyTableState = mtstate;
1038-
10391032
partRelInfo->ri_CopyMultiInsertBuffer = NULL;
10401033

10411034
/*

src/backend/executor/execUtils.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ CreateExecutorState(void)
130130
estate->es_result_relations = NULL;
131131
estate->es_opened_result_relations = NIL;
132132
estate->es_tuple_routing_result_relations = NIL;
133-
estate->es_insert_pending_result_relations = NIL;
134133
estate->es_trig_target_relations = NIL;
135134

135+
estate->es_insert_pending_result_relations = NIL;
136+
estate->es_insert_pending_modifytables = NIL;
137+
136138
estate->es_param_list_info = NULL;
137139
estate->es_param_exec_vals = NULL;
138140

src/backend/executor/nodeModifyTable.c

+16-15
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,12 @@ ExecInsert(ModifyTableContext *context,
858858

859859
/*
860860
* If these are the first tuples stored in the buffers, add the
861-
* target rel to the es_insert_pending_result_relations list,
862-
* except in the case where flushing was done above, in which case
863-
* the target rel would already have been added to the list, so no
864-
* need to do this.
861+
* target rel and the mtstate to the
862+
* es_insert_pending_result_relations and
863+
* es_insert_pending_modifytables lists respectively, execpt in
864+
* the case where flushing was done above, in which case they
865+
* would already have been added to the lists, so no need to do
866+
* this.
865867
*/
866868
if (resultRelInfo->ri_NumSlots == 0 && !flushed)
867869
{
@@ -870,6 +872,8 @@ ExecInsert(ModifyTableContext *context,
870872
estate->es_insert_pending_result_relations =
871873
lappend(estate->es_insert_pending_result_relations,
872874
resultRelInfo);
875+
estate->es_insert_pending_modifytables =
876+
lappend(estate->es_insert_pending_modifytables, mtstate);
873877
}
874878
Assert(list_member_ptr(estate->es_insert_pending_result_relations,
875879
resultRelInfo));
@@ -1219,12 +1223,14 @@ ExecBatchInsert(ModifyTableState *mtstate,
12191223
static void
12201224
ExecPendingInserts(EState *estate)
12211225
{
1222-
ListCell *lc;
1226+
ListCell *l1,
1227+
*l2;
12231228

1224-
foreach(lc, estate->es_insert_pending_result_relations)
1229+
forboth(l1, estate->es_insert_pending_result_relations,
1230+
l2, estate->es_insert_pending_modifytables)
12251231
{
1226-
ResultRelInfo *resultRelInfo = (ResultRelInfo *) lfirst(lc);
1227-
ModifyTableState *mtstate = resultRelInfo->ri_ModifyTableState;
1232+
ResultRelInfo *resultRelInfo = (ResultRelInfo *) lfirst(l1);
1233+
ModifyTableState *mtstate = (ModifyTableState *) lfirst(l2);
12281234

12291235
Assert(mtstate);
12301236
ExecBatchInsert(mtstate, resultRelInfo,
@@ -1236,7 +1242,9 @@ ExecPendingInserts(EState *estate)
12361242
}
12371243

12381244
list_free(estate->es_insert_pending_result_relations);
1245+
list_free(estate->es_insert_pending_modifytables);
12391246
estate->es_insert_pending_result_relations = NIL;
1247+
estate->es_insert_pending_modifytables = NIL;
12401248
}
12411249

12421250
/*
@@ -4342,13 +4350,6 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
43424350
}
43434351
else
43444352
resultRelInfo->ri_BatchSize = 1;
4345-
4346-
/*
4347-
* If doing batch insert, setup back-link so we can easily find the
4348-
* mtstate again.
4349-
*/
4350-
if (resultRelInfo->ri_BatchSize > 1)
4351-
resultRelInfo->ri_ModifyTableState = mtstate;
43524353
}
43534354

43544355
/*

src/include/nodes/execnodes.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,6 @@ typedef struct ResultRelInfo
575575
* one of its ancestors; see ExecCrossPartitionUpdateForeignKey().
576576
*/
577577
List *ri_ancestorResultRels;
578-
579-
/* for use by nodeModifyTable.c when performing batch-inserts */
580-
struct ModifyTableState *ri_ModifyTableState;
581578
} ResultRelInfo;
582579

583580
/* ----------------
@@ -703,10 +700,11 @@ typedef struct EState
703700
struct JitInstrumentation *es_jit_worker_instr;
704701

705702
/*
706-
* The following list contains ResultRelInfos for foreign tables on which
707-
* batch-inserts are to be executed.
703+
* Lists of ResultRelInfos for foreign tables on which batch-inserts are
704+
* to be executed and owning ModifyTableStates, stored in the same order.
708705
*/
709706
List *es_insert_pending_result_relations;
707+
List *es_insert_pending_modifytables;
710708
} EState;
711709

712710

0 commit comments

Comments
 (0)