diff --git a/pkg/dal/exec_aggregate.go b/pkg/dal/exec_aggregate.go index 167a21038..e8e1a96d1 100644 --- a/pkg/dal/exec_aggregate.go +++ b/pkg/dal/exec_aggregate.go @@ -87,7 +87,7 @@ func (xs *aggregate) Next(ctx context.Context) (more bool) { func (xs *aggregate) next(ctx context.Context) (more bool, err error) { var g *aggregateGroup for { - if xs.ctr >= int(xs.filter.limit) { + if xs.limitExceeded() { return false, nil } @@ -134,6 +134,10 @@ func (xs *aggregate) next(ctx context.Context) (more bool, err error) { return true, nil } +func (xs *aggregate) limitExceeded() bool { + return xs.filter.limit > 0 && xs.ctr >= int(xs.filter.limit) +} + func (xs *aggregate) More(limit uint, v ValueGetter) (err error) { // Redo the cursor xs.filter.cursor, err = filter.PagingCursorFrom(xs.filter.OrderBy(), v, xs.collectPrimaryAttributes()...) diff --git a/pkg/dal/exec_join_left.go b/pkg/dal/exec_join_left.go index b563da30a..d5f1d2907 100644 --- a/pkg/dal/exec_join_left.go +++ b/pkg/dal/exec_join_left.go @@ -162,7 +162,7 @@ func (xs *joinLeft) ForwardCursor(v ValueGetter) (pc *filter.PagingCursor, err e // next prepares the next scan row based on the defined join plan func (xs *joinLeft) next(ctx context.Context) (more bool, err error) { - if xs.i >= int(xs.filter.limit) { + if !xs.limitExceeded() { return false, nil } @@ -176,6 +176,10 @@ func (xs *joinLeft) next(ctx context.Context) (more bool, err error) { return true, nil } +func (xs *joinLeft) limitExceeded() bool { + return xs.filter.limit > 0 && xs.i >= int(xs.filter.limit) +} + // pullNext pulls additional data so we can produce more // // This step may be omitted based on the join plan.