From 650663b4cb4714a34d7171981de4392486a85f86 Mon Sep 17 00:00:00 2001 From: Tomas Vondra Date: Thu, 12 Aug 2021 21:32:53 +0200 Subject: [PATCH] Use appropriate tuple descriptor in FDW batching The FDW batching code was using the same tuple descriptor both for all slots (regular and plan slots), but that's incorrect - the subplan may use a different descriptor. Currently this is benign, because batching is used only for INSERTs, and in that case the descriptors always match. But that would change if we allow batching UPDATEs. Fix by copying the appropriate tuple descriptor. Backpatch to 14, where the FDW batching was implemented. Author: Amit Langote Backpatch-through: 14, where FDW batching was added Discussion: https://postgr.es/m/CA%2BHiwqEWd5B0-e-RvixGGUrNvGkjH2s4m95%3DJcwUnyV%3Df0rAKQ%40mail.gmail.com --- src/backend/executor/nodeModifyTable.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index c24684aa6fe..d328856ae5b 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -709,17 +709,19 @@ ExecInsert(ModifyTableState *mtstate, * keep them across batches. To mitigate an inefficiency in how * resource owner handles objects with many references (as with * many slots all referencing the same tuple descriptor) we copy - * the tuple descriptor for each slot. + * the appropriate tuple descriptor for each slot. */ if (resultRelInfo->ri_NumSlots >= resultRelInfo->ri_NumSlotsInitialized) { TupleDesc tdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor); + TupleDesc plan_tdesc = + CreateTupleDescCopy(planSlot->tts_tupleDescriptor); resultRelInfo->ri_Slots[resultRelInfo->ri_NumSlots] = MakeSingleTupleTableSlot(tdesc, slot->tts_ops); resultRelInfo->ri_PlanSlots[resultRelInfo->ri_NumSlots] = - MakeSingleTupleTableSlot(tdesc, planSlot->tts_ops); + MakeSingleTupleTableSlot(plan_tdesc, planSlot->tts_ops); /* remember how many batch slots we initialized */ resultRelInfo->ri_NumSlotsInitialized++;