aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-04-25 09:42:33 +0900
committerMichael Paquier <michael@paquier.xyz>2023-04-25 09:42:33 +0900
commitaa6177c882d4cd11559d0a10b73e6cd1d8c18fb1 (patch)
treea30441967a278dd2820b3f02bb7b104a290f1ce3 /src/backend/executor
parentc1598d85fe465e650e6af126610c8e33c450f939 (diff)
downloadpostgresql-aa6177c882d4cd11559d0a10b73e6cd1d8c18fb1.tar.gz
postgresql-aa6177c882d4cd11559d0a10b73e6cd1d8c18fb1.zip
Fix buffer refcount leak with FDW bulk inserts
The leak would show up when using batch inserts with foreign tables included in a partition tree, as the slots used in the batch were not reset once processed. In order to fix this problem, some ExecClearTuple() are added to clean up the slots used once a batch is filled and processed, mapping with the number of slots currently in use as tracked by the counter ri_NumSlots. This buffer refcount leak has been introduced in b676ac4 with the addition of the executor facility to improve bulk inserts for FDWs, so backpatch down to 14. Alexander has provided the patch (slightly modified by me). The test for postgres_fdw comes from me, based on the test case that the author has sent in the report. Author: Alexander Pyhalov Discussion: https://postgr.es/m/b035780a740efd38dc30790c76927255@postgrespro.ru Backpatch-through: 14
Diffstat (limited to 'src/backend/executor')
-rw-r--r--src/backend/executor/nodeModifyTable.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 2f6e66b6413..ea6d7012650 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -837,7 +837,6 @@ ExecInsert(ModifyTableContext *context,
resultRelInfo->ri_PlanSlots,
resultRelInfo->ri_NumSlots,
estate, canSetTag);
- resultRelInfo->ri_NumSlots = 0;
flushed = true;
}
@@ -1240,6 +1239,14 @@ ExecBatchInsert(ModifyTableState *mtstate,
if (canSetTag && numInserted > 0)
estate->es_processed += numInserted;
+
+ /* Clean up all the slots, ready for the next batch */
+ for (i = 0; i < numSlots; i++)
+ {
+ ExecClearTuple(slots[i]);
+ ExecClearTuple(planSlots[i]);
+ }
+ resultRelInfo->ri_NumSlots = 0;
}
/*
@@ -1263,7 +1270,6 @@ ExecPendingInserts(EState *estate)
resultRelInfo->ri_PlanSlots,
resultRelInfo->ri_NumSlots,
estate, mtstate->canSetTag);
- resultRelInfo->ri_NumSlots = 0;
}
list_free(estate->es_insert_pending_result_relations);