fix(tsm1): Avoid searching index if key outside index bounds

This improvement avoids performing a binary search on the index by
first checking the key against the lower and upper bounds. Particularly
useful for multiple, fully-compacted TSM files.
pull/9882/merge
Stuart Carnie 2018-05-23 07:48:01 -07:00 committed by Stuart Carnie
parent e209a0a1f2
commit e3d7095d14
1 changed files with 4 additions and 0 deletions

View File

@ -839,6 +839,10 @@ func (d *indirectIndex) searchOffset(key []byte) int {
// search returns the byte position of key in the index. If key is not // search returns the byte position of key in the index. If key is not
// in the index, len(index) is returned. // in the index, len(index) is returned.
func (d *indirectIndex) search(key []byte) int { func (d *indirectIndex) search(key []byte) int {
if !d.ContainsKey(key) {
return len(d.b)
}
// We use a binary search across our indirect offsets (pointers to all the keys // We use a binary search across our indirect offsets (pointers to all the keys
// in the index slice). // in the index slice).
i := bytesutil.SearchBytesFixed(d.offsets, 4, func(x []byte) bool { i := bytesutil.SearchBytesFixed(d.offsets, 4, func(x []byte) bool {