Fix initialization of FDW batching in ExecInitModifyTable
authorTomas Vondra <tomas.vondra@postgresql.org>
Thu, 21 Jan 2021 02:23:24 +0000 (03:23 +0100)
committerTomas Vondra <tomas.vondra@postgresql.org>
Thu, 21 Jan 2021 02:34:32 +0000 (03:34 +0100)
ExecInitModifyTable has to initialize batching for all result relations,
not just the first one. Furthermore, when junk filters were necessary,
the pointer pointed past the mtstate->resultRelInfo array.

Per reports from multiple non-x86 animals (florican, locust, ...).

Discussion: https://postgr.es/m/20200628151002.7x5laxwpgvkyiu3q@development

src/backend/executor/nodeModifyTable.c

index 9c36860704aad8c15e4aa2bd989576c0bddff727..5d90337498371a17f539fe09ae18ed4d16b53692 100644 (file)
@@ -2797,18 +2797,29 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
         * Determine if the FDW supports batch insert and determine the batch
         * size (a FDW may support batching, but it may be disabled for the
         * server/table).
+        *
+        * We only do this for INSERT, so that for UPDATE/DELETE the batch
+        * size remains set to 0.
         */
-       if (!resultRelInfo->ri_usesFdwDirectModify &&
-               operation == CMD_INSERT &&
-               resultRelInfo->ri_FdwRoutine != NULL &&
-               resultRelInfo->ri_FdwRoutine->GetForeignModifyBatchSize &&
-               resultRelInfo->ri_FdwRoutine->ExecForeignBatchInsert)
-               resultRelInfo->ri_BatchSize =
-                       resultRelInfo->ri_FdwRoutine->GetForeignModifyBatchSize(resultRelInfo);
-       else
-               resultRelInfo->ri_BatchSize = 1;
+       if (operation == CMD_INSERT)
+       {
+               resultRelInfo = mtstate->resultRelInfo;
+               for (i = 0; i < nplans; i++)
+               {
+                       if (!resultRelInfo->ri_usesFdwDirectModify &&
+                               resultRelInfo->ri_FdwRoutine != NULL &&
+                               resultRelInfo->ri_FdwRoutine->GetForeignModifyBatchSize &&
+                               resultRelInfo->ri_FdwRoutine->ExecForeignBatchInsert)
+                               resultRelInfo->ri_BatchSize =
+                                       resultRelInfo->ri_FdwRoutine->GetForeignModifyBatchSize(resultRelInfo);
+                       else
+                               resultRelInfo->ri_BatchSize = 1;
+
+                       Assert(resultRelInfo->ri_BatchSize >= 1);
 
-       Assert(resultRelInfo->ri_BatchSize >= 1);
+                       resultRelInfo++;
+               }
+       }
 
        /*
         * Lastly, if this is not the primary (canSetTag) ModifyTable node, add it