Skip to content

Commit

Permalink
planner: enable more linter for planner/core/plan.go (pingcap#37072)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei authored Aug 12, 2022
1 parent 96ada10 commit 61c8438
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
3 changes: 3 additions & 0 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"server/conn.go": "server/conn.go",
"server/conn_stmt.go": "server/conn_stmt.go",
"server/conn_test.go": "server/conn_test.go",
"planner/core/plan.go": "planner/core/plan.go",
"errno/": "only table code"
}
},
Expand Down Expand Up @@ -300,6 +301,7 @@
"planner/implementation": "planner code",
"planner/cascades": "planner code",
"planner/core/plan_cache.go": "planner code",
"planner/core/plan.go": "planner/core/plan.go",
"util/": "util code",
"parser/": "parser code",
"meta/": "parser code"
Expand Down Expand Up @@ -637,6 +639,7 @@
},
"only_files": {
"expression/builtin_cast.go": "enable expression/builtin_cast.go",
"planner/core/plan.go": "planner/core/plan.go",
"server/conn.go": "server/conn.go",
"server/conn_stmt.go": "server/conn_stmt.go",
"server/conn_test.go": "server/conn_test.go",
Expand Down
50 changes: 24 additions & 26 deletions planner/core/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ func optimizeByShuffle4Window(pp *PhysicalWindow, ctx sessionctx.Context) *Physi
for _, item := range pp.PartitionBy {
partitionBy = append(partitionBy, item.Col)
}
NDV := int(getColsNDV(partitionBy, dataSource.Schema(), dataSource.statsInfo()))
if NDV <= 1 {
ndv := int(getColsNDV(partitionBy, dataSource.Schema(), dataSource.statsInfo()))
if ndv <= 1 {
return nil
}
concurrency = mathutil.Min(concurrency, NDV)
concurrency = mathutil.Min(concurrency, ndv)

byItems := make([]expression.Expression, 0, len(pp.PartitionBy))
for _, item := range pp.PartitionBy {
Expand Down Expand Up @@ -182,11 +182,11 @@ func optimizeByShuffle4StreamAgg(pp *PhysicalStreamAgg, ctx sessionctx.Context)
partitionBy = append(partitionBy, col)
}
}
NDV := int(getColsNDV(partitionBy, dataSource.Schema(), dataSource.statsInfo()))
if NDV <= 1 {
ndv := int(getColsNDV(partitionBy, dataSource.Schema(), dataSource.statsInfo()))
if ndv <= 1 {
return nil
}
concurrency = mathutil.Min(concurrency, NDV)
concurrency = mathutil.Min(concurrency, ndv)

reqProp := &property.PhysicalProperty{ExpectedCnt: math.MaxFloat64}
shuffle := PhysicalShuffle{
Expand Down Expand Up @@ -445,7 +445,7 @@ func (p *baseLogicalPlan) MaxOneRow() bool {
}

// ExplainInfo implements Plan interface.
func (p *baseLogicalPlan) ExplainInfo() string {
func (*baseLogicalPlan) ExplainInfo() string {
return ""
}

Expand Down Expand Up @@ -505,12 +505,12 @@ func (p *basePhysicalPlan) Clone() (PhysicalPlan, error) {
}

// ExplainInfo implements Plan interface.
func (p *basePhysicalPlan) ExplainInfo() string {
func (*basePhysicalPlan) ExplainInfo() string {
return ""
}

// ExplainNormalizedInfo implements PhysicalPlan interface.
func (p *basePhysicalPlan) ExplainNormalizedInfo() string {
func (*basePhysicalPlan) ExplainNormalizedInfo() string {
return ""
}

Expand All @@ -519,41 +519,41 @@ func (p *basePhysicalPlan) GetChildReqProps(idx int) *property.PhysicalProperty
}

// ExtractCorrelatedCols implements PhysicalPlan interface.
func (p *basePhysicalPlan) ExtractCorrelatedCols() []*expression.CorrelatedColumn {
func (*basePhysicalPlan) ExtractCorrelatedCols() []*expression.CorrelatedColumn {
return nil
}

// GetLogicalTS4TaskMap get the logical TimeStamp now to help rollback the TaskMap changes after that.
func (p *baseLogicalPlan) GetLogicalTS4TaskMap() uint64 {
p.ctx.GetSessionVars().StmtCtx.TaskMapBakTS += 1
p.ctx.GetSessionVars().StmtCtx.TaskMapBakTS++
return p.ctx.GetSessionVars().StmtCtx.TaskMapBakTS
}

func (p *baseLogicalPlan) rollBackTaskMap(TS uint64) {
func (p *baseLogicalPlan) rollBackTaskMap(ts uint64) {
if !p.ctx.GetSessionVars().StmtCtx.StmtHints.TaskMapNeedBackUp() {
return
}
if len(p.taskMapBak) > 0 {
// Rollback all the logs with TimeStamp TS.
N := len(p.taskMapBak)
for i := 0; i < N; i++ {
n := len(p.taskMapBak)
for i := 0; i < n; i++ {
cur := p.taskMapBak[i]
if p.taskMapBakTS[i] < TS {
if p.taskMapBakTS[i] < ts {
continue
}

// Remove the i_th log.
p.taskMapBak = append(p.taskMapBak[:i], p.taskMapBak[i+1:]...)
p.taskMapBakTS = append(p.taskMapBakTS[:i], p.taskMapBakTS[i+1:]...)
i--
N--
n--

// Roll back taskMap.
p.taskMap[cur] = nil
}
}
for _, child := range p.children {
child.rollBackTaskMap(TS)
child.rollBackTaskMap(ts)
}
}

Expand All @@ -566,8 +566,8 @@ func (p *baseLogicalPlan) storeTask(prop *property.PhysicalProperty, task task)
key := prop.HashCode()
if p.ctx.GetSessionVars().StmtCtx.StmtHints.TaskMapNeedBackUp() {
// Empty string for useless change.
TS := p.GetLogicalTS4TaskMap()
p.taskMapBakTS = append(p.taskMapBakTS, TS)
ts := p.GetLogicalTS4TaskMap()
p.taskMapBakTS = append(p.taskMapBakTS, ts)
p.taskMapBak = append(p.taskMapBak, string(key))
}
p.taskMap[string(key)] = task
Expand Down Expand Up @@ -657,7 +657,7 @@ func newBasePhysicalPlan(ctx sessionctx.Context, tp string, self PhysicalPlan, o
}
}

func (p *baseLogicalPlan) ExtractCorrelatedCols() []*expression.CorrelatedColumn {
func (*baseLogicalPlan) ExtractCorrelatedCols() []*expression.CorrelatedColumn {
return nil
}

Expand All @@ -680,15 +680,13 @@ type basePlan struct {
}

// OutputNames returns the outputting names of each column.
func (p *basePlan) OutputNames() types.NameSlice {
func (*basePlan) OutputNames() types.NameSlice {
return nil
}

func (p *basePlan) SetOutputNames(_ types.NameSlice) {
}
func (*basePlan) SetOutputNames(_ types.NameSlice) {}

func (p *basePlan) replaceExprColumns(_ map[string]*expression.Column) {
}
func (*basePlan) replaceExprColumns(_ map[string]*expression.Column) {}

// ID implements Plan ID interface.
func (p *basePlan) ID() int {
Expand All @@ -701,7 +699,7 @@ func (p *basePlan) statsInfo() *property.StatsInfo {
}

// ExplainInfo implements Plan interface.
func (p *basePlan) ExplainInfo() string {
func (*basePlan) ExplainInfo() string {
return "N/A"
}

Expand Down

0 comments on commit 61c8438

Please sign in to comment.