Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0b5c161

Browse files
committed
amcheck: Don't load the right sibling page into BtreeCheckState
5ae2087 implemented a cross-page unique constraint check by loading the right sibling to the BtreeCheckState.target variable. This is wrong, because bt_target_page_check() shouldn't change the target page. Also, BtreeCheckState.target shouldn't be changed alone without BtreeCheckState.targetblock. However, the above didn't cause any visible bugs for the following reasons. 1. We do a cross-page unique constraint check only for leaf index pages. 2. The only way target page get accessed after a cross-page unique constraint check is loading of the lowkey. 3. The only place lowkey is used is bt_child_highkey_check(), and that applies only to non-leafs. The reasons above don't diminish the fact that changing BtreeCheckState.target for a cross-page unique constraint check is wrong. This commit changes this check to temporarily store the right sibling to the local variable. Reported-by: Peter Geoghegan Discussion: https://postgr.es/m/CAH2-Wzk%2B2116uOXdOViA27SHcr31WKPgmjsxXLBs_aTxAeThzg%40mail.gmail.com Author: Pavel Borisov
1 parent 532d94f commit 0b5c161

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

contrib/amcheck/verify_nbtree.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,20 +1892,24 @@ bt_target_page_check(BtreeCheckState *state)
18921892
/* The first key on the next page is the same */
18931893
if (_bt_compare(state->rel, rightkey, state->target, max) == 0 && !rightkey->anynullkeys)
18941894
{
1895+
Page rightpage;
1896+
18951897
elog(DEBUG2, "cross page equal keys");
1896-
state->target = palloc_btree_page(state,
1897-
rightblock_number);
1898-
topaque = BTPageGetOpaque(state->target);
1898+
rightpage = palloc_btree_page(state,
1899+
rightblock_number);
1900+
topaque = BTPageGetOpaque(rightpage);
18991901

19001902
if (P_IGNORE(topaque) || !P_ISLEAF(topaque))
19011903
break;
19021904

19031905
itemid = PageGetItemIdCareful(state, rightblock_number,
1904-
state->target,
1906+
rightpage,
19051907
rightfirstoffset);
1906-
itup = (IndexTuple) PageGetItem(state->target, itemid);
1908+
itup = (IndexTuple) PageGetItem(rightpage, itemid);
19071909

19081910
bt_entry_unique_check(state, itup, rightblock_number, rightfirstoffset, &lVis);
1911+
1912+
pfree(rightpage);
19091913
}
19101914
}
19111915
}

0 commit comments

Comments
 (0)