Skip to content

Commit d43a97e

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 dc3648f commit d43a97e

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
@@ -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

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

935935
Assert(partRelInfo->ri_BatchSize >= 1);
936936

937-
/*
938-
* If doing batch insert, setup back-link so we can easily find the
939-
* mtstate again.
940-
*/
941-
if (partRelInfo->ri_BatchSize > 1)
942-
partRelInfo->ri_ModifyTableState = mtstate;
943-
944937
partRelInfo->ri_CopyMultiInsertBuffer = NULL;
945938

946939
/*

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
@@ -742,10 +742,12 @@ ExecInsert(ModifyTableState *mtstate,
742742

743743
/*
744744
* If these are the first tuples stored in the buffers, add the
745-
* target rel to the es_insert_pending_result_relations list,
746-
* except in the case where flushing was done above, in which case
747-
* the target rel would already have been added to the list, so no
748-
* need to do this.
745+
* target rel and the mtstate to the
746+
* es_insert_pending_result_relations and
747+
* es_insert_pending_modifytables lists respectively, execpt in
748+
* the case where flushing was done above, in which case they
749+
* would already have been added to the lists, so no need to do
750+
* this.
749751
*/
750752
if (resultRelInfo->ri_NumSlots == 0 && !flushed)
751753
{
@@ -754,6 +756,8 @@ ExecInsert(ModifyTableState *mtstate,
754756
estate->es_insert_pending_result_relations =
755757
lappend(estate->es_insert_pending_result_relations,
756758
resultRelInfo);
759+
estate->es_insert_pending_modifytables =
760+
lappend(estate->es_insert_pending_modifytables, mtstate);
757761
}
758762
Assert(list_member_ptr(estate->es_insert_pending_result_relations,
759763
resultRelInfo));
@@ -1445,12 +1449,14 @@ ldelete:;
14451449
static void
14461450
ExecPendingInserts(EState *estate)
14471451
{
1448-
ListCell *lc;
1452+
ListCell *l1,
1453+
*l2;
14491454

1450-
foreach(lc, estate->es_insert_pending_result_relations)
1455+
forboth(l1, estate->es_insert_pending_result_relations,
1456+
l2, estate->es_insert_pending_modifytables)
14511457
{
1452-
ResultRelInfo *resultRelInfo = (ResultRelInfo *) lfirst(lc);
1453-
ModifyTableState *mtstate = resultRelInfo->ri_ModifyTableState;
1458+
ResultRelInfo *resultRelInfo = (ResultRelInfo *) lfirst(l1);
1459+
ModifyTableState *mtstate = (ModifyTableState *) lfirst(l2);
14541460

14551461
Assert(mtstate);
14561462
ExecBatchInsert(mtstate, resultRelInfo,
@@ -1462,7 +1468,9 @@ ExecPendingInserts(EState *estate)
14621468
}
14631469

14641470
list_free(estate->es_insert_pending_result_relations);
1471+
list_free(estate->es_insert_pending_modifytables);
14651472
estate->es_insert_pending_result_relations = NIL;
1473+
estate->es_insert_pending_modifytables = NIL;
14661474
}
14671475

14681476
/*
@@ -3183,13 +3191,6 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
31833191
}
31843192
else
31853193
resultRelInfo->ri_BatchSize = 1;
3186-
3187-
/*
3188-
* If doing batch insert, setup back-link so we can easily find the
3189-
* mtstate again.
3190-
*/
3191-
if (resultRelInfo->ri_BatchSize > 1)
3192-
resultRelInfo->ri_ModifyTableState = mtstate;
31933194
}
31943195

31953196
/*

src/include/nodes/execnodes.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,6 @@ typedef struct ResultRelInfo
524524

525525
/* for use by copyfrom.c when performing multi-inserts */
526526
struct CopyMultiInsertBuffer *ri_CopyMultiInsertBuffer;
527-
528-
/* for use by nodeModifyTable.c when performing batch-inserts */
529-
struct ModifyTableState *ri_ModifyTableState;
530527
} ResultRelInfo;
531528

532529
/* ----------------
@@ -650,10 +647,11 @@ typedef struct EState
650647
struct JitInstrumentation *es_jit_worker_instr;
651648

652649
/*
653-
* The following list contains ResultRelInfos for foreign tables on which
654-
* batch-inserts are to be executed.
650+
* Lists of ResultRelInfos for foreign tables on which batch-inserts are
651+
* to be executed and owning ModifyTableStates, stored in the same order.
655652
*/
656653
List *es_insert_pending_result_relations;
654+
List *es_insert_pending_modifytables;
657655
} EState;
658656

659657

0 commit comments

Comments
 (0)