Skip to content

Commit

Permalink
Use pebble bloom filter
Browse files Browse the repository at this point in the history
  • Loading branch information
marino39 committed Apr 30, 2024
1 parent ea1a806 commit 918020a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
3 changes: 3 additions & 0 deletions keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,5 +343,8 @@ func DefaultKeyComparer() *pebble.Comparer {
}

func _KeyPrefixSplitIndex(rawKey []byte) int {
if len(rawKey) < 6 {
return len(rawKey)
}
return 6 + int(binary.BigEndian.Uint32(rawKey[2:6]))
}
33 changes: 19 additions & 14 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (t *_table[T]) ReIndex(idxs []*Index[T]) error {
counter := 0
indexKeyBuffer := make([]byte, 0, (DefaultKeyBufferSize)*len(idxs))

for iter.SeekGE(prefix); iter.Valid(); iter.Next() {
for iter.SeekPrefixGE(prefix); iter.Valid(); iter.Next() {
var tr T

// deserialize row
Expand Down Expand Up @@ -388,8 +388,9 @@ func (t *_table[T]) Insert(ctx context.Context, trs []T, optBatch ...Batch) erro
// iter
iter := t.db.Iter(&IterOptions{
IterOptions: pebble.IterOptions{
LowerBound: keys[0],
UpperBound: t.dataKeySpaceEnd,
LowerBound: keys[0],
UpperBound: t.dataKeySpaceEnd,
UseL6Filters: true,
},
}, batchReadWrite)
defer iter.Close()
Expand Down Expand Up @@ -507,8 +508,9 @@ func (t *_table[T]) Update(ctx context.Context, trs []T, optBatch ...Batch) erro
// iter
iter := t.db.Iter(&IterOptions{
IterOptions: pebble.IterOptions{
LowerBound: keys[0],
UpperBound: t.dataKeySpaceEnd,
LowerBound: keys[0],
UpperBound: t.dataKeySpaceEnd,
UseL6Filters: true,
},
}, batchReadWrite)
defer iter.Close()
Expand All @@ -526,7 +528,7 @@ func (t *_table[T]) Update(ctx context.Context, trs []T, optBatch ...Batch) erro
continue
}

if !iter.SeekGE(key) || !bytes.Equal(iter.Key(), key) {
if !iter.SeekPrefixGE(key) || !bytes.Equal(iter.Key(), key) {
return fmt.Errorf("record: %x not found", key[_KeyPrefixSplitIndex(key):])
}

Expand Down Expand Up @@ -692,8 +694,9 @@ func (t *_table[T]) Upsert(ctx context.Context, trs []T, onConflict func(old, ne
// iter
iter := t.db.Iter(&IterOptions{
IterOptions: pebble.IterOptions{
LowerBound: keys[0],
UpperBound: t.dataKeySpaceEnd,
LowerBound: keys[0],
UpperBound: t.dataKeySpaceEnd,
UseL6Filters: true,
},
}, batchReadWrite)
defer iter.Close()
Expand Down Expand Up @@ -823,14 +826,15 @@ func (t *_table[T]) exist(key []byte, batch Batch, iter Iterator) bool {
if iter == nil {
iter = t.db.Iter(&IterOptions{
IterOptions: pebble.IterOptions{
LowerBound: key,
UpperBound: t.dataKeySpaceEnd,
LowerBound: key,
UpperBound: t.dataKeySpaceEnd,
UseL6Filters: true,
},
}, batch)
defer iter.Close()
}

return iter.SeekGE(key) && bytes.Equal(iter.Key(), key)
return iter.SeekPrefixGE(key) && bytes.Equal(iter.Key(), key)
}

func (t *_table[T]) GetPoint(ctx context.Context, in T, optBatch ...Batch) (T, error) {
Expand Down Expand Up @@ -948,8 +952,9 @@ func (t *_table[T]) get(keys [][]byte, batch Batch, values [][]byte, errorOnNotE

iter := t.db.Iter(&IterOptions{
IterOptions: pebble.IterOptions{
LowerBound: keys[0],
UpperBound: t.dataKeySpaceEnd,
LowerBound: keys[0],
UpperBound: t.dataKeySpaceEnd,
UseL6Filters: true,
},
}, batch)
defer iter.Close()
Expand All @@ -964,7 +969,7 @@ func (t *_table[T]) get(keys [][]byte, batch Batch, values [][]byte, errorOnNotE
}
}

if !iter.SeekGE(keys[i]) || !bytes.Equal(iter.Key(), keys[i]) {
if !iter.SeekPrefixGE(keys[i]) || !bytes.Equal(iter.Key(), keys[i]) {
if errorOnNotExist {
return nil, ErrNotFound
} else {
Expand Down

0 comments on commit 918020a

Please sign in to comment.