3
0

Fixed improper limit check for aggregate and join

This commit is contained in:
Tomaž Jerman
2022-09-21 15:38:55 +02:00
parent 340873c82e
commit d7ecbafa66
2 changed files with 10 additions and 2 deletions

View File

@@ -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()...)

View File

@@ -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.