Fix GIN posting tree page deletion with incomplete splits.

GIN posting tree page deletion failed to consider whether the target
page's left sibling page, or the deletion target itself, was marked as
incompletely split.  Page deletion finds the target page's left sibling
by walking the parent's downlinks, but an incompletely split page's new
right half is part of the sibling chain despite having no downlink.
Deletion could therefore overwrite the rightlink of the wrong page,
disconnecting the split's still-live right half from the sibling chain.
Scans would then silently miss tuples from that page.

To fix, teach the relevant page deletion path to avoid deleting a
posting tree page whose left sibling is marked incompletely split (and
to avoid doing so when the target page itself is so marked).  This is
essentially the same approach used by nbtree page deletion.

Claude Code found this problem.  The committed test case is a simplified
version of the one that it wrote to demonstrate this bug.

Author: Peter Geoghegan <[email protected]>
Reviewed-by: Andrey Borodin <[email protected]>
Discussion: 
https://postgr.es/m/CAH2-Wz=skjcn+otfvn9rdg+ps9e4cuqwnp-9t12ue2d8neg...@mail.gmail.com
Backpatch-through: 14

Branch
------
master

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

Modified Files
--------------
src/backend/access/gin/ginvacuum.c                 |  18 +++-
src/test/modules/gin/Makefile                      |   2 +-
.../modules/gin/expected/gin_incomplete_splits.out | 109 ++++++++++++++++++++-
src/test/modules/gin/sql/gin_incomplete_splits.sql |  83 +++++++++++++++-
4 files changed, 206 insertions(+), 6 deletions(-)

Reply via email to