Skip to content

Commit 650663b

Browse files
committed
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
1 parent ba95829 commit 650663b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/backend/executor/nodeModifyTable.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,17 +709,19 @@ ExecInsert(ModifyTableState *mtstate,
709709
* keep them across batches. To mitigate an inefficiency in how
710710
* resource owner handles objects with many references (as with
711711
* many slots all referencing the same tuple descriptor) we copy
712-
* the tuple descriptor for each slot.
712+
* the appropriate tuple descriptor for each slot.
713713
*/
714714
if (resultRelInfo->ri_NumSlots >= resultRelInfo->ri_NumSlotsInitialized)
715715
{
716716
TupleDesc tdesc = CreateTupleDescCopy(slot->tts_tupleDescriptor);
717+
TupleDesc plan_tdesc =
718+
CreateTupleDescCopy(planSlot->tts_tupleDescriptor);
717719

718720
resultRelInfo->ri_Slots[resultRelInfo->ri_NumSlots] =
719721
MakeSingleTupleTableSlot(tdesc, slot->tts_ops);
720722

721723
resultRelInfo->ri_PlanSlots[resultRelInfo->ri_NumSlots] =
722-
MakeSingleTupleTableSlot(tdesc, planSlot->tts_ops);
724+
MakeSingleTupleTableSlot(plan_tdesc, planSlot->tts_ops);
723725

724726
/* remember how many batch slots we initialized */
725727
resultRelInfo->ri_NumSlotsInitialized++;

0 commit comments

Comments
 (0)