]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Remove new structure member from ResultRelInfo.
authorEtsuro Fujita <efujita@postgresql.org>
Thu, 8 Dec 2022 07:15:01 +0000 (16:15 +0900)
committerEtsuro Fujita <efujita@postgresql.org>
Thu, 8 Dec 2022 07:15:01 +0000 (16:15 +0900)
In commit ffbb7e65a, 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

src/backend/executor/execMain.c
src/backend/executor/execPartition.c
src/backend/executor/execUtils.c
src/backend/executor/nodeModifyTable.c
src/include/nodes/execnodes.h

index ea64adc0259a0e661cb74145ce04b45c99115150..ef2fd46092e8f0647658819f142d174a50b81f0d 100644 (file)
@@ -1261,7 +1261,6 @@ InitResultRelInfo(ResultRelInfo *resultRelInfo,
        resultRelInfo->ri_ChildToRootMap = NULL;
        resultRelInfo->ri_ChildToRootMapValid = false;
        resultRelInfo->ri_CopyMultiInsertBuffer = NULL;
-       resultRelInfo->ri_ModifyTableState = NULL;
 }
 
 /*
index 7cc5b10f0397c261de4784767dfac66352530b39..e03ea27299c8ee929b96e07673e41d6b64cf83ee 100644 (file)
@@ -1035,13 +1035,6 @@ ExecInitRoutingInfo(ModifyTableState *mtstate,
 
        Assert(partRelInfo->ri_BatchSize >= 1);
 
-       /*
-        * If doing batch insert, setup back-link so we can easily find the
-        * mtstate again.
-        */
-       if (partRelInfo->ri_BatchSize > 1)
-               partRelInfo->ri_ModifyTableState = mtstate;
-
        partRelInfo->ri_CopyMultiInsertBuffer = NULL;
 
        /*
index 0e595ffa6e5e3476daf271505722eb14574dc561..358e5828831834c599c56aad0b1ca02c06bb6383 100644 (file)
@@ -127,9 +127,11 @@ CreateExecutorState(void)
        estate->es_result_relations = NULL;
        estate->es_opened_result_relations = NIL;
        estate->es_tuple_routing_result_relations = NIL;
-       estate->es_insert_pending_result_relations = NIL;
        estate->es_trig_target_relations = NIL;
 
+       estate->es_insert_pending_result_relations = NIL;
+       estate->es_insert_pending_modifytables = NIL;
+
        estate->es_param_list_info = NULL;
        estate->es_param_exec_vals = NULL;
 
index ec84125aec375ae0c8d0df1ace61e800ac9e7f62..8794528d6af6fcfc5ad3b0bded3db033a6f79085 100644 (file)
@@ -858,10 +858,12 @@ ExecInsert(ModifyTableContext *context,
 
                        /*
                         * If these are the first tuples stored in the buffers, add the
-                        * target rel to the es_insert_pending_result_relations list,
-                        * except in the case where flushing was done above, in which case
-                        * the target rel would already have been added to the list, so no
-                        * need to do this.
+                        * target rel and the mtstate to the
+                        * es_insert_pending_result_relations and
+                        * es_insert_pending_modifytables lists respectively, execpt in
+                        * the case where flushing was done above, in which case they
+                        * would already have been added to the lists, so no need to do
+                        * this.
                         */
                        if (resultRelInfo->ri_NumSlots == 0 && !flushed)
                        {
@@ -870,6 +872,8 @@ ExecInsert(ModifyTableContext *context,
                                estate->es_insert_pending_result_relations =
                                        lappend(estate->es_insert_pending_result_relations,
                                                        resultRelInfo);
+                               estate->es_insert_pending_modifytables =
+                                       lappend(estate->es_insert_pending_modifytables, mtstate);
                        }
                        Assert(list_member_ptr(estate->es_insert_pending_result_relations,
                                                                   resultRelInfo));
@@ -1219,12 +1223,14 @@ ExecBatchInsert(ModifyTableState *mtstate,
 static void
 ExecPendingInserts(EState *estate)
 {
-       ListCell   *lc;
+       ListCell   *l1,
+                          *l2;
 
-       foreach(lc, estate->es_insert_pending_result_relations)
+       forboth(l1, estate->es_insert_pending_result_relations,
+                       l2, estate->es_insert_pending_modifytables)
        {
-               ResultRelInfo *resultRelInfo = (ResultRelInfo *) lfirst(lc);
-               ModifyTableState *mtstate = resultRelInfo->ri_ModifyTableState;
+               ResultRelInfo *resultRelInfo = (ResultRelInfo *) lfirst(l1);
+               ModifyTableState *mtstate = (ModifyTableState *) lfirst(l2);
 
                Assert(mtstate);
                ExecBatchInsert(mtstate, resultRelInfo,
@@ -1236,7 +1242,9 @@ ExecPendingInserts(EState *estate)
        }
 
        list_free(estate->es_insert_pending_result_relations);
+       list_free(estate->es_insert_pending_modifytables);
        estate->es_insert_pending_result_relations = NIL;
+       estate->es_insert_pending_modifytables = NIL;
 }
 
 /*
@@ -4342,13 +4350,6 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
                }
                else
                        resultRelInfo->ri_BatchSize = 1;
-
-               /*
-                * If doing batch insert, setup back-link so we can easily find the
-                * mtstate again.
-                */
-               if (resultRelInfo->ri_BatchSize > 1)
-                       resultRelInfo->ri_ModifyTableState = mtstate;
        }
 
        /*
index 05ec9f2bf75dc0bd536716e20b8ae2087f5ad4b8..580e99242be956870368f3ec07c0013a65c1f404 100644 (file)
@@ -556,9 +556,6 @@ typedef struct ResultRelInfo
         * one of its ancestors; see ExecCrossPartitionUpdateForeignKey().
         */
        List       *ri_ancestorResultRels;
-
-       /* for use by nodeModifyTable.c when performing batch-inserts */
-       struct ModifyTableState *ri_ModifyTableState;
 } ResultRelInfo;
 
 /* ----------------
@@ -682,10 +679,11 @@ typedef struct EState
        struct JitInstrumentation *es_jit_worker_instr;
 
        /*
-        * The following list contains ResultRelInfos for foreign tables on which
-        * batch-inserts are to be executed.
+        * Lists of ResultRelInfos for foreign tables on which batch-inserts are
+        * to be executed and owning ModifyTableStates, stored in the same order.
         */
        List       *es_insert_pending_result_relations;
+       List       *es_insert_pending_modifytables;
 } EState;