Fix crash when a page was split during GiST index creation.
authorHeikki Linnakangas <[email protected]>
Fri, 13 Dec 2019 21:58:10 +0000 (23:58 +0200)
committerHeikki Linnakangas <[email protected]>
Fri, 13 Dec 2019 21:58:10 +0000 (23:58 +0200)
The bug was similar to the one that was fixed in commit 22251686f0. When
we split page X and insert the downlink for the new page, the parent page
might also need to be split. When that happens, the downlink offset number
we remembered for X is no longer valid. We correctly called
gistFindCorrectParent() to re-find it, but gistFindCorrectParent() doesn't
do anything if the LSN of the page hasn't changed, and we stopped updating
LSNs during index build in commit 9155580fd5. The buggy codepath was taken
if the page was split into three or more pages, and inserting the downlink
caused the parent page to split. To fix, explicitly mark the downlink
offset number as invalid, to force gistFindCorrectParent() to re-find it.

Fixes bug #16134 reported by Alexander Lakhin, reported again as #16162 by
Andreas Kunert. Thanks to Jeff Janes, Tom Lane and Tomas Vondra for
debugging. Backpatch to v12, where we stopped WAL-logging during index
build.

Discussion: https://www.postgresql.org/message-id/16134-0423f729671dec64%40postgresql.org
Discussion: https://www.postgresql.org/message-id/16162-45d21b7b6c1a3105%40postgresql.org

src/backend/access/gist/gist.c

index 3800f58ce7244fecca99c8910179d86b09d52302..b87facb2fa97e39d88b782aad5e3ae591dc56d65 100644 (file)
@@ -1345,6 +1345,7 @@ gistfinishsplit(GISTInsertState *state, GISTInsertStack *stack,
                         * If the parent page was split, need to relocate the original
                         * parent pointer.
                         */
+                       stack->downlinkoffnum = InvalidOffsetNumber;
                        gistFindCorrectParent(state->r, stack);
                }
                /* gistinserttuples() released the lock on right->buf. */