Skip to content

Commit

Permalink
address the comment
Browse files Browse the repository at this point in the history
Signed-off-by: yisaer <disxiaofei@163.com>
  • Loading branch information
Yisaer committed Nov 29, 2021
1 parent 518c657 commit 713d65c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
19 changes: 0 additions & 19 deletions planner/core/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/plancodec"
"github.com/pingcap/tidb/util/stringutil"
"github.com/pingcap/tidb/util/tracing"
"github.com/pingcap/tipb/go-tipb"
)

Expand Down Expand Up @@ -891,23 +890,11 @@ func (p *LogicalAggregation) ExplainInfo() string {
return buffer.String()
}

func (p *LogicalAggregation) buildLogicalPlanTrace() *tracing.LogicalPlanTrace {
lpt := p.baseLogicalPlan.buildLogicalPlanTrace()
lpt.ExplainInfo = p.ExplainInfo()
return lpt
}

// ExplainInfo implements Plan interface.
func (p *LogicalProjection) ExplainInfo() string {
return expression.ExplainExpressionList(p.Exprs, p.schema)
}

func (p *LogicalProjection) buildLogicalPlanTrace() *tracing.LogicalPlanTrace {
lpt := p.baseLogicalPlan.buildLogicalPlanTrace()
lpt.ExplainInfo = p.ExplainInfo()
return lpt
}

// ExplainInfo implements Plan interface.
func (p *LogicalSelection) ExplainInfo() string {
return string(expression.SortedExplainExpressionList(p.Conditions))
Expand Down Expand Up @@ -943,12 +930,6 @@ func (ds *DataSource) ExplainInfo() string {
return buffer.String()
}

func (ds *DataSource) buildLogicalPlanTrace() *tracing.LogicalPlanTrace {
lpt := ds.baseLogicalPlan.buildLogicalPlanTrace()
lpt.ExplainInfo = ds.ExplainInfo()
return lpt
}

// ExplainInfo implements Plan interface.
func (p *PhysicalExchangeSender) ExplainInfo() string {
buffer := bytes.NewBufferString("ExchangeType: ")
Expand Down
4 changes: 2 additions & 2 deletions planner/core/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (op *logicalOptimizeOp) appendBeforeRuleOptimize(index int, name string, be
if op.tracer == nil {
return
}
op.tracer.AppendRuleTracerBeforeRuleOptimize(index, name, before.buildLogicalPlanTrace())
op.tracer.AppendRuleTracerBeforeRuleOptimize(index, name, before.buildLogicalPlanTrace(before))
}

func (op *logicalOptimizeOp) appendStepToCurrent(id int, tp, reason, action string) {
Expand All @@ -116,7 +116,7 @@ func (op *logicalOptimizeOp) trackAfterRuleOptimize(after LogicalPlan) {
if op.tracer == nil {
return
}
op.tracer.TrackLogicalPlanAfterRuleOptimize(after.buildLogicalPlanTrace())
op.tracer.TrackLogicalPlanAfterRuleOptimize(after.buildLogicalPlanTrace(after))
}

// logicalOptRule means a logical optimizing rule, which contains decorrelate, ppd, column pruning, etc.
Expand Down
13 changes: 9 additions & 4 deletions planner/core/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ type Plan interface {
SelectBlockOffset() int
}

type OperatorExplainInfo interface {
// ExplainInfo returns operator information to be explained.
ExplainInfo() string
}

func enforceProperty(p *property.PhysicalProperty, tsk task, ctx sessionctx.Context) task {
if p.TaskTp == property.MppTaskType {
if mpp, ok := tsk.(*mppTask); ok && !mpp.invalid() {
Expand Down Expand Up @@ -308,7 +313,7 @@ type LogicalPlan interface {
canPushToCop(store kv.StoreType) bool

// buildLogicalPlanTrace clone necessary information from LogicalPlan
buildLogicalPlanTrace() *tracing.LogicalPlanTrace
buildLogicalPlanTrace(op OperatorExplainInfo) *tracing.LogicalPlanTrace
}

// PhysicalPlan is a tree of the physical operators.
Expand Down Expand Up @@ -382,10 +387,10 @@ func (p *baseLogicalPlan) ExplainInfo() string {
}

// buildLogicalPlanTrace implements LogicalPlan
func (p *baseLogicalPlan) buildLogicalPlanTrace() *tracing.LogicalPlanTrace {
planTrace := &tracing.LogicalPlanTrace{ID: p.ID(), TP: p.TP()}
func (p *baseLogicalPlan) buildLogicalPlanTrace(op OperatorExplainInfo) *tracing.LogicalPlanTrace {
planTrace := &tracing.LogicalPlanTrace{ID: p.ID(), TP: p.TP(), ExplainInfo: op.ExplainInfo()}
for _, child := range p.Children() {
planTrace.Children = append(planTrace.Children, child.buildLogicalPlanTrace())
planTrace.Children = append(planTrace.Children, child.buildLogicalPlanTrace(child))
}
return planTrace
}
Expand Down

0 comments on commit 713d65c

Please sign in to comment.