diff options
author | Peter Geoghegan | 2019-03-20 16:30:57 +0000 |
---|---|---|
committer | Peter Geoghegan | 2019-03-20 16:30:57 +0000 |
commit | e5adcb789d80ba565ccacb1ed4341a7c29085238 (patch) | |
tree | 3393597468587cf5906dea6a4ae41e0a01db9ca5 /src/backend/access/nbtree/README | |
parent | 550b9d26f80fa3048f2d5883f0779ed29465960a (diff) |
Refactor nbtree insertion scankeys.
Use dedicated struct to represent nbtree insertion scan keys. Having a
dedicated struct makes the difference between search type scankeys and
insertion scankeys a lot clearer, and simplifies the signature of
several related functions. This is based on a suggestion by Andrey
Lepikhov.
Streamline how unique index insertions cache binary search progress.
Cache the state of in-progress binary searches within _bt_check_unique()
for later instead of having callers avoid repeating the binary search in
an ad-hoc manner. This makes it easy to add a new optimization:
_bt_check_unique() now falls out of its loop immediately in the common
case where it's already clear that there couldn't possibly be a
duplicate.
The new _bt_check_unique() scheme makes it a lot easier to manage cached
binary search effort afterwards, from within _bt_findinsertloc(). This
is needed for the upcoming patch to make nbtree tuples unique by
treating heap TID as a final tiebreaker column. Unique key binary
searches need to restore lower and upper bounds. They cannot simply
continue to use the >= lower bound as the offset to insert at, because
the heap TID tiebreaker column must be used in comparisons for the
restored binary search (unlike the original _bt_check_unique() binary
search, where scankey's heap TID column must be omitted).
Author: Peter Geoghegan, Heikki Linnakangas
Reviewed-By: Heikki Linnakangas, Andrey Lepikhov
Discussion: https://postgr.es/m/CAH2-WzmE6AhUdk9NdWBf4K3HjWXZBX3+umC7mH7+WDrKcRtsOw@mail.gmail.com
Diffstat (limited to 'src/backend/access/nbtree/README')
-rw-r--r-- | src/backend/access/nbtree/README | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/backend/access/nbtree/README b/src/backend/access/nbtree/README index b0b4ab8b766..a295a7a286d 100644 --- a/src/backend/access/nbtree/README +++ b/src/backend/access/nbtree/README @@ -598,19 +598,22 @@ scankey point to comparison functions that return boolean, such as int4lt. There might be more than one scankey entry for a given index column, or none at all. (We require the keys to appear in index column order, but the order of multiple keys for a given column is unspecified.) An -insertion scankey uses the same array-of-ScanKey data structure, but the -sk_func pointers point to btree comparison support functions (ie, 3-way -comparators that return int4 values interpreted as <0, =0, >0). In an -insertion scankey there is exactly one entry per index column. Insertion -scankeys are built within the btree code (eg, by _bt_mkscankey()) and are -used to locate the starting point of a scan, as well as for locating the -place to insert a new index tuple. (Note: in the case of an insertion -scankey built from a search scankey, there might be fewer keys than -index columns, indicating that we have no constraints for the remaining -index columns.) After we have located the starting point of a scan, the -original search scankey is consulted as each index entry is sequentially -scanned to decide whether to return the entry and whether the scan can -stop (see _bt_checkkeys()). +insertion scankey ("BTScanInsert" data structure) uses a similar +array-of-ScanKey data structure, but the sk_func pointers point to btree +comparison support functions (ie, 3-way comparators that return int4 values +interpreted as <0, =0, >0). In an insertion scankey there is at most one +entry per index column. There is also other data about the rules used to +locate where to begin the scan, such as whether or not the scan is a +"nextkey" scan. Insertion scankeys are built within the btree code (eg, by +_bt_mkscankey()) and are used to locate the starting point of a scan, as +well as for locating the place to insert a new index tuple. (Note: in the +case of an insertion scankey built from a search scankey or built from a +truncated pivot tuple, there might be fewer keys than index columns, +indicating that we have no constraints for the remaining index columns.) +After we have located the starting point of a scan, the original search +scankey is consulted as each index entry is sequentially scanned to decide +whether to return the entry and whether the scan can stop (see +_bt_checkkeys()). We use term "pivot" index tuples to distinguish tuples which don't point to heap tuples, but rather used for tree navigation. Pivot tuples includes |