Skip to content

Commit 6aef624

Browse files
authored
planner: move invalidTask to task base pkg. (#53267)
ref #51664, ref #52714
1 parent acdb6f5 commit 6aef624

File tree

7 files changed

+84
-72
lines changed

7 files changed

+84
-72
lines changed

pkg/planner/core/base/task_base.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ type Task interface {
3232
// MemoryUsage returns the memory usage of current task.
3333
MemoryUsage() int64
3434
}
35+
36+
// InvalidTask is just a common invalid singleton instance initialized by core's empty RootTask.
37+
var InvalidTask Task

pkg/planner/core/core_init.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package core
1717
import (
1818
"github.com/pingcap/tidb/pkg/expression"
1919
"github.com/pingcap/tidb/pkg/planner/cardinality"
20+
"github.com/pingcap/tidb/pkg/planner/core/base"
2021
plannerutil "github.com/pingcap/tidb/pkg/planner/util"
2122
"github.com/pingcap/tidb/pkg/planner/util/utilfuncp"
2223
"github.com/pingcap/tidb/pkg/statistics"
@@ -38,6 +39,7 @@ func init() {
3839
statistics.PrepareCols4MVIndex = PrepareIdxColsAndUnwrapArrayType
3940

4041
// For basic optimizer init.
42+
base.InvalidTask = &RootTask{} // invalid if p is nil
4143
expression.EvalSimpleAst = evalAstExpr
4244
expression.BuildSimpleExpr = buildSimpleExpr
4345
expression.DecodeKeyFromString = decodeKeyFromString

pkg/planner/core/find_best_task.go

Lines changed: 61 additions & 54 deletions
Large diffs are not rendered by default.

pkg/planner/core/plan.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ func enforceProperty(p *property.PhysicalProperty, tsk base.Task, ctx base.PlanC
4848
if p.TaskTp == property.MppTaskType {
4949
mpp, ok := tsk.(*MppTask)
5050
if !ok || mpp.Invalid() {
51-
return invalidTask
51+
return base.InvalidTask
5252
}
5353
if !p.IsSortItemAllForPartition() {
5454
ctx.GetSessionVars().RaiseWarningWhenMPPEnforced("MPP mode may be blocked because operator `Sort` is not supported now.")
55-
return invalidTask
55+
return base.InvalidTask
5656
}
5757
tsk = mpp.enforceExchanger(p)
5858
}

pkg/planner/core/task.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,12 @@ func (p *PhysicalHashJoin) attach2TaskForMpp(tasks ...base.Task) base.Task {
387387
lTask, lok := tasks[0].(*MppTask)
388388
rTask, rok := tasks[1].(*MppTask)
389389
if !lok || !rok {
390-
return invalidTask
390+
return base.InvalidTask
391391
}
392392
if p.mppShuffleJoin {
393393
// protection check is case of some bugs
394394
if len(lTask.hashCols) != len(rTask.hashCols) || len(lTask.hashCols) == 0 {
395-
return invalidTask
395+
return base.InvalidTask
396396
}
397397
lTask, rTask = p.convertPartitionKeysIfNeed(lTask, rTask)
398398
}
@@ -1017,7 +1017,7 @@ func (p *PhysicalExpand) Attach2Task(tasks ...base.Task) base.Task {
10171017
mpp.p = p
10181018
return mpp
10191019
}
1020-
return invalidTask
1020+
return base.InvalidTask
10211021
}
10221022

10231023
// Attach2Task implements PhysicalPlan interface.
@@ -1052,11 +1052,11 @@ func (p *PhysicalUnionAll) attach2MppTasks(tasks ...base.Task) base.Task {
10521052
} else if root, ok := tk.(*RootTask); ok && root.IsEmpty() {
10531053
continue
10541054
} else {
1055-
return invalidTask
1055+
return base.InvalidTask
10561056
}
10571057
}
10581058
if len(childPlans) == 0 {
1059-
return invalidTask
1059+
return base.InvalidTask
10601060
}
10611061
p.SetChildren(childPlans...)
10621062
return t
@@ -1069,8 +1069,8 @@ func (p *PhysicalUnionAll) Attach2Task(tasks ...base.Task) base.Task {
10691069
if p.TP() == plancodec.TypePartitionUnion {
10701070
// In attach2MppTasks(), will attach PhysicalUnion to mppTask directly.
10711071
// But PartitionUnion cannot pushdown to tiflash, so here disable PartitionUnion pushdown to tiflash explicitly.
1072-
// For now, return invalidTask immediately, we can refine this by letting childTask of PartitionUnion convert to rootTask.
1073-
return invalidTask
1072+
// For now, return base.InvalidTask immediately, we can refine this by letting childTask of PartitionUnion convert to rootTask.
1073+
return base.InvalidTask
10741074
}
10751075
return p.attach2MppTasks(tasks...)
10761076
}
@@ -1758,7 +1758,7 @@ func (p *PhysicalStreamAgg) Attach2Task(tasks ...base.Task) base.Task {
17581758
storeType := cop.getStoreType()
17591759
// TiFlash doesn't support Stream Aggregation
17601760
if storeType == kv.TiFlash && len(p.GroupByItems) > 0 {
1761-
return invalidTask
1761+
return base.InvalidTask
17621762
}
17631763
partialAgg, finalAgg := p.newPartialAggregate(storeType, false)
17641764
if partialAgg != nil {
@@ -2122,7 +2122,7 @@ func (p *PhysicalHashAgg) attach2TaskForMpp(tasks ...base.Task) base.Task {
21222122
t := tasks[0].Copy()
21232123
mpp, ok := t.(*MppTask)
21242124
if !ok {
2125-
return invalidTask
2125+
return base.InvalidTask
21262126
}
21272127
switch p.MppRunMode {
21282128
case Mpp1Phase:
@@ -2139,7 +2139,7 @@ func (p *PhysicalHashAgg) attach2TaskForMpp(tasks ...base.Task) base.Task {
21392139
proj := p.convertAvgForMPP()
21402140
partialAgg, finalAgg := p.newPartialAggregate(kv.TiFlash, true)
21412141
if partialAgg == nil {
2142-
return invalidTask
2142+
return base.InvalidTask
21432143
}
21442144
attachPlan2Task(partialAgg, mpp)
21452145
partitionCols := p.MppPartitionCols
@@ -2149,7 +2149,7 @@ func (p *PhysicalHashAgg) attach2TaskForMpp(tasks ...base.Task) base.Task {
21492149
for _, expr := range items {
21502150
col, ok := expr.(*expression.Column)
21512151
if !ok {
2152-
return invalidTask
2152+
return base.InvalidTask
21532153
}
21542154
partitionCols = append(partitionCols, &property.MPPPartitionColumn{
21552155
Col: col,
@@ -2188,12 +2188,12 @@ func (p *PhysicalHashAgg) attach2TaskForMpp(tasks ...base.Task) base.Task {
21882188
proj := p.convertAvgForMPP()
21892189
partialAgg, finalAgg := p.newPartialAggregate(kv.TiFlash, true)
21902190
if finalAgg == nil {
2191-
return invalidTask
2191+
return base.InvalidTask
21922192
}
21932193

21942194
final, middle, partial, proj4Partial, err := p.adjust3StagePhaseAgg(partialAgg, finalAgg, canUse3StageAgg, groupingSets, mpp)
21952195
if err != nil {
2196-
return invalidTask
2196+
return base.InvalidTask
21972197
}
21982198

21992199
// partial agg proj would be null if one scalar agg cannot run in two-phase mode
@@ -2241,7 +2241,7 @@ func (p *PhysicalHashAgg) attach2TaskForMpp(tasks ...base.Task) base.Task {
22412241
attachPlan2Task(proj, newMpp)
22422242
return newMpp
22432243
default:
2244-
return invalidTask
2244+
return base.InvalidTask
22452245
}
22462246
}
22472247

pkg/planner/core/task_base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (t *MppTask) ConvertToRootTaskImpl(ctx base.PlanContext) *RootTask {
201201
// It's only for TableScan. This is ensured by converting mppTask to rootTask just after TableScan is built,
202202
// so no other operators are added into this mppTask.
203203
logutil.BgLogger().Error("expect Selection or TableScan for mppTask.p", zap.String("mppTask.p", t.p.TP()))
204-
return invalidTask
204+
return base.InvalidTask.(*RootTask)
205205
}
206206
selectivity, _, err := cardinality.Selectivity(ctx, t.tblColHists, t.rootTaskConds, nil)
207207
if err != nil {

pkg/planner/util/utilfuncp/func_pointer_misc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ var GetTaskPlanCost func(t base.Task, pop *optimizetrace.PhysicalOptimizeOp) (fl
4848

4949
// AddSelection will add a selection if necessary.
5050
// This function is util function pointer that initialized by core functionality.
51-
// todo: (3) arenatlx, remove this func pointer when inside referred LogicalSelection is moved out of core.
51+
// todo: (4) arenatlx, remove this func pointer when inside referred LogicalSelection is moved out of core.
5252
var AddSelection func(p base.LogicalPlan, child base.LogicalPlan, conditions []expression.Expression,
5353
chIdx int, opt *optimizetrace.LogicalOptimizeOp)

0 commit comments

Comments
 (0)