mirror of
https://github.com/postgres/postgres.git
synced 2025-06-05 23:56:58 +03:00
amcheck: Don't load the right sibling page into BtreeCheckState
5ae2087202 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
This commit is contained in:
parent
532d94fec3
commit
0b5c161248
@ -1892,20 +1892,24 @@ bt_target_page_check(BtreeCheckState *state)
|
|||||||
/* The first key on the next page is the same */
|
/* The first key on the next page is the same */
|
||||||
if (_bt_compare(state->rel, rightkey, state->target, max) == 0 && !rightkey->anynullkeys)
|
if (_bt_compare(state->rel, rightkey, state->target, max) == 0 && !rightkey->anynullkeys)
|
||||||
{
|
{
|
||||||
|
Page rightpage;
|
||||||
|
|
||||||
elog(DEBUG2, "cross page equal keys");
|
elog(DEBUG2, "cross page equal keys");
|
||||||
state->target = palloc_btree_page(state,
|
rightpage = palloc_btree_page(state,
|
||||||
rightblock_number);
|
rightblock_number);
|
||||||
topaque = BTPageGetOpaque(state->target);
|
topaque = BTPageGetOpaque(rightpage);
|
||||||
|
|
||||||
if (P_IGNORE(topaque) || !P_ISLEAF(topaque))
|
if (P_IGNORE(topaque) || !P_ISLEAF(topaque))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
itemid = PageGetItemIdCareful(state, rightblock_number,
|
itemid = PageGetItemIdCareful(state, rightblock_number,
|
||||||
state->target,
|
rightpage,
|
||||||
rightfirstoffset);
|
rightfirstoffset);
|
||||||
itup = (IndexTuple) PageGetItem(state->target, itemid);
|
itup = (IndexTuple) PageGetItem(rightpage, itemid);
|
||||||
|
|
||||||
bt_entry_unique_check(state, itup, rightblock_number, rightfirstoffset, &lVis);
|
bt_entry_unique_check(state, itup, rightblock_number, rightfirstoffset, &lVis);
|
||||||
|
|
||||||
|
pfree(rightpage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user