]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Don't release index root page pin in ginFindParents().
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 13 Nov 2023 16:44:35 +0000 (11:44 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 13 Nov 2023 16:45:13 +0000 (11:45 -0500)
It's clearly stated in the comments that ginFindParents() must keep
the pin on the index's root page that's associated with the topmost
GinBtreeStack item.  However, the code path for the case that the
desired downlink has been pushed down to the next index level
ignored this proviso, and would release the pin anyway if we were
still examining the root level.  That led to an assertion failure
or "buffer NNNN is not owned by resource owner" error later, when
we try to release the pin again at the end of the insertion.

This is quite hard to reproduce, since it can only happen if an
index root page split occurs concurrently with our own insertion.
Thanks to Jeff Janes for finding a test case that triggers it
often enough to allow investigation.

This has been there since the beginning of GIN, so back-patch
to all supported branches.

Discussion: https://postgr.es/m/CAMkU=1yCAKtv86dMrD__Ja-7KzjE=uMeKX8y__cx5W-OEWy2ow@mail.gmail.com

src/backend/access/gin/ginbtree.c

index fde350eef13bbe5384e255dcb21e58750777c477..f665355782397b200c4bb603920c9f03d18702b0 100644 (file)
@@ -275,7 +275,11 @@ ginFindParents(GinBtree btree, GinBtreeStack *stack)
                        blkno = GinPageGetOpaque(page)->rightlink;
                        if (blkno == InvalidBlockNumber)
                        {
-                               UnlockReleaseBuffer(buffer);
+                               /* Link not present in this level */
+                               LockBuffer(buffer, GIN_UNLOCK);
+                               /* Do not release pin on the root buffer */
+                               if (buffer != root->buffer)
+                                       ReleaseBuffer(buffer);
                                break;
                        }
                        buffer = ginStepRight(buffer, btree->index, GIN_EXCLUSIVE);