Fix GIN multiple-VACUUM-scans pending list bug.

ginbulkdelete performs pending list cleanup before it searches the entry
tree (and any posting trees) for dead TIDs.  This is necessary to avoid
leaving behind dangling TID references that index vacuuming is required
to remove; nothing prevents recently inserted pending list tuples from
containing TIDs that VACUUM already considers dead.

However, ginbulkdelete neglected to perform pending list cleanup on
VACUUM's second or subsequent call.  It was therefore possible for a
VACUUM that requires multiple rounds of index vacuuming to leave behind
dangling references.

To fix, teach ginbulkdelete to perform pending list cleanup during every
call.  In passing, tweak some related comments in the pending list
cleanup path to make it clear why it's safe for VACUUM to not _fully_
empty an index's pending list.

This was arguably an oversight in commit e2c79e14, which fixed a similar
issue where pending list cleanup by VACUUM could end early, but missed
this closely related problem.

Author: Peter Geoghegan <[email protected]>
Reviewed-by: Andrey Borodin <[email protected]>
Discussion: 
https://postgr.es/m/cah2-wzmsa-rpa2ko8a5lagonmbpimj--71xkibqwgjk3fq8...@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/b0a36462bf28ad233f016f4b8ad3ce021ff9b76b

Modified Files
--------------
src/backend/access/gin/ginfast.c   | 15 +++++++++------
src/backend/access/gin/ginvacuum.c | 18 ++++++++++++------
src/include/access/gin_private.h   |  2 +-
3 files changed, 22 insertions(+), 13 deletions(-)

Reply via email to