diff options
author | Teodor Sigaev <teodor@sigaev.ru> | 2018-04-23 15:55:10 +0300 |
---|---|---|
committer | Teodor Sigaev <teodor@sigaev.ru> | 2018-04-23 15:55:10 +0300 |
commit | 6db4b49986be3fe59a1f6ba6fabf9852864efc3e (patch) | |
tree | 7df7a5e74e34121c679ca92fa87ecf50eda88f78 /src/include/access/nbtree.h | |
parent | 6a7b2ce2bdb9ab5fd23c98ace4bb2d811231706a (diff) | |
download | postgresql-6db4b49986be3fe59a1f6ba6fabf9852864efc3e.tar.gz postgresql-6db4b49986be3fe59a1f6ba6fabf9852864efc3e.zip |
Fix wrong validation of top-parent pointer during page deletion in Btree.
After introducing usage of t_tid of inner or page high key for storing
number of attributes of tuple, validation of tuple's ItemPointer with
ItemPointerIsValid becomes incorrect, it's need to validate only blocknumber of
ItemPointer. Missing this causes a incorrect page deletion, fix that. Test is
added.
BTW, current contrib/amcheck doesn't fail on index corrupted by this way.
Also introduce BTreeTupleGetTopParent/BTreeTupleSetTopParent macroses to improve
code readability and to avoid possible confusion with page high key: high key
is used to store top-parent link for branch to remove.
Bug found by Michael Paquier, but bug doesn't exist in previous versions because
t_tid was set to P_HIKEY.
Author: Teodor Sigaev
Reviewer: Peter Geoghegan
Discussion: https://www.postgresql.org/message-id/flat/20180419052436.GA16000%40paquier.xyz
Diffstat (limited to 'src/include/access/nbtree.h')
-rw-r--r-- | src/include/access/nbtree.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h index 1194be92811..892aeca3003 100644 --- a/src/include/access/nbtree.h +++ b/src/include/access/nbtree.h @@ -227,6 +227,20 @@ typedef struct BTMetaPageData ItemPointerSetBlockNumber(&((itup)->t_tid), (blkno)) /* + * Get/set leaf page highkey's link. During the second phase of deletion, the + * target leaf page's high key may point to an ancestor page (at all other + * times, the leaf level high key's link is not used). See the nbtree README + * for full details. + */ +#define BTreeTupleGetTopParent(itup) \ + ItemPointerGetBlockNumberNoCheck(&((itup)->t_tid)) +#define BTreeTupleSetTopParent(itup, blkno) \ + do { \ + ItemPointerSetBlockNumber(&((itup)->t_tid), (blkno)); \ + BTreeTupleSetNAtts((itup), 0); \ + } while(0) + +/* * Get/set number of attributes within B-tree index tuple. Asserts should be * removed when BT_RESERVED_OFFSET_MASK bits will be used. */ |