mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
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 <pg@bowt.ie> Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru> Discussion: https://postgr.es/m/CAH2-Wz=sKJcn+OtfVN9rdg+Ps9e4cuQWNP-9t12UE2d8nEG90Q@mail.gmail.com Backpatch-through: 14
This commit is contained in:
@@ -153,6 +153,8 @@ ginDeletePage(GinVacuumState *gvs, BlockNumber deleteBlkno, BlockNumber leftBlkn
|
||||
page = BufferGetPage(dBuffer);
|
||||
rightlink = GinPageGetOpaque(page)->rightlink;
|
||||
|
||||
Assert(GinPageGetOpaque(BufferGetPage(lBuffer))->rightlink == deleteBlkno);
|
||||
|
||||
/*
|
||||
* Any insert which would have gone on the leaf block will now go to its
|
||||
* right sibling.
|
||||
@@ -307,8 +309,21 @@ ginScanToDelete(GinVacuumState *gvs, BlockNumber blkno, bool isRoot,
|
||||
|
||||
if (isempty)
|
||||
{
|
||||
/* we never delete the left- or rightmost branch */
|
||||
if (BufferIsValid(me->leftBuffer) && !GinPageRightMost(page))
|
||||
/*
|
||||
* Proceed to the ginDeletePage() if target page is not the leftmost
|
||||
* or the rightmost page.
|
||||
*
|
||||
* leftBuffer is the target's left sibling according to the parent
|
||||
* level, which is not necessarily its left sibling in the sibling
|
||||
* link chain (the rightlinks stored on pages): the new right half of
|
||||
* an incompletely split page is in the sibling chain, but has no
|
||||
* downlink yet. ginDeletePage isn't prepared to deal with that, so
|
||||
* we must refuse to delete when either the target or its left
|
||||
* sibling page is marked incompletely split.
|
||||
*/
|
||||
if (BufferIsValid(me->leftBuffer) && !GinPageRightMost(page) &&
|
||||
!GinPageIsIncompleteSplit(page) &&
|
||||
!GinPageIsIncompleteSplit(BufferGetPage(me->leftBuffer)))
|
||||
{
|
||||
Assert(!isRoot);
|
||||
ginDeletePage(gvs, blkno, BufferGetBlockNumber(me->leftBuffer),
|
||||
|
||||
Reference in New Issue
Block a user