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

Push the max int as limitation #289

Merged
merged 3 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -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