Skip to content

Commit

Permalink
Push the max int as limitation for aggregation
Browse files Browse the repository at this point in the history
Signed-off-by: Gao Hongtao <[email protected]>
  • Loading branch information
hanahmily committed Jun 28, 2023
1 parent 69ad27b commit 8a81256
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Release Notes.
- Generalize the index's docID to uint64.
- Remove redundant ID tag type.
- Improve granularity of index in `measure` by leveling up from data point to series.
- Set the maximum integer as the limit for aggregation or grouping operations when performing aggregation or grouping operations in a query plan.

### Bugs

Expand Down
17 changes: 11 additions & 6 deletions pkg/query/logical/measure/measure_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package measure

import (
"context"
"math"

commonv1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/common/v1"
measurev1 "github.com/apache/skywalking-banyandb/api/proto/banyandb/measure/v1"
Expand Down Expand Up @@ -72,8 +73,16 @@ func Analyze(_ context.Context, criteria *measurev1.QueryRequest, metadata *comm
// parse fields
plan := parseFields(criteria, metadata, groupByEntity)

// parse limit and offset
limitParameter := criteria.GetLimit()
if limitParameter == 0 {
limitParameter = defaultLimit
}
pushedLimit := int(limitParameter + criteria.GetOffset())

if criteria.GetGroupBy() != nil {
plan = newUnresolvedGroupBy(plan, groupByTags, groupByEntity)
pushedLimit = math.MaxInt
}

if criteria.GetAgg() != nil {
Expand All @@ -82,25 +91,21 @@ func Analyze(_ context.Context, criteria *measurev1.QueryRequest, metadata *comm
criteria.GetAgg().GetFunction(),
criteria.GetGroupBy() != nil,
)
pushedLimit = math.MaxInt
}

if criteria.GetTop() != nil {
plan = top(plan, criteria.GetTop())
}

// parse limit and offset
limitParameter := criteria.GetLimit()
if limitParameter == 0 {
limitParameter = defaultLimit
}
plan = limit(plan, criteria.GetOffset(), limitParameter)
p, err := plan.Analyze(s)
if err != nil {
return nil, err
}
rules := []logical.OptimizeRule{
logical.NewPushDownOrder(criteria.OrderBy),
logical.NewPushDownMaxSize(int(limitParameter + criteria.GetOffset())),
logical.NewPushDownMaxSize(pushedLimit),
}
if err := logical.ApplyRules(p, rules...); err != nil {
return nil, err
Expand Down

0 comments on commit 8a81256

Please sign in to comment.