Skip to content

Commit 741b884

Browse files
committed
Fix yet another crash in page split during GiST index creation.
Commit a7ee7c8 fixed a bug in GiST page split during index creation, where we failed to re-find the position of a downlink after the page containing it was split. However, that fix was incomplete; the other call to gistinserttuples() in the same function needs to also clear 'downlinkoffnum'. Fixes bug #16134 reported by Alexander Lakhin, for real this time. The previous fix was enough to fix the crash with the reproducer script for bug #16162, but the original script for #16134 was still crashing. Backpatch to v12, like the previous incomplete fix. Discussion: https://www.postgresql.org/message-id/d869f537-abe4-d2ea-0510-38cd053f5152%40gmail.com
1 parent 5024231 commit 741b884

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/backend/access/gist/gist.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,28 +1325,27 @@ gistfinishsplit(GISTInsertState *state, GISTInsertStack *stack,
13251325
* downlink for the original page as one operation.
13261326
*/
13271327
LockBuffer(stack->parent->buffer, GIST_EXCLUSIVE);
1328-
gistFindCorrectParent(state->r, stack);
13291328

13301329
/*
1331-
* insert downlinks for the siblings from right to left, until there are
1330+
* Insert downlinks for the siblings from right to left, until there are
13321331
* only two siblings left.
13331332
*/
13341333
for (int pos = list_length(splitinfo) - 1; pos > 1; pos--)
13351334
{
13361335
right = (GISTPageSplitInfo *) list_nth(splitinfo, pos);
13371336
left = (GISTPageSplitInfo *) list_nth(splitinfo, pos - 1);
13381337

1338+
gistFindCorrectParent(state->r, stack);
13391339
if (gistinserttuples(state, stack->parent, giststate,
13401340
&right->downlink, 1,
13411341
InvalidOffsetNumber,
13421342
left->buf, right->buf, false, false))
13431343
{
13441344
/*
1345-
* If the parent page was split, need to relocate the original
1346-
* parent pointer.
1345+
* If the parent page was split, the existing downlink might
1346+
* have moved.
13471347
*/
13481348
stack->downlinkoffnum = InvalidOffsetNumber;
1349-
gistFindCorrectParent(state->r, stack);
13501349
}
13511350
/* gistinserttuples() released the lock on right->buf. */
13521351
}
@@ -1361,13 +1360,21 @@ gistfinishsplit(GISTInsertState *state, GISTInsertStack *stack,
13611360
*/
13621361
tuples[0] = left->downlink;
13631362
tuples[1] = right->downlink;
1364-
gistinserttuples(state, stack->parent, giststate,
1365-
tuples, 2,
1366-
stack->downlinkoffnum,
1367-
left->buf, right->buf,
1368-
true, /* Unlock parent */
1369-
unlockbuf /* Unlock stack->buffer if caller wants that */
1370-
);
1363+
gistFindCorrectParent(state->r, stack);
1364+
if (gistinserttuples(state, stack->parent, giststate,
1365+
tuples, 2,
1366+
stack->downlinkoffnum,
1367+
left->buf, right->buf,
1368+
true, /* Unlock parent */
1369+
unlockbuf /* Unlock stack->buffer if caller wants that */
1370+
))
1371+
{
1372+
/*
1373+
* If the parent page was split, the downlink might have moved.
1374+
*/
1375+
stack->downlinkoffnum = InvalidOffsetNumber;
1376+
}
1377+
13711378
Assert(left->buf == stack->buffer);
13721379

13731380
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy