diff --git a/CHANGES.md b/CHANGES.md index b5a83500d..770060cea 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/pkg/query/logical/measure/measure_analyzer.go b/pkg/query/logical/measure/measure_analyzer.go index 953681477..30a3623dc 100644 --- a/pkg/query/logical/measure/measure_analyzer.go +++ b/pkg/query/logical/measure/measure_analyzer.go @@ -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" @@ -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 { @@ -82,17 +91,13 @@ 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 { @@ -100,7 +105,7 @@ func Analyze(_ context.Context, criteria *measurev1.QueryRequest, metadata *comm } 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