Skip to content

Commit

Permalink
node/metabase: Interrupt search by primary filter faster
Browse files Browse the repository at this point in the history
Primary filters are applied to sorted meta bucket's elements. This
allows us to speed up execution when we reached mismatch at some point:
 - for EQ/PREFIX/LT/LE/GE matchers, any next item will definitely fail;
 - for GT matcher, any next item will definitely fail if some previous
 element matched.

Now the meta bucket iterator breaks when the mentioned conditions are
reached. This speeds up the processing of most search queries,
especially as the number of objects increases.

Refs #3058.

Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
  • Loading branch information
cthulhu-rider committed Feb 24, 2025
1 parent 38c934a commit cc3b264
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/local_object_storage/metabase/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ func (db *DB) searchTx(tx *bbolt.Tx, cnr cid.ID, fs object.SearchFilters, fInt m
var more bool
var id, dbVal, primDBVal []byte
var keyBuf keyBuffer
var wasPrimMatch bool
attrSkr := &metaAttributeSeeker{keyBuf: &keyBuf, bkt: metaBkt}
curEpoch := db.epochState.CurrentEpoch()
dbValInt := new(big.Int)
Expand Down Expand Up @@ -476,8 +477,12 @@ nextPrimKey:
matches = matchValues(checkedDBVal, mch, fltVal)
}
if !matches {
if mch != object.MatchStringNotEqual && (wasPrimMatch || mch != object.MatchNumGT) {
break nextPrimKey
}
continue nextPrimKey
}
wasPrimMatch = true
// TODO: attribute value can be requested, it can be collected here, or we can
// detect earlier when an object goes beyond the already collected result. The
// code can become even more complex. Same below
Expand Down

0 comments on commit cc3b264

Please sign in to comment.