Skip to content

Commit f76b975

Browse files
committed
Don't release index root page pin in ginFindParents().
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
1 parent a3e9262 commit f76b975

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/backend/access/gin/ginbtree.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,11 @@ ginFindParents(GinBtree btree, GinBtreeStack *stack)
274274
blkno = GinPageGetOpaque(page)->rightlink;
275275
if (blkno == InvalidBlockNumber)
276276
{
277-
UnlockReleaseBuffer(buffer);
277+
/* Link not present in this level */
278+
LockBuffer(buffer, GIN_UNLOCK);
279+
/* Do not release pin on the root buffer */
280+
if (buffer != root->buffer)
281+
ReleaseBuffer(buffer);
278282
break;
279283
}
280284
buffer = ginStepRight(buffer, btree->index, GIN_EXCLUSIVE);

0 commit comments

Comments
 (0)