Fix initialization of FDW batching in ExecInitModifyTable
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:
@@ -2797,9 +2797,16 @@ 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 (operation == CMD_INSERT)
+ {
+ resultRelInfo = mtstate->resultRelInfo;
+ for (i = 0; i < nplans; i++)
+ {
if (!resultRelInfo->ri_usesFdwDirectModify &&
- operation == CMD_INSERT &&
resultRelInfo->ri_FdwRoutine != NULL &&
resultRelInfo->ri_FdwRoutine->GetForeignModifyBatchSize &&
resultRelInfo->ri_FdwRoutine->ExecForeignBatchInsert)
@@ -2810,6 +2817,10 @@ ExecInitModifyTable(ModifyTable *node, EState *estate, int eflags)
Assert(resultRelInfo->ri_BatchSize >= 1);
+ resultRelInfo++;
+ }
+ }
+
/*
* Lastly, if this is not the primary (canSetTag) ModifyTable node, add it
* to estate->es_auxmodifytables so that it will be run to completion by
