aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/gist/gist.c
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2021-01-20 11:58:03 +0200
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2021-01-20 11:58:27 +0200
commit0326635dd484fe1d5272dd0c551b78e3f779acb4 (patch)
tree5d6ec9c8a7e1cb7666751a87265fbef5432f2dcf /src/backend/access/gist/gist.c
parent5ad672fc2f6541ec5a0c533fd44d3819bff1447a (diff)
downloadpostgresql-0326635dd484fe1d5272dd0c551b78e3f779acb4.tar.gz
postgresql-0326635dd484fe1d5272dd0c551b78e3f779acb4.zip
Fix bug in detecting concurrent page splits in GiST insert
In commit 9eb5607e699, I got the condition on checking for split or deleted page wrong: I used && instead of ||. The comment correctly said "concurrent split _or_ deletion". As a result, GiST insertion could miss a concurrent split, and insert to wrong page. Duncan Sands demonstrated this with a test script that did a lot of concurrent inserts. Backpatch to v12, where this was introduced. REINDEX is required to fix indexes that were affected by this bug. Backpatch-through: 12 Reported-by: Duncan Sands Discussion: https://www.postgresql.org/message-id/a9690483-6c6c-3c82-c8ba-dc1a40848f11%40deepbluecap.com
Diffstat (limited to 'src/backend/access/gist/gist.c')
-rw-r--r--src/backend/access/gist/gist.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 12d8a68c6c1..9a5a98a61ea 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -242,6 +242,9 @@ gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate,
if (GistFollowRight(page))
elog(ERROR, "concurrent GiST page split was incomplete");
+ /* should never try to insert to a deleted page */
+ Assert(!GistPageIsDeleted(page));
+
*splitinfo = NIL;
/*
@@ -857,7 +860,7 @@ gistdoinsert(Relation r, IndexTuple itup, Size freespace,
*/
}
else if ((GistFollowRight(stack->page) ||
- stack->parent->lsn < GistPageGetNSN(stack->page)) &&
+ stack->parent->lsn < GistPageGetNSN(stack->page)) ||
GistPageIsDeleted(stack->page))
{
/*