Fix buffer refcount leak with FDW bulk inserts
commit806fad7573e2b44de57888e3c04eab8eec4a69a8
authorMichael Paquier <michael@paquier.xyz>
Tue, 25 Apr 2023 00:42:19 +0000 (25 09:42 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 25 Apr 2023 00:42:19 +0000 (25 09:42 +0900)
tree3243aefc32dca743face3b189585d92767c272c1
parent1118cd37eb61e6a2428f457a8b2026a7bb3f801a
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
contrib/postgres_fdw/expected/postgres_fdw.out
contrib/postgres_fdw/sql/postgres_fdw.sql
src/backend/executor/nodeModifyTable.c