mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
amcheck: Fix posting tree checks in gin_index_check()
Fix two issues in parent_key validation in posting trees: * It's not enough to check stack->parentblk is valid to determine if the parentkey is valid. It's possible parentblk is set to a valid block number, but parentkey is invalid. So check parentkey directly. * We don't need to invalidate parentkey for all child pages of the rightmost page. It's enough to invalidate it for the rightmost child only, which means we can check more cases (less false negatives). Issues reported by Arseniy Mukhin, along with a proposed patch. Review by Andrey M. Borodin, cleanup and improvements by me. Author: Arseniy Mukhin <arseniy.mukhin.dev@gmail.com> Reviewed-by: Andrey M. Borodin <x4mmm@yandex-team.ru> Discussion: https://postgr.es/m/CAE7r3MJ611B9TE=YqBBncewp7-k64VWs+sjk7XF6fJUX77uFBA@mail.gmail.com
This commit is contained in:
@ -345,7 +345,7 @@ gin_check_posting_tree_parent_keys_consistency(Relation rel, BlockNumber posting
|
||||
* Check if this tuple is consistent with the downlink in the
|
||||
* parent.
|
||||
*/
|
||||
if (stack->parentblk != InvalidBlockNumber && i == maxoff &&
|
||||
if (i == maxoff && ItemPointerIsValid(&stack->parentkey) &&
|
||||
ItemPointerCompare(&stack->parentkey, &posting_item->key) < 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INDEX_CORRUPTED),
|
||||
@ -358,14 +358,10 @@ gin_check_posting_tree_parent_keys_consistency(Relation rel, BlockNumber posting
|
||||
ptr->depth = stack->depth + 1;
|
||||
|
||||
/*
|
||||
* Set rightmost parent key to invalid item pointer. Its value
|
||||
* is 'Infinity' and not explicitly stored.
|
||||
* The rightmost parent key is always invalid item pointer.
|
||||
* Its value is 'Infinity' and not explicitly stored.
|
||||
*/
|
||||
if (rightlink == InvalidBlockNumber)
|
||||
ItemPointerSetInvalid(&ptr->parentkey);
|
||||
else
|
||||
ptr->parentkey = posting_item->key;
|
||||
|
||||
ptr->parentkey = posting_item->key;
|
||||
ptr->parentblk = stack->blkno;
|
||||
ptr->blkno = BlockIdGetBlockNumber(&posting_item->child_blkno);
|
||||
ptr->next = stack->next;
|
||||
|
Reference in New Issue
Block a user