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

planner: stream agg should not be pushed to double read (#12443) #12690

Merged
merged 3 commits into from
Oct 28, 2019
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
7 changes: 4 additions & 3 deletions planner/core/rule_inject_extra_projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ func injectProjBelowAgg(aggPlan PhysicalPlan, aggFuncs []*aggregation.AggFuncDes
}
projExprs = append(projExprs, arg)
newArg := &expression.Column{
RetType: arg.GetType(),
ColName: model.NewCIStr(fmt.Sprintf("col_%d", len(projSchemaCols))),
Index: cursor,
UniqueID: aggPlan.context().GetSessionVars().AllocPlanColumnID(),
RetType: arg.GetType(),
ColName: model.NewCIStr(fmt.Sprintf("col_%d", len(projSchemaCols))),
Index: cursor,
}
projSchemaCols = append(projSchemaCols, newArg)
f.Args[i] = newArg
Expand Down
29 changes: 19 additions & 10 deletions planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,18 +509,27 @@ func (p *basePhysicalAgg) newPartialAggregate() (partial, final PhysicalPlan) {
func (p *PhysicalStreamAgg) attach2Task(tasks ...task) task {
t := tasks[0].copy()
if cop, ok := t.(*copTask); ok {
partialAgg, finalAgg := p.newPartialAggregate()
if partialAgg != nil {
if cop.tablePlan != nil {
partialAgg.SetChildren(cop.tablePlan)
cop.tablePlan = partialAgg
} else {
partialAgg.SetChildren(cop.indexPlan)
cop.indexPlan = partialAgg
// We should not push agg down across double read, since the data of second read is ordered by handle instead of index.
// The `doubleReadNeedProj` is always set if the double read needs to keep order. So we just use it to decided
// whether the following plan is double read with order reserved.
if !cop.doubleReadNeedProj {
partialAgg, finalAgg := p.newPartialAggregate()
if partialAgg != nil {
if cop.tablePlan != nil {
cop.finishIndexPlan()
partialAgg.SetChildren(cop.tablePlan)
cop.tablePlan = partialAgg
} else {
partialAgg.SetChildren(cop.indexPlan)
cop.indexPlan = partialAgg
}
}
t = finishCopTask(p.ctx, cop)
attachPlan2Task(finalAgg, t)
} else {
t = finishCopTask(p.ctx, cop)
attachPlan2Task(p, t)
}
t = finishCopTask(p.ctx, cop)
attachPlan2Task(finalAgg, t)
} else {
attachPlan2Task(p, t)
}
Expand Down