You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2023/06/15 01:59:30 UTC

[skywalking-banyandb] 01/02: Change postinglist's value type to uint64

This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch series-index
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit 03e02f31e6f37bb00a387c6e37a76e7cdcfa8c00
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Wed Jun 14 11:02:07 2023 +0000

    Change postinglist's value type to uint64
    
    Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
 banyand/tsdb/block.go                |   6 +-
 banyand/tsdb/series_seek_filter.go   |   2 +-
 banyand/tsdb/series_seek_sort.go     |   2 +-
 pkg/index/index.go                   |  17 +++--
 pkg/index/inverted/inverted.go       |  60 +++++++++------
 pkg/index/inverted/inverted_test.go  | 142 ++++++++++++++++++++++++-----------
 pkg/index/lsm/lsm.go                 |   7 +-
 pkg/index/lsm/search.go              |   5 +-
 pkg/index/posting/posting.go         |  18 ++---
 pkg/index/posting/roaring/roaring.go |  33 ++++----
 pkg/index/testcases/duration.go      |   5 +-
 pkg/index/testcases/service_name.go  |   5 +-
 pkg/query/logical/index_filter.go    |  12 +--
 13 files changed, 193 insertions(+), 121 deletions(-)

diff --git a/banyand/tsdb/block.go b/banyand/tsdb/block.go
index 70f97726..4a10ceab 100644
--- a/banyand/tsdb/block.go
+++ b/banyand/tsdb/block.go
@@ -406,7 +406,7 @@ func (d *bDelegate) write(key []byte, val []byte, ts time.Time) error {
 }
 
 func (d *bDelegate) writePrimaryIndex(field index.Field, id common.ItemID) error {
-	if err := d.delegate.lsmIndex.Write([]index.Field{field}, id); err != nil {
+	if err := d.delegate.lsmIndex.Write([]index.Field{field}, uint64(id)); err != nil {
 		receivedNumCounter.Inc(1, append(d.delegate.position.ShardLabelValues(), "primary", "true")...)
 		return err
 	}
@@ -421,7 +421,7 @@ func (d *bDelegate) writeLSMIndex(fields []index.Field, id common.ItemID) error
 		total += len(f.Marshal())
 	}
 
-	if err := d.delegate.lsmIndex.Write(fields, id); err != nil {
+	if err := d.delegate.lsmIndex.Write(fields, uint64(id)); err != nil {
 		receivedNumCounter.Inc(1, append(d.delegate.position.ShardLabelValues(), "local_lsm", "true")...)
 		return err
 	}
@@ -436,7 +436,7 @@ func (d *bDelegate) writeInvertedIndex(fields []index.Field, id common.ItemID) e
 		total += len(f.Marshal())
 	}
 
-	if err := d.delegate.invertedIndex.Write(fields, id); err != nil {
+	if err := d.delegate.invertedIndex.Write(fields, uint64(id)); err != nil {
 		receivedNumCounter.Inc(1, append(d.delegate.position.ShardLabelValues(), "local_inverted", "true")...)
 		return err
 	}
diff --git a/banyand/tsdb/series_seek_filter.go b/banyand/tsdb/series_seek_filter.go
index 64d7ed10..60b323e7 100644
--- a/banyand/tsdb/series_seek_filter.go
+++ b/banyand/tsdb/series_seek_filter.go
@@ -49,7 +49,7 @@ func (s *seekerBuilder) buildIndexFilter(block blockDelegate) (filterFn, error)
 		return nil, err
 	}
 	return func(item Item) bool {
-		valid := allItemIDs.Contains(item.ID())
+		valid := allItemIDs.Contains(uint64(item.ID()))
 		s.seriesSpan.l.Trace().Int("valid_item_num", allItemIDs.Len()).Bool("valid", valid).Msg("filter item by index")
 		return valid
 	}, nil
diff --git a/banyand/tsdb/series_seek_sort.go b/banyand/tsdb/series_seek_sort.go
index f41e750f..63f85ddc 100644
--- a/banyand/tsdb/series_seek_sort.go
+++ b/banyand/tsdb/series_seek_sort.go
@@ -200,7 +200,7 @@ func (s *searcherIterator) Next() bool {
 func (s *searcherIterator) Val() Item {
 	return &item{
 		sortedField: s.curKey,
-		itemID:      s.cur.Current(),
+		itemID:      common.ItemID(s.cur.Current()),
 		data:        s.data,
 		seriesID:    s.seriesID,
 	}
diff --git a/pkg/index/index.go b/pkg/index/index.go
index 024811ab..3314fd8f 100644
--- a/pkg/index/index.go
+++ b/pkg/index/index.go
@@ -48,14 +48,21 @@ func (f FieldKey) MarshalIndexRule() string {
 
 // Marshal encodes f to bytes.
 func (f FieldKey) Marshal() []byte {
-	s := f.SeriesID.Marshal()
+	var s []byte
+	if f.HasSeriesID() {
+		s = f.SeriesID.Marshal()
+	}
 	i := []byte(f.MarshalIndexRule())
 	b := make([]byte, len(s)+len(i))
-	bp := copy(b, s)
-	copy(b[bp:], i)
+	copy(b, s)
+	copy(b[len(s):], i)
 	return b
 }
 
+func (f FieldKey) HasSeriesID() bool {
+	return f.SeriesID > 0
+}
+
 // MarshalToStr encodes f to string.
 func (f FieldKey) MarshalToStr() string {
 	return string(f.Marshal())
@@ -183,9 +190,9 @@ type PostingValue struct {
 	Term  []byte
 }
 
-// Writer allows writing fields and itemID in a document to a index.
+// Writer allows writing fields and docID in a document to a index.
 type Writer interface {
-	Write(fields []Field, itemID common.ItemID) error
+	Write(fields []Field, docID uint64) error
 }
 
 // FieldIterable allows building a FieldIterator.
diff --git a/pkg/index/inverted/inverted.go b/pkg/index/inverted/inverted.go
index 05aa471c..308132e1 100644
--- a/pkg/index/inverted/inverted.go
+++ b/pkg/index/inverted/inverted.go
@@ -35,7 +35,6 @@ import (
 	"github.com/dgraph-io/badger/v3/y"
 	"go.uber.org/multierr"
 
-	"github.com/apache/skywalking-banyandb/api/common"
 	databasev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1"
 	modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
 	"github.com/apache/skywalking-banyandb/pkg/convert"
@@ -47,7 +46,7 @@ import (
 )
 
 const (
-	docID         = "_id"
+	docIDField    = "_id"
 	batchSize     = 1024
 	seriesIDField = "series_id"
 	idField       = "id"
@@ -79,7 +78,7 @@ type StoreOpts struct {
 
 type doc struct {
 	fields []index.Field
-	itemID common.ItemID
+	docID  uint64
 }
 
 type flushEvent struct {
@@ -128,7 +127,7 @@ func (s *store) Close() error {
 	return s.writer.Close()
 }
 
-func (s *store) Write(fields []index.Field, itemID common.ItemID) error {
+func (s *store) Write(fields []index.Field, docID uint64) error {
 	if len(fields) < 1 {
 		return nil
 	}
@@ -140,7 +139,7 @@ func (s *store) Write(fields []index.Field, itemID common.ItemID) error {
 	case <-s.closer.CloseNotify():
 	case s.ch <- doc{
 		fields: fields,
-		itemID: itemID,
+		docID:  docID,
 	}:
 	}
 	return nil
@@ -175,15 +174,18 @@ func (s *store) Iterator(fieldKey index.FieldKey, termRange index.RangeOpts, ord
 			SetField(fk)
 	} else {
 		shouldDecodeTerm = false
-		query = bluge.NewBooleanQuery().
+		bQuery := bluge.NewBooleanQuery().
 			AddMust(bluge.NewTermRangeInclusiveQuery(
 				string(termRange.Lower),
 				string(termRange.Upper),
 				termRange.IncludesLower,
 				termRange.IncludesUpper,
 			).
-				SetField(fk)).
-			AddMust(bluge.NewTermQuery(string(fieldKey.SeriesID.Marshal())).SetField(seriesIDField))
+				SetField(fk))
+		if fieldKey.HasSeriesID() {
+			bQuery.AddMust(bluge.NewTermQuery(string(fieldKey.SeriesID.Marshal())).SetField(seriesIDField))
+		}
+		query = bQuery
 	}
 
 	sortedKey := fk
@@ -214,9 +216,12 @@ func (s *store) MatchTerms(field index.Field) (list posting.List, err error) {
 		query = bluge.NewTermQuery(string(field.Marshal())).SetField(fk)
 	} else {
 		shouldDecodeTerm = false
-		query = bluge.NewBooleanQuery().
-			AddMust(bluge.NewTermQuery(string(field.Term)).SetField(fk)).
-			AddMust(bluge.NewTermQuery(string(field.Key.SeriesID.Marshal())).SetField(seriesIDField))
+		bQuery := bluge.NewBooleanQuery().
+			AddMust(bluge.NewTermQuery(string(field.Term)).SetField(fk))
+		if field.Key.HasSeriesID() {
+			bQuery.AddMust(bluge.NewTermQuery(string(field.Key.SeriesID.Marshal())).SetField(seriesIDField))
+		}
+		query = bQuery
 	}
 	documentMatchIterator, err := reader.Search(context.Background(), bluge.NewAllMatches(query))
 	if err != nil {
@@ -244,7 +249,9 @@ func (s *store) Match(fieldKey index.FieldKey, matches []string) (posting.List,
 	analyzer := analyzers[fieldKey.Analyzer]
 	fk := fieldKey.MarshalIndexRule()
 	query := bluge.NewBooleanQuery()
-	query.AddMust(bluge.NewTermQuery(string(fieldKey.SeriesID.Marshal())).SetField(seriesIDField))
+	if fieldKey.HasSeriesID() {
+		query.AddMust(bluge.NewTermQuery(string(fieldKey.SeriesID.Marshal())).SetField(seriesIDField))
+	}
 	for _, m := range matches {
 		query.AddMust(bluge.NewMatchQuery(m).SetField(fk).
 			SetAnalyzer(analyzer))
@@ -315,8 +322,10 @@ func (s *store) run() {
 					// TODO: generate a segment directly.
 					fk := d.fields[0].Key
 					docIDBuffer.Reset()
-					docIDBuffer.Write(fk.SeriesID.Marshal())
-					docIDBuffer.Write(convert.Uint64ToBytes(uint64(d.itemID)))
+					if fk.HasSeriesID() {
+						docIDBuffer.Write(fk.SeriesID.Marshal())
+					}
+					docIDBuffer.Write(convert.Uint64ToBytes(uint64(d.docID)))
 					doc := bluge.NewDocument(docIDBuffer.String())
 					toAddSeriesIDField := false
 					for _, f := range d.fields {
@@ -328,7 +337,7 @@ func (s *store) run() {
 								WithAnalyzer(analyzers[f.Key.Analyzer]))
 						}
 					}
-					if toAddSeriesIDField {
+					if toAddSeriesIDField && fk.HasSeriesID() {
 						doc.AddField(bluge.NewKeywordFieldBytes(seriesIDField, fk.SeriesID.Marshal()))
 					}
 					size++
@@ -407,13 +416,18 @@ func (bmi *blugeMatchIterator) nextTerm() bool {
 		return false
 	}
 	i := 0
-	var itemID common.ItemID
+	var docID uint64
 	var term []byte
 	bmi.err = match.VisitStoredFields(func(field string, value []byte) bool {
-		if field == docID {
-			// value = seriesID(8bytes)+itemID(8bytes)
-			id := convert.BytesToUint64(value[8:])
-			itemID = common.ItemID(id)
+		if field == docIDField {
+			var id uint64
+			if len(value) == 8 {
+				id = convert.BytesToUint64(value)
+			} else if len(value) == 16 {
+				// value = seriesID(8bytes)+docID(8bytes)
+				id = convert.BytesToUint64(value[8:])
+			}
+			docID = uint64(id)
 			i++
 		}
 		if field == bmi.fieldKey {
@@ -438,18 +452,18 @@ func (bmi *blugeMatchIterator) nextTerm() bool {
 	if bmi.agg == nil {
 		bmi.agg = &index.PostingValue{
 			Term:  term,
-			Value: roaring.NewPostingListWithInitialData(uint64(itemID)),
+			Value: roaring.NewPostingListWithInitialData(uint64(docID)),
 		}
 		return true
 	}
 	if bytes.Equal(bmi.agg.Term, term) {
-		bmi.agg.Value.Insert(itemID)
+		bmi.agg.Value.Insert(uint64(docID))
 		return true
 	}
 	bmi.current = bmi.agg
 	bmi.agg = &index.PostingValue{
 		Term:  term,
-		Value: roaring.NewPostingListWithInitialData(uint64(itemID)),
+		Value: roaring.NewPostingListWithInitialData(uint64(docID)),
 	}
 	return false
 }
diff --git a/pkg/index/inverted/inverted_test.go b/pkg/index/inverted/inverted_test.go
index a1109f92..b8d458f1 100644
--- a/pkg/index/inverted/inverted_test.go
+++ b/pkg/index/inverted/inverted_test.go
@@ -35,21 +35,6 @@ import (
 	"github.com/apache/skywalking-banyandb/pkg/test/flags"
 )
 
-var (
-	serviceName = index.FieldKey{
-		// http_method
-		IndexRuleID: 6,
-		SeriesID:    common.SeriesID(0),
-		Analyzer:    databasev1.IndexRule_ANALYZER_SIMPLE,
-	}
-	serviceName1 = index.FieldKey{
-		// http_method
-		IndexRuleID: 6,
-		SeriesID:    common.SeriesID(1),
-		Analyzer:    databasev1.IndexRule_ANALYZER_SIMPLE,
-	}
-)
-
 func TestStore_Match(t *testing.T) {
 	tester := assert.New(t)
 	path, fn := setUp(require.New(t))
@@ -57,37 +42,23 @@ func TestStore_Match(t *testing.T) {
 		Path:   path,
 		Logger: logger.GetLogger("test"),
 	})
+	tester.NoError(err)
 	defer func() {
 		tester.NoError(s.Close())
 		fn()
 	}()
-	tester.NoError(err)
-	tester.NoError(s.Write([]index.Field{{
-		Key:  serviceName,
-		Term: []byte("GET::/product/order"),
-	}}, common.ItemID(1)))
-	tester.NoError(s.Write([]index.Field{{
-		Key:  serviceName,
-		Term: []byte("GET::/root/product"),
-	}}, common.ItemID(2)))
-	tester.NoError(s.Write([]index.Field{{
-		Key:  serviceName,
-		Term: []byte("org.apache.skywalking.examples.OrderService.order"),
-	}}, common.ItemID(3)))
-	s.(*store).flush()
-	tester.NoError(s.Write([]index.Field{{
-		Key:  serviceName1,
-		Term: []byte("test.1"),
-	}}, common.ItemID(1)))
-	tester.NoError(s.Write([]index.Field{{
-		Key:  serviceName1,
-		Term: []byte("test.2"),
-	}}, common.ItemID(2)))
-	tester.NoError(s.Write([]index.Field{{
-		Key:  serviceName1,
-		Term: []byte("test.3"),
-	}}, common.ItemID(3)))
-	s.(*store).flush()
+	serviceName := index.FieldKey{
+		// http_method
+		IndexRuleID: 6,
+		SeriesID:    common.SeriesID(11),
+		Analyzer:    databasev1.IndexRule_ANALYZER_SIMPLE,
+	}
+	setup(tester, s, serviceName, index.FieldKey{
+		// http_method
+		IndexRuleID: 6,
+		SeriesID:    common.SeriesID(1),
+		Analyzer:    databasev1.IndexRule_ANALYZER_SIMPLE,
+	})
 
 	tests := []struct {
 		want    posting.List
@@ -146,6 +117,63 @@ func TestStore_Match(t *testing.T) {
 			matches: []string{"OrderService", "order"},
 			want:    roaring.NewPostingListWithInitialData(3),
 		},
+		{
+			matches: []string{"test"},
+			want:    roaring.NewPostingListWithInitialData(),
+		},
+	}
+	for _, tt := range tests {
+		name := strings.Join(tt.matches, " and ")
+		t.Run(name, func(t *testing.T) {
+			list, err := s.Match(serviceName, tt.matches)
+			if tt.wantErr {
+				tester.Error(err)
+				return
+			}
+			tester.NoError(err, name)
+			tester.NotNil(list, name)
+			tester.Equal(tt.want, list, name)
+		})
+	}
+}
+
+func TestStore_SeriesMatch(t *testing.T) {
+	tester := assert.New(t)
+	path, fn := setUp(require.New(t))
+	s, err := NewStore(StoreOpts{
+		Path:   path,
+		Logger: logger.GetLogger("test"),
+	})
+	tester.NoError(err)
+	defer func() {
+		tester.NoError(s.Close())
+		fn()
+	}()
+	serviceName := index.FieldKey{
+		// http_method
+		IndexRuleID: 6,
+		Analyzer:    databasev1.IndexRule_ANALYZER_SIMPLE,
+	}
+	setup(tester, s, serviceName, serviceName)
+
+	tests := []struct {
+		want    posting.List
+		matches []string
+		wantErr bool
+	}{
+
+		{
+			matches: []string{"test"},
+			want:    roaring.NewPostingListWithInitialData(1, 2, 3),
+		},
+		{
+			matches: []string{"a"},
+			want:    roaring.NewPostingListWithInitialData(1),
+		},
+		{
+			matches: []string{"root"},
+			want:    roaring.NewPostingListWithInitialData(),
+		},
 	}
 	for _, tt := range tests {
 		name := strings.Join(tt.matches, " and ")
@@ -162,6 +190,36 @@ func TestStore_Match(t *testing.T) {
 	}
 }
 
+func setup(tester *assert.Assertions, s index.Store, serviceName, serviceName1 index.FieldKey) index.Store {
+	tester.NoError(s.Write([]index.Field{{
+		Key:  serviceName,
+		Term: []byte("GET::/product/order"),
+	}}, 1))
+	tester.NoError(s.Write([]index.Field{{
+		Key:  serviceName,
+		Term: []byte("GET::/root/product"),
+	}}, 2))
+	tester.NoError(s.Write([]index.Field{{
+		Key:  serviceName,
+		Term: []byte("org.apache.skywalking.examples.OrderService.order"),
+	}}, 3))
+	s.(*store).flush()
+	tester.NoError(s.Write([]index.Field{{
+		Key:  serviceName1,
+		Term: []byte("test.a"),
+	}}, 1))
+	tester.NoError(s.Write([]index.Field{{
+		Key:  serviceName1,
+		Term: []byte("test.b"),
+	}}, 2))
+	tester.NoError(s.Write([]index.Field{{
+		Key:  serviceName1,
+		Term: []byte("test.c"),
+	}}, 3))
+	s.(*store).flush()
+	return s
+}
+
 func TestStore_MatchTerm(t *testing.T) {
 	tester := assert.New(t)
 	path, fn := setUp(require.New(t))
diff --git a/pkg/index/lsm/lsm.go b/pkg/index/lsm/lsm.go
index df0e4644..1db33826 100644
--- a/pkg/index/lsm/lsm.go
+++ b/pkg/index/lsm/lsm.go
@@ -23,7 +23,6 @@ import (
 
 	"go.uber.org/multierr"
 
-	"github.com/apache/skywalking-banyandb/api/common"
 	"github.com/apache/skywalking-banyandb/banyand/kv"
 	"github.com/apache/skywalking-banyandb/pkg/convert"
 	"github.com/apache/skywalking-banyandb/pkg/index"
@@ -49,10 +48,10 @@ func (s *store) Close() (err error) {
 	return err
 }
 
-func (s *store) Write(fields []index.Field, itemID common.ItemID) (err error) {
+func (s *store) Write(fields []index.Field, docID uint64) (err error) {
 	for _, field := range fields {
-		itemIDInt := uint64(itemID)
-		err = multierr.Append(err, s.lsm.PutWithVersion(field.Marshal(), convert.Uint64ToBytes(itemIDInt), itemIDInt))
+		docIDInt := uint64(docID)
+		err = multierr.Append(err, s.lsm.PutWithVersion(field.Marshal(), convert.Uint64ToBytes(docIDInt), docIDInt))
 	}
 	return err
 }
diff --git a/pkg/index/lsm/search.go b/pkg/index/lsm/search.go
index 58dca066..daa21677 100644
--- a/pkg/index/lsm/search.go
+++ b/pkg/index/lsm/search.go
@@ -23,7 +23,6 @@ import (
 	"github.com/pkg/errors"
 	"go.uber.org/multierr"
 
-	"github.com/apache/skywalking-banyandb/api/common"
 	modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
 	"github.com/apache/skywalking-banyandb/banyand/kv"
 	"github.com/apache/skywalking-banyandb/pkg/convert"
@@ -41,7 +40,7 @@ func (s *store) MatchField(fieldKey index.FieldKey) (list posting.List, err erro
 func (s *store) MatchTerms(field index.Field) (list posting.List, err error) {
 	list = roaring.NewPostingList()
 	err = s.lsm.GetAll(field.Marshal(), func(itemID []byte) error {
-		list.Insert(common.ItemID(convert.BytesToUint64(itemID)))
+		list.Insert(convert.BytesToUint64(itemID))
 		return nil
 	})
 	if errors.Is(err, kv.ErrKeyNotFound) {
@@ -90,7 +89,7 @@ func (s *store) Iterator(fieldKey index.FieldKey, termRange index.RangeOpts, ord
 						Uint64("item_id", itemID).
 						Msg("fetched item from the index")
 				}
-				pv.Value.Insert(common.ItemID(itemID))
+				pv.Value.Insert(itemID)
 			}
 			return pv, nil
 		}), nil
diff --git a/pkg/index/posting/posting.go b/pkg/index/posting/posting.go
index 3807223c..5f115030 100644
--- a/pkg/index/posting/posting.go
+++ b/pkg/index/posting/posting.go
@@ -20,20 +20,18 @@ package posting
 
 import (
 	"github.com/pkg/errors"
-
-	"github.com/apache/skywalking-banyandb/api/common"
 )
 
 // ErrListEmpty indicates the postings list is empty.
 var ErrListEmpty = errors.New("postings list is empty")
 
-// List is a collection of common.ItemID.
+// List is a collection of uint64.
 type List interface {
-	Contains(id common.ItemID) bool
+	Contains(id uint64) bool
 
 	IsEmpty() bool
 
-	Max() (common.ItemID, error)
+	Max() (uint64, error)
 
 	Len() int
 
@@ -43,7 +41,7 @@ type List interface {
 
 	Equal(other List) bool
 
-	Insert(i common.ItemID)
+	Insert(i uint64)
 
 	Intersect(other List) error
 
@@ -55,13 +53,13 @@ type List interface {
 
 	AddIterator(iter Iterator) error
 
-	AddRange(min, max common.ItemID) error
+	AddRange(min, max uint64) error
 
-	RemoveRange(min, max common.ItemID) error
+	RemoveRange(min, max uint64) error
 
 	Reset()
 
-	ToSlice() []common.ItemID
+	ToSlice() []uint64
 
 	Marshall() ([]byte, error)
 
@@ -74,7 +72,7 @@ type List interface {
 type Iterator interface {
 	Next() bool
 
-	Current() common.ItemID
+	Current() uint64
 
 	Close() error
 }
diff --git a/pkg/index/posting/roaring/roaring.go b/pkg/index/posting/roaring/roaring.go
index 3d31eb7d..5143f273 100644
--- a/pkg/index/posting/roaring/roaring.go
+++ b/pkg/index/posting/roaring/roaring.go
@@ -22,7 +22,6 @@ import (
 	"github.com/RoaringBitmap/roaring/roaring64"
 	"github.com/pkg/errors"
 
-	"github.com/apache/skywalking-banyandb/api/common"
 	"github.com/apache/skywalking-banyandb/pkg/index/posting"
 )
 
@@ -61,7 +60,7 @@ func NewPostingList() posting.List {
 func NewPostingListWithInitialData(data ...uint64) posting.List {
 	list := NewPostingList()
 	for _, d := range data {
-		list.Insert(common.ItemID(d))
+		list.Insert(d)
 	}
 	return list
 }
@@ -75,19 +74,19 @@ func NewRange(start, end uint64) posting.List {
 	return list
 }
 
-func (p *postingsList) Contains(id common.ItemID) bool {
-	return p.bitmap.Contains(uint64(id))
+func (p *postingsList) Contains(id uint64) bool {
+	return p.bitmap.Contains(id)
 }
 
 func (p *postingsList) IsEmpty() bool {
 	return p.bitmap.IsEmpty()
 }
 
-func (p *postingsList) Max() (common.ItemID, error) {
+func (p *postingsList) Max() (uint64, error) {
 	if p.IsEmpty() {
 		return 0, posting.ErrListEmpty
 	}
-	return common.ItemID(p.bitmap.Maximum()), nil
+	return p.bitmap.Maximum(), nil
 }
 
 func (p *postingsList) Len() int {
@@ -126,8 +125,8 @@ func (p *postingsList) Equal(other posting.List) bool {
 	return true
 }
 
-func (p *postingsList) Insert(id common.ItemID) {
-	p.bitmap.Add(uint64(id))
+func (p *postingsList) Insert(id uint64) {
+	p.bitmap.Add(id)
 }
 
 func (p *postingsList) Intersect(other posting.List) error {
@@ -174,16 +173,16 @@ func (p *postingsList) AddIterator(iter posting.Iterator) error {
 	return nil
 }
 
-func (p *postingsList) AddRange(min, max common.ItemID) error {
+func (p *postingsList) AddRange(min, max uint64) error {
 	for i := min; i < max; i++ {
-		p.bitmap.Add(uint64(i))
+		p.bitmap.Add(i)
 	}
 	return nil
 }
 
-func (p *postingsList) RemoveRange(min, max common.ItemID) error {
+func (p *postingsList) RemoveRange(min, max uint64) error {
 	for i := min; i < max; i++ {
-		p.bitmap.Remove(uint64(i))
+		p.bitmap.Remove(i)
 	}
 	return nil
 }
@@ -198,11 +197,11 @@ func (p *postingsList) SizeInBytes() int64 {
 
 type roaringIterator struct {
 	iter    roaring64.IntIterable64
-	current common.ItemID
+	current uint64
 	closed  bool
 }
 
-func (it *roaringIterator) Current() common.ItemID {
+func (it *roaringIterator) Current() uint64 {
 	return it.current
 }
 
@@ -211,7 +210,7 @@ func (it *roaringIterator) Next() bool {
 		return false
 	}
 	v := it.iter.Next()
-	it.current = common.ItemID(v)
+	it.current = v
 	return true
 }
 
@@ -220,10 +219,10 @@ func (it *roaringIterator) Close() error {
 	return nil
 }
 
-func (p *postingsList) ToSlice() []common.ItemID {
+func (p *postingsList) ToSlice() []uint64 {
 	iter := p.Iterator()
 	defer iter.Close()
-	s := make([]common.ItemID, 0, p.Len())
+	s := make([]uint64, 0, p.Len())
 	for iter.Next() {
 		s = append(s, iter.Current())
 	}
diff --git a/pkg/index/testcases/duration.go b/pkg/index/testcases/duration.go
index a7221a18..16d728a8 100644
--- a/pkg/index/testcases/duration.go
+++ b/pkg/index/testcases/duration.go
@@ -25,7 +25,6 @@ import (
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/require"
 
-	"github.com/apache/skywalking-banyandb/api/common"
 	modelv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
 	"github.com/apache/skywalking-banyandb/pkg/convert"
 	"github.com/apache/skywalking-banyandb/pkg/index"
@@ -331,7 +330,7 @@ func setUpPartialDuration(t *assert.Assertions, store index.Writer, r map[int]po
 	}
 	sort.Ints(idx)
 	for i := 100; i < 200; i++ {
-		id := common.ItemID(i)
+		id := uint64(i)
 		for i2, term := range idx {
 			if i%len(idx) != i2 || r[term] == nil {
 				continue
@@ -340,7 +339,7 @@ func setUpPartialDuration(t *assert.Assertions, store index.Writer, r map[int]po
 				Key:  duration,
 				Term: convert.Int64ToBytes(int64(term)),
 			}}, id))
-			r[term].Insert(id)
+			r[term].Insert(uint64(id))
 		}
 	}
 	return r
diff --git a/pkg/index/testcases/service_name.go b/pkg/index/testcases/service_name.go
index a77020f3..9268a4e5 100644
--- a/pkg/index/testcases/service_name.go
+++ b/pkg/index/testcases/service_name.go
@@ -22,7 +22,6 @@ import (
 
 	"github.com/stretchr/testify/assert"
 
-	"github.com/apache/skywalking-banyandb/api/common"
 	"github.com/apache/skywalking-banyandb/pkg/index"
 	"github.com/apache/skywalking-banyandb/pkg/index/posting"
 	"github.com/apache/skywalking-banyandb/pkg/index/posting/roaring"
@@ -92,12 +91,12 @@ func SetUp(t *assert.Assertions, store SimpleStore) {
 			t.NoError(store.Write([]index.Field{{
 				Key:  serviceName,
 				Term: []byte("gateway"),
-			}}, common.ItemID(i)))
+			}}, uint64(i)))
 		} else {
 			t.NoError(store.Write([]index.Field{{
 				Key:  serviceName,
 				Term: []byte("webpage"),
-			}}, common.ItemID(i)))
+			}}, uint64(i)))
 		}
 	}
 }
diff --git a/pkg/query/logical/index_filter.go b/pkg/query/logical/index_filter.go
index 97855a2c..cc83f7d8 100644
--- a/pkg/query/logical/index_filter.go
+++ b/pkg/query/logical/index_filter.go
@@ -648,7 +648,7 @@ func (an emptyNode) String() string {
 
 type bypassList struct{}
 
-func (bl bypassList) Contains(_ common.ItemID) bool {
+func (bl bypassList) Contains(_ uint64) bool {
 	// all items should be fetched
 	return true
 }
@@ -657,7 +657,7 @@ func (bl bypassList) IsEmpty() bool {
 	return false
 }
 
-func (bl bypassList) Max() (common.ItemID, error) {
+func (bl bypassList) Max() (uint64, error) {
 	panic("not invoked")
 }
 
@@ -677,7 +677,7 @@ func (bl bypassList) Equal(_ posting.List) bool {
 	panic("not invoked")
 }
 
-func (bl bypassList) Insert(_ common.ItemID) {
+func (bl bypassList) Insert(_ uint64) {
 	panic("not invoked")
 }
 
@@ -701,11 +701,11 @@ func (bl bypassList) AddIterator(_ posting.Iterator) error {
 	panic("not invoked")
 }
 
-func (bl bypassList) AddRange(_ common.ItemID, _ common.ItemID) error {
+func (bl bypassList) AddRange(_ uint64, _ uint64) error {
 	panic("not invoked")
 }
 
-func (bl bypassList) RemoveRange(_ common.ItemID, _ common.ItemID) error {
+func (bl bypassList) RemoveRange(_ uint64, _ uint64) error {
 	panic("not invoked")
 }
 
@@ -713,7 +713,7 @@ func (bl bypassList) Reset() {
 	panic("not invoked")
 }
 
-func (bl bypassList) ToSlice() []common.ItemID {
+func (bl bypassList) ToSlice() []uint64 {
 	panic("not invoked")
 }