* downlink for the original page as one operation.
*/
LockBuffer(stack->parent->buffer, GIST_EXCLUSIVE);
- gistFindCorrectParent(state->r, stack);
/*
- * insert downlinks for the siblings from right to left, until there are
+ * Insert downlinks for the siblings from right to left, until there are
* only two siblings left.
*/
for (int pos = list_length(splitinfo) - 1; pos > 1; pos--)
right = (GISTPageSplitInfo *) list_nth(splitinfo, pos);
left = (GISTPageSplitInfo *) list_nth(splitinfo, pos - 1);
+ gistFindCorrectParent(state->r, stack);
if (gistinserttuples(state, stack->parent, giststate,
&right->downlink, 1,
InvalidOffsetNumber,
left->buf, right->buf, false, false))
{
/*
- * If the parent page was split, need to relocate the original
- * parent pointer.
+ * If the parent page was split, the existing downlink might
+ * have moved.
*/
stack->downlinkoffnum = InvalidOffsetNumber;
- gistFindCorrectParent(state->r, stack);
}
/* gistinserttuples() released the lock on right->buf. */
}
*/
tuples[0] = left->downlink;
tuples[1] = right->downlink;
- gistinserttuples(state, stack->parent, giststate,
- tuples, 2,
- stack->downlinkoffnum,
- left->buf, right->buf,
- true, /* Unlock parent */
- unlockbuf /* Unlock stack->buffer if caller wants that */
- );
+ gistFindCorrectParent(state->r, stack);
+ if (gistinserttuples(state, stack->parent, giststate,
+ tuples, 2,
+ stack->downlinkoffnum,
+ left->buf, right->buf,
+ true, /* Unlock parent */
+ unlockbuf /* Unlock stack->buffer if caller wants that */
+ ))
+ {
+ /*
+ * If the parent page was split, the downlink might have moved.
+ */
+ stack->downlinkoffnum = InvalidOffsetNumber;
+ }
+
Assert(left->buf == stack->buffer);
/*