Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize query performance of series index #491

Merged
merged 21 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Release Notes.
- Add the stream query trace.
- Add the topN query trace.
- Introduce the round-robin selector to Liaison Node.
- Optimize query performance of series index.

### Bugs

Expand Down
12 changes: 5 additions & 7 deletions banyand/internal/storage/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ import (
"go.uber.org/multierr"

"github.com/apache/skywalking-banyandb/api/common"
databasev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1"
"github.com/apache/skywalking-banyandb/pkg/index"
"github.com/apache/skywalking-banyandb/pkg/index/inverted"
"github.com/apache/skywalking-banyandb/pkg/index/posting"
"github.com/apache/skywalking-banyandb/pkg/logger"
pbv1 "github.com/apache/skywalking-banyandb/pkg/pb/v1"
"github.com/apache/skywalking-banyandb/pkg/query"
"github.com/apache/skywalking-banyandb/pkg/query/logical"
"github.com/apache/skywalking-banyandb/pkg/query/model"
)

Expand Down Expand Up @@ -172,7 +170,9 @@ func convertIndexSeriesToSeriesList(indexSeries []index.Series) (pbv1.SeriesList
return seriesList, nil
}

func (s *seriesIndex) Search(ctx context.Context, series []*pbv1.Series, filter index.Filter, order *model.OrderBy, preloadSize int) (sl pbv1.SeriesList, err error) {
func (s *seriesIndex) Search(ctx context.Context, series []*pbv1.Series, blugeQuery *inverted.BlugeQuery,
filter index.Filter, order *model.OrderBy, preloadSize int,
) (sl pbv1.SeriesList, err error) {
tracer := query.GetTracer(ctx)
if tracer != nil {
var span *query.Span
Expand All @@ -190,7 +190,7 @@ func (s *seriesIndex) Search(ctx context.Context, series []*pbv1.Series, filter
}

pl := seriesList.ToList()
if filter != nil && filter != logical.ENode {
if blugeQuery != nil {
var plFilter posting.List
func() {
if tracer != nil {
Expand All @@ -206,9 +206,7 @@ func (s *seriesIndex) Search(ctx context.Context, series []*pbv1.Series, filter
span.Stop()
}()
}
if plFilter, err = filter.Execute(func(_ databasev1.IndexRule_Type) (index.Searcher, error) {
return s.store, nil
}, 0); err != nil {
if plFilter, err = s.store.Execute(blugeQuery); err != nil {
return
}
if plFilter == nil {
Expand Down
3 changes: 2 additions & 1 deletion banyand/internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
"github.com/apache/skywalking-banyandb/pkg/fs"
"github.com/apache/skywalking-banyandb/pkg/index"
"github.com/apache/skywalking-banyandb/pkg/index/inverted"
"github.com/apache/skywalking-banyandb/pkg/logger"
pbv1 "github.com/apache/skywalking-banyandb/pkg/pb/v1"
"github.com/apache/skywalking-banyandb/pkg/query/model"
Expand Down Expand Up @@ -67,7 +68,7 @@ type SupplyTSDB[T TSTable] func() T
// IndexDB is the interface of index database.
type IndexDB interface {
Write(docs index.Documents) error
Search(ctx context.Context, series []*pbv1.Series, filter index.Filter, order *model.OrderBy, preloadSize int) (pbv1.SeriesList, error)
Search(ctx context.Context, series []*pbv1.Series, query *inverted.BlugeQuery, filter index.Filter, order *model.OrderBy, preloadSize int) (pbv1.SeriesList, error)
hanahmily marked this conversation as resolved.
Show resolved Hide resolved
}

// TSDB allows listing and getting shard details.
Expand Down
2 changes: 1 addition & 1 deletion banyand/measure/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (s *measure) searchSeriesList(ctx context.Context, series []*pbv1.Series, m
) (sl pbv1.SeriesList, tables []*tsTable, err error) {
for i := range segments {
tables = append(tables, segments[i].Tables()...)
sll, err := segments[i].IndexDB().Search(ctx, series, mqo.Filter, mqo.Order, preloadSize)
sll, err := segments[i].IndexDB().Search(ctx, series, mqo.Query, mqo.Filter, mqo.Order, preloadSize)
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions banyand/stream/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ import (
"github.com/apache/skywalking-banyandb/banyand/internal/storage"
"github.com/apache/skywalking-banyandb/pkg/convert"
"github.com/apache/skywalking-banyandb/pkg/index"
"github.com/apache/skywalking-banyandb/pkg/index/inverted"
"github.com/apache/skywalking-banyandb/pkg/index/posting"
"github.com/apache/skywalking-banyandb/pkg/index/posting/roaring"
itersort "github.com/apache/skywalking-banyandb/pkg/iter/sort"
"github.com/apache/skywalking-banyandb/pkg/logger"
"github.com/apache/skywalking-banyandb/pkg/partition"
pbv1 "github.com/apache/skywalking-banyandb/pkg/pb/v1"
"github.com/apache/skywalking-banyandb/pkg/query"
"github.com/apache/skywalking-banyandb/pkg/query/logical"
"github.com/apache/skywalking-banyandb/pkg/query/model"
)

Expand Down Expand Up @@ -519,7 +519,7 @@ func (qr *queryResult) mergeByTimestamp() *model.StreamResult {
func indexSearch(sqo model.StreamQueryOptions,
tabs []*tsTable, seriesList pbv1.SeriesList,
) (posting.List, error) {
if sqo.Filter == nil || sqo.Filter == logical.ENode {
if sqo.Filter == nil || sqo.Filter == inverted.ENode {
return nil, nil
}
result := roaring.NewPostingList()
Expand Down
29 changes: 29 additions & 0 deletions pkg/convert/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to Apache Software Foundation (ASF) under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Apache Software Foundation (ASF) licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package convert

import "encoding/json"

// JSONToString converts a JSON marshaler to its JSON string representation.
func JSONToString(marshaler json.Marshaler) string {
bb, err := marshaler.MarshalJSON()
if err != nil {
return err.Error()
}
return string(bb)
}
4 changes: 4 additions & 0 deletions pkg/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"fmt"
"io"

"github.com/blugelabs/bluge"

"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"
Expand Down Expand Up @@ -188,6 +190,8 @@ type SeriesStore interface {
Store
// Search returns a list of series that match the given matchers.
Search(context.Context, []SeriesMatcher) ([]Series, error)
// Execute returns a posting list that matches the given query.
Execute(bluge.Query) (posting.List, error)
hanahmily marked this conversation as resolved.
Show resolved Hide resolved
}

// SeriesMatcherType represents the type of series matcher.
Expand Down
Loading
Loading