Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Jun 19, 2024
1 parent 6441298 commit cd246e3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions go/vt/vtgate/planbuilder/operators/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,18 @@ func (a *Aggregator) FindCol(ctx *plancontext.PlanningContext, in sqlparser.Expr

expr := a.DT.RewriteExpression(ctx, in)
if offset, found := canReuseColumn(ctx, a.Columns, expr, extractExpr); found {
a.checkOffset(offset)
return offset
}
return -1
}

func (a *Aggregator) checkOffset(offset int) {
if a.ResultColumns > 0 && a.ResultColumns <= offset {
a.ResultColumns = offset + 1
}
}

func (a *Aggregator) AddColumn(ctx *plancontext.PlanningContext, reuse bool, groupBy bool, ae *sqlparser.AliasedExpr) int {
rewritten := a.DT.RewriteExpression(ctx, ae.Expr)

Expand All @@ -160,6 +167,7 @@ func (a *Aggregator) AddColumn(ctx *plancontext.PlanningContext, reuse bool, gro
if reuse {
offset := a.findColInternal(ctx, ae, groupBy)
if offset >= 0 {
a.checkOffset(offset)
return offset
}
}
Expand Down Expand Up @@ -191,6 +199,7 @@ func (a *Aggregator) AddColumn(ctx *plancontext.PlanningContext, reuse bool, gro
panic(errFailedToPlan(ae))
}

a.checkOffset(offset)
return offset
}

Expand Down Expand Up @@ -249,6 +258,7 @@ func (a *Aggregator) AddWSColumn(ctx *plancontext.PlanningContext, offset int, u
// TODO: we could handle this case by adding a projection on under the aggregator to make the columns line up
panic(errFailedToPlan(wsAe))
}
a.checkOffset(wsOffset)
return wsOffset
}

Expand Down

0 comments on commit cd246e3

Please sign in to comment.