@@ -236,21 +236,12 @@ typedef struct BTBuildState
236
236
/*
237
237
* Status record for a btree page being built. We have one of these
238
238
* for each active tree level.
239
- *
240
- * The reason we need to store a copy of the minimum key is that we'll
241
- * need to propagate it to the parent node when this page is linked
242
- * into its parent. However, if the page is not a leaf page, the first
243
- * entry on the page doesn't need to contain a key, so we will not have
244
- * stored the key itself on the page. (You might think we could skip
245
- * copying the minimum key on leaf pages, but actually we must have a
246
- * writable copy anyway because we'll poke the page's address into it
247
- * before passing it up to the parent...)
248
239
*/
249
240
typedef struct BTPageState
250
241
{
251
242
Page btps_page ; /* workspace for page building */
252
243
BlockNumber btps_blkno ; /* block # to write this page at */
253
- IndexTuple btps_minkey ; /* copy of minimum key (first item) on page */
244
+ IndexTuple btps_lowkey ; /* page's strict lower bound pivot tuple */
254
245
OffsetNumber btps_lastoff ; /* last item offset loaded */
255
246
uint32 btps_level ; /* tree level (0 = leaf) */
256
247
Size btps_full ; /* "full" if less than this much free space */
@@ -717,7 +708,7 @@ _bt_pagestate(BTWriteState *wstate, uint32 level)
717
708
/* and assign it a page position */
718
709
state -> btps_blkno = wstate -> btws_pages_alloced ++ ;
719
710
720
- state -> btps_minkey = NULL ;
711
+ state -> btps_lowkey = NULL ;
721
712
/* initialize lastoff so first item goes into P_FIRSTKEY */
722
713
state -> btps_lastoff = P_HIKEY ;
723
714
state -> btps_level = level ;
@@ -980,28 +971,27 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
980
971
}
981
972
982
973
/*
983
- * Link the old page into its parent, using its minimum key. If we
984
- * don't have a parent, we have to create one; this adds a new btree
985
- * level.
974
+ * Link the old page into its parent, using its low key. If we don't
975
+ * have a parent, we have to create one; this adds a new btree level.
986
976
*/
987
977
if (state -> btps_next == NULL )
988
978
state -> btps_next = _bt_pagestate (wstate , state -> btps_level + 1 );
989
979
990
- Assert ((BTreeTupleGetNAtts (state -> btps_minkey , wstate -> index ) <=
980
+ Assert ((BTreeTupleGetNAtts (state -> btps_lowkey , wstate -> index ) <=
991
981
IndexRelationGetNumberOfKeyAttributes (wstate -> index ) &&
992
- BTreeTupleGetNAtts (state -> btps_minkey , wstate -> index ) > 0 ) ||
982
+ BTreeTupleGetNAtts (state -> btps_lowkey , wstate -> index ) > 0 ) ||
993
983
P_LEFTMOST ((BTPageOpaque ) PageGetSpecialPointer (opage )));
994
- Assert (BTreeTupleGetNAtts (state -> btps_minkey , wstate -> index ) == 0 ||
984
+ Assert (BTreeTupleGetNAtts (state -> btps_lowkey , wstate -> index ) == 0 ||
995
985
!P_LEFTMOST ((BTPageOpaque ) PageGetSpecialPointer (opage )));
996
- BTreeInnerTupleSetDownLink (state -> btps_minkey , oblkno );
997
- _bt_buildadd (wstate , state -> btps_next , state -> btps_minkey );
998
- pfree (state -> btps_minkey );
986
+ BTreeInnerTupleSetDownLink (state -> btps_lowkey , oblkno );
987
+ _bt_buildadd (wstate , state -> btps_next , state -> btps_lowkey );
988
+ pfree (state -> btps_lowkey );
999
989
1000
990
/*
1001
- * Save a copy of the high key from the old page. It is also used as
1002
- * the minimum key for the new page.
991
+ * Save a copy of the high key from the old page. It is also the low
992
+ * key for the new page.
1003
993
*/
1004
- state -> btps_minkey = CopyIndexTuple (oitup );
994
+ state -> btps_lowkey = CopyIndexTuple (oitup );
1005
995
1006
996
/*
1007
997
* Set the sibling links for both pages.
@@ -1032,18 +1022,17 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
1032
1022
* was created that became the current page. Either way, the current page
1033
1023
* definitely has space for new item.
1034
1024
*
1035
- * If the new item is the first for its page, stash a copy for later. Note
1036
- * this will only happen for the first item on a level; on later pages,
1037
- * the first item for a page is copied from the prior page in the code
1038
- * above. The minimum key for an entire level is nothing more than a
1039
- * minus infinity (downlink only) pivot tuple placeholder.
1025
+ * If the new item is the first for its page, it must also be the first
1026
+ * item on its entire level. On later same-level pages, a low key for a
1027
+ * page will be copied from the prior page in the code above. Generate a
1028
+ * minus infinity low key here instead.
1040
1029
*/
1041
1030
if (last_off == P_HIKEY )
1042
1031
{
1043
- Assert (state -> btps_minkey == NULL );
1044
- state -> btps_minkey = CopyIndexTuple ( itup );
1045
- /* _bt_sortaddtup() will perform full truncation later */
1046
- BTreeTupleSetNAtts (state -> btps_minkey , 0 );
1032
+ Assert (state -> btps_lowkey == NULL );
1033
+ state -> btps_lowkey = palloc0 ( sizeof ( IndexTupleData ) );
1034
+ state -> btps_lowkey -> t_info = sizeof ( IndexTupleData );
1035
+ BTreeTupleSetNAtts (state -> btps_lowkey , 0 );
1047
1036
}
1048
1037
1049
1038
/*
@@ -1083,7 +1072,7 @@ _bt_uppershutdown(BTWriteState *wstate, BTPageState *state)
1083
1072
* We have to link the last page on this level to somewhere.
1084
1073
*
1085
1074
* If we're at the top, it's the root, so attach it to the metapage.
1086
- * Otherwise, add an entry for it to its parent using its minimum key.
1075
+ * Otherwise, add an entry for it to its parent using its low key.
1087
1076
* This may cause the last page of the parent level to split, but
1088
1077
* that's not a problem -- we haven't gotten to it yet.
1089
1078
*/
@@ -1095,16 +1084,16 @@ _bt_uppershutdown(BTWriteState *wstate, BTPageState *state)
1095
1084
}
1096
1085
else
1097
1086
{
1098
- Assert ((BTreeTupleGetNAtts (s -> btps_minkey , wstate -> index ) <=
1087
+ Assert ((BTreeTupleGetNAtts (s -> btps_lowkey , wstate -> index ) <=
1099
1088
IndexRelationGetNumberOfKeyAttributes (wstate -> index ) &&
1100
- BTreeTupleGetNAtts (s -> btps_minkey , wstate -> index ) > 0 ) ||
1089
+ BTreeTupleGetNAtts (s -> btps_lowkey , wstate -> index ) > 0 ) ||
1101
1090
P_LEFTMOST (opaque ));
1102
- Assert (BTreeTupleGetNAtts (s -> btps_minkey , wstate -> index ) == 0 ||
1091
+ Assert (BTreeTupleGetNAtts (s -> btps_lowkey , wstate -> index ) == 0 ||
1103
1092
!P_LEFTMOST (opaque ));
1104
- BTreeInnerTupleSetDownLink (s -> btps_minkey , blkno );
1105
- _bt_buildadd (wstate , s -> btps_next , s -> btps_minkey );
1106
- pfree (s -> btps_minkey );
1107
- s -> btps_minkey = NULL ;
1093
+ BTreeInnerTupleSetDownLink (s -> btps_lowkey , blkno );
1094
+ _bt_buildadd (wstate , s -> btps_next , s -> btps_lowkey );
1095
+ pfree (s -> btps_lowkey );
1096
+ s -> btps_lowkey = NULL ;
1108
1097
}
1109
1098
1110
1099
/*
0 commit comments