diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c index e85abcfd72..ed9e703f71 100644 --- a/src/backend/access/nbtree/nbtinsert.c +++ b/src/backend/access/nbtree/nbtinsert.c @@ -167,13 +167,11 @@ top: * but we need to be consistent */ /* - * Check if the page is still the rightmost leaf page, has enough - * free space to accommodate the new tuple, no split is in progress - * and the scankey is greater than or equal to the first key on the - * page. + * Check if the page is still the rightmost valid leaf page, has + * enough free space to accommodate the new tuple and the scankey + * is strictly greater than the first key on the page. */ if (P_ISLEAF(lpageop) && P_RIGHTMOST(lpageop) && - !P_INCOMPLETE_SPLIT(lpageop) && !P_IGNORE(lpageop) && (PageGetFreeSpace(page) > itemsz) && PageGetMaxOffsetNumber(page) >= P_FIRSTDATAKEY(lpageop) && @@ -187,9 +185,9 @@ top: _bt_relbuf(rel, buf); /* - * Something did not workout. Just forget about the cached + * Something did not work out. Just forget about the cached * block and follow the normal path. It might be set again if - * the conditions are favourble. + * the conditions are favourable. */ RelationSetTargetBlock(rel, InvalidBlockNumber); } @@ -970,16 +968,7 @@ _bt_insertonpg(Relation rel, XLogRegisterData((char *) &xlrec, SizeOfBtreeInsert); if (P_ISLEAF(lpageop)) - { xlinfo = XLOG_BTREE_INSERT_LEAF; - - /* - * Cache the block information if we just inserted into the - * rightmost leaf page of the index. - */ - if (P_RIGHTMOST(lpageop)) - RelationSetTargetBlock(rel, BufferGetBlockNumber(buf)); - } else { /* @@ -1032,6 +1021,13 @@ _bt_insertonpg(Relation rel, END_CRIT_SECTION(); + /* + * Cache the block information if we just inserted into the + * rightmost leaf page of the index. + */ + if (P_ISLEAF(lpageop) && P_RIGHTMOST(lpageop)) + RelationSetTargetBlock(rel, BufferGetBlockNumber(buf)); + /* release buffers */ if (BufferIsValid(metabuf)) _bt_relbuf(rel, metabuf);