Skip to content

Commit

Permalink
Push the max int as limitation (#289)
Browse files Browse the repository at this point in the history
Signed-off-by: Gao Hongtao <[email protected]>
Co-authored-by: Jiajing LU <[email protected]>
  • Loading branch information
hanahmily and lujiajing1126 authored Jun 28, 2023
1 parent 6d50052 commit 1f2e8f4
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 @@ -32,6 +32,7 @@ Release Notes.

- Fix iterator leaks and ensure proper closure and introduce a closer to guarantee all iterators are closed
- Fix resource corrupts caused by update indexRule operation
- Set the maximum integer as the limit for aggregation or grouping operations when performing aggregation or grouping operations in a query plan.

### Chores

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 1f2e8f4

Please sign in to comment.