pgsql: Rework ginScanToDelete() to pass Buffers instead of BlockNumbers

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Rework ginScanToDelete() to pass Buffers instead of BlockNumbers
Date: 2026-03-13 12:01:51
Message-ID: E1w11DD-003lFr-0v@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Rework ginScanToDelete() to pass Buffers instead of BlockNumbers.

Previously, ginScanToDelete() and ginDeletePage() passed BlockNumbers and
re-read pages that were already pinned and locked during the tree walk. The
caller ginVacuumPostingTree()) held a cleanup-locked root buffer, yet
ginScanToDelete() re-read it by block number with special-case code to skip
re-locking.

At first, this commit gives both functions more appropriate names,
ginScanPostingTreeToDelete() and ginDeletePostingPage(), indicating they deal
with posting trees/pages. This is more descriptive and similar to the way we
name other GIN functions, for instance, ginVacuumPostingTree() and
ginVacuumPostingTreeLeaves().

Then rework both functions to pass Buffers directly. DataPageDeleteStack now
carries buffer, myoff (downlink offset in parent), and isRoot per level,
so ginScanPostingTreeToDelete() takes only GinVacuumState and
DataPageDeleteStack pointers. Also, ginDeletePostingPage() receives the three
Buffers directly, and no longer reads or releases them itself. The caller
reads and locks child pages before recursing, and manages buffer lifecycle
afterward.

This eliminates the confusing isRoot special cases in buffer management,
including the apparent (but unreachable) double release of the root
buffer identified by Andres Freund.

Add comments explaining the locking protocol and the DataPageDeleteStack
structure.

Reported-by: Andres Freund <andres(at)anarazel(dot)de>
Discussion: https://postgr.es/m/utrlxij43fbguzw4kldte2spc4btoldizutcqyrfakqnbrp3ir@ph3sphpj4asz
Reviewed-by: Pavel Borisov <pashkin(dot)elfe(at)gmail(dot)com>
Reviewed-by: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Reviewed-by: Jinbinge <jinbinge(at)126(dot)com>

Branch
------
master

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

Modified Files
--------------
src/backend/access/gin/README | 8 +-
src/backend/access/gin/ginvacuum.c | 193 ++++++++++++++++++++++---------------
2 files changed, 119 insertions(+), 82 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-03-13 13:14:03 pgsql: Check for interrupts during non-fast-update GIN insertion
Previous Message Heikki Linnakangas 2026-03-13 09:08:00 pgsql: Fix pointer type of ShmemAllocatorData->index