mirror of
https://github.com/postgres/postgres.git
synced 2025-07-09 22:41:56 +03:00
Harmonize nbtree page split point code.
An nbtree split point can be thought of as a point between two adjoining tuples from an imaginary version of the page being split that includes the incoming/new item (in addition to the items that really are on the page). These adjoining tuples are called the lastleft and firstright tuples. The variables that represent split points contained a field called firstright, which is an offset number of the first data item from the original page that goes on the new right page. The corresponding tuple from origpage was usually the same thing as the actual firstright tuple, but not always: the firstright tuple is sometimes the new/incoming item instead. This situation seems unnecessarily confusing. Make things clearer by renaming the origpage offset returned by _bt_findsplitloc() to "firstrightoff". We now have a firstright tuple and a firstrightoff offset number which are comparable to the newitem/lastleft tuples and the newitemoff/lastleftoff offset numbers respectively. Also make sure that we are consistent about how we describe nbtree page split point state. Push the responsibility for dealing with pg_upgrade'd !heapkeyspace indexes down to lower level code, relieving _bt_split() from dealing with it directly. This means that we always have a palloc'd left page high key on the leaf level, no matter what. This enables simplifying some of the code (and code comments) within _bt_split(). Finally, restructure the page split code to make it clearer why suffix truncation (which only takes place during leaf page splits) is completely different to the first data item truncation that takes place during internal page splits. Tuples are marked as having fewer attributes stored in both cases, and the firstright tuple is truncated in both cases, so it's easy to imagine somebody missing the distinction.
This commit is contained in:
@ -2346,17 +2346,12 @@ _bt_keep_natts(Relation rel, IndexTuple lastleft, IndexTuple firstright,
|
||||
ScanKey scankey;
|
||||
|
||||
/*
|
||||
* Be consistent about the representation of BTREE_VERSION 2/3 tuples
|
||||
* across Postgres versions; don't allow new pivot tuples to have
|
||||
* truncated key attributes there. _bt_compare() treats truncated key
|
||||
* attributes as having the value minus infinity, which would break
|
||||
* searches within !heapkeyspace indexes.
|
||||
* _bt_compare() treats truncated key attributes as having the value minus
|
||||
* infinity, which would break searches within !heapkeyspace indexes. We
|
||||
* must still truncate away non-key attribute values, though.
|
||||
*/
|
||||
if (!itup_key->heapkeyspace)
|
||||
{
|
||||
Assert(nkeyatts != IndexRelationGetNumberOfAttributes(rel));
|
||||
return nkeyatts;
|
||||
}
|
||||
|
||||
scankey = itup_key->scankeys;
|
||||
keepnatts = 1;
|
||||
|
Reference in New Issue
Block a user