Skip to content

Commit a0bf7a0

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 6bcd1d9 commit a0bf7a0

File tree

5 files changed

+22
-29
lines changed

5 files changed

+22
-29
lines changed

src/backend/executor/execMain.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,6 @@ InitResultRelInfo(ResultRelInfo *resultRelInfo,
12611261
resultRelInfo->ri_ChildToRootMap = NULL;
12621262
resultRelInfo->ri_ChildToRootMapValid = false;
12631263
resultRelInfo->ri_CopyMultiInsertBuffer = NULL;
1264-
resultRelInfo->ri_ModifyTableState = NULL;
12651264
}
12661265

12671266
/*

src/backend/executor/execPartition.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,13 +1035,6 @@ ExecInitRoutingInfo(ModifyTableState *mtstate,
10351035

10361036
Assert(partRelInfo->ri_BatchSize >= 1);
10371037

1038-
/*
1039-
* If doing batch insert, setup back-link so we can easily find the
1040-
* mtstate again.
1041-
*/
1042-
if (partRelInfo->ri_BatchSize > 1)
1043-
partRelInfo->ri_ModifyTableState = mtstate;
1044-
10451038
partRelInfo->ri_CopyMultiInsertBuffer = NULL;
10461039

10471040
/*

src/backend/executor/execUtils.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ CreateExecutorState(void)
127127
estate->es_result_relations = NULL;
128128
estate->es_opened_result_relations = NIL;
129129
estate->es_tuple_routing_result_relations = NIL;
130-
estate->es_insert_pending_result_relations = NIL;
131130
estate->es_trig_target_relations = NIL;
132131

132+
estate->es_insert_pending_result_relations = NIL;
133+
estate->es_insert_pending_modifytables = NIL;
134+
133135
estate->es_param_list_info = NULL;
134136
estate->es_param_exec_vals = NULL;
135137

src/backend/executor/nodeModifyTable.c

Lines changed: 16 additions & 15 deletions
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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,6 @@ typedef struct ResultRelInfo
556556
* one of its ancestors; see ExecCrossPartitionUpdateForeignKey().
557557
*/
558558
List *ri_ancestorResultRels;
559-
560-
/* for use by nodeModifyTable.c when performing batch-inserts */
561-
struct ModifyTableState *ri_ModifyTableState;
562559
} ResultRelInfo;
563560

564561
/* ----------------
@@ -682,10 +679,11 @@ typedef struct EState
682679
struct JitInstrumentation *es_jit_worker_instr;
683680

684681
/*
685-
* The following list contains ResultRelInfos for foreign tables on which
686-
* batch-inserts are to be executed.
682+
* Lists of ResultRelInfos for foreign tables on which batch-inserts are
683+
* to be executed and owning ModifyTableStates, stored in the same order.
687684
*/
688685
List *es_insert_pending_result_relations;
686+
List *es_insert_pending_modifytables;
689687
} EState;
690688

691689

0 commit comments

Comments
 (0)