Skip to content

Commit 6526d07

Browse files
committed
Relax assertion in finding correct GiST parent
Commit 28d3c2d introduced an assertion that if the memorized downlink location in the insertion stack isn't valid, the parent's LSN should've changed too. Turns out that was too strict. In gistFindCorrectParent(), if we walk right, we update the parent's block number and clear its memorized 'downlinkoffnum'. That triggered the assertion on next call to gistFindCorrectParent(), if the parent needed to be split too. Relax the assertion, so that it's OK if downlinkOffnum is InvalidOffsetNumber. Backpatch to v13-, all supported versions. The assertion was added in commit 28d3c2d in v12. Reported-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Discussion: https://www.postgresql.org/message-id/18396-03cac9beb2f7aac3@postgresql.org
1 parent c88b36d commit 6526d07

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/backend/access/gist/gist.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,12 +1043,19 @@ gistFindCorrectParent(Relation r, GISTInsertStack *child, bool is_build)
10431043
/*
10441044
* The page has changed since we looked. During normal operation, every
10451045
* update of a page changes its LSN, so the LSN we memorized should have
1046-
* changed too. During index build, however, we don't WAL-log the changes
1047-
* until we have built the index, so the LSN doesn't change. There is no
1048-
* concurrent activity during index build, but we might have changed the
1049-
* parent ourselves.
1046+
* changed too.
1047+
*
1048+
* During index build, however, we don't WAL-log the changes until we have
1049+
* built the index, so the LSN doesn't change. There is no concurrent
1050+
* activity during index build, but we might have changed the parent
1051+
* ourselves.
1052+
*
1053+
* We will also get here if child->downlinkoffnum is invalid. That happens
1054+
* if 'parent' had been updated by an earlier call to this function on its
1055+
* grandchild, which had to move right.
10501056
*/
1051-
Assert(parent->lsn != PageGetLSN(parent->page) || is_build);
1057+
Assert(parent->lsn != PageGetLSN(parent->page) || is_build ||
1058+
child->downlinkoffnum == InvalidOffsetNumber);
10521059

10531060
/*
10541061
* Scan the page to re-find the downlink. If the page was split, it might

0 commit comments

Comments
 (0)