From 3583aba62abdd8df2ebfea9bdbf38a9b2df6bf08 Mon Sep 17 00:00:00 2001 From: yisaer Date: Mon, 20 Dec 2021 17:01:04 +0800 Subject: [PATCH 1/4] address the comment Signed-off-by: yisaer --- planner/core/logical_plan_trace_test.go | 70 ++++++++++---------- planner/core/optimizer.go | 4 +- planner/core/plan.go | 8 +-- planner/core/rule_aggregation_elimination.go | 6 +- planner/core/rule_aggregation_push_down.go | 20 +++--- planner/core/rule_eliminate_projection.go | 8 +-- planner/core/rule_join_elimination.go | 4 +- planner/core/rule_join_reorder.go | 6 +- planner/core/rule_max_min_eliminate.go | 26 ++++---- planner/core/rule_partition_processor.go | 14 ++-- 10 files changed, 83 insertions(+), 83 deletions(-) diff --git a/planner/core/logical_plan_trace_test.go b/planner/core/logical_plan_trace_test.go index 58348bd7712de..d456cbfc677bc 100644 --- a/planner/core/logical_plan_trace_test.go +++ b/planner/core/logical_plan_trace_test.go @@ -92,8 +92,8 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "partition_processor", assertRuleSteps: []assertTraceStep{ { - assertReason: "Datasource[1] has multiple needed partitions[p1,p2] after pruning", - assertAction: "Datasource[1] becomes PartitionUnion[6] with children[TableScan[1],TableScan[1]]", + assertReason: "DataSource_1 has multiple needed partitions[p1,p2] after pruning", + assertAction: "DataSource_1 becomes PartitionUnion_6 with children[TableScan_1,TableScan_1]", }, }, }, @@ -103,8 +103,8 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "partition_processor", assertRuleSteps: []assertTraceStep{ { - assertReason: "Datasource[1] has one needed partition[p1] after pruning", - assertAction: "Datasource[1] becomes TableScan[1]", + assertReason: "DataSource_1 has one needed partition[p1] after pruning", + assertAction: "DataSource_1 becomes TableScan_1", }, }, }, @@ -114,8 +114,8 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "partition_processor", assertRuleSteps: []assertTraceStep{ { - assertReason: "Datasource[1] has multiple needed partitions[p1,p2] after pruning", - assertAction: "Datasource[1] becomes PartitionUnion[7] with children[TableScan[1],TableScan[1]]", + assertReason: "DataSource_1 has multiple needed partitions[p1,p2] after pruning", + assertAction: "DataSource_1 becomes PartitionUnion_7 with children[TableScan_1,TableScan_1]", }, }, }, @@ -125,8 +125,8 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "partition_processor", assertRuleSteps: []assertTraceStep{ { - assertReason: "Datasource[1] has one needed partition[p2] after pruning", - assertAction: "Datasource[1] becomes TableScan[1]", + assertReason: "DataSource_1 has one needed partition[p2] after pruning", + assertAction: "DataSource_1 becomes TableScan_1", }, }, }, @@ -136,8 +136,8 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "partition_processor", assertRuleSteps: []assertTraceStep{ { - assertReason: "Datasource[1] doesn't have needed partition table after pruning", - assertAction: "Datasource[1] becomes TableDual[5]", + assertReason: "DataSource_1 doesn't have needed partition table after pruning", + assertAction: "DataSource_1 becomes TableDual_5", }, }, }, @@ -147,8 +147,8 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "partition_processor", assertRuleSteps: []assertTraceStep{ { - assertReason: "Datasource[1] has multiple needed partitions[p1,p2] after pruning", - assertAction: "Datasource[1] becomes PartitionUnion[7] with children[TableScan[1],TableScan[1]]", + assertReason: "DataSource_1 has multiple needed partitions[p1,p2] after pruning", + assertAction: "DataSource_1 becomes PartitionUnion_7 with children[TableScan_1,TableScan_1]", }, }, }, @@ -158,8 +158,8 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "partition_processor", assertRuleSteps: []assertTraceStep{ { - assertReason: "Datasource[1] has one needed partition[p1] after pruning", - assertAction: "Datasource[1] becomes TableScan[1]", + assertReason: "DataSource_1 has one needed partition[p1] after pruning", + assertAction: "DataSource_1 becomes TableScan_1", }, }, }, @@ -196,7 +196,7 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { }, { assertReason: "[test.t.a] is a unique key", - assertAction: "aggregation is simplified to a projection", + assertAction: "Aggregation_2 is simplified to a Projection_4", }, }, }, @@ -206,8 +206,8 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "projection_eliminate", assertRuleSteps: []assertTraceStep{ { - assertAction: "Proj[2] is eliminated, Proj[3]'s expressions changed into[plus(1, plus(1, test.t.a))]", - assertReason: "Proj[3]'s child proj[2] is redundant", + assertAction: "Projection_2 is eliminated, Projection_3's expressions changed into[plus(1, plus(1, test.t.a))]", + assertReason: "Projection_3's child Projection_2 is redundant", }, }, }, @@ -217,8 +217,8 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "aggregation_push_down", assertRuleSteps: []assertTraceStep{ { - assertAction: "agg[6] pushed down across join[5], and join right path becomes agg[8]", - assertReason: "agg[6]'s functions[count(Column#38)] are decomposable with join", + assertAction: "Aggregation_6 pushed down across Join_5, and Join_5 right path becomes Aggregation_8", + assertReason: "Aggregation_6's functions[count(Column#38)] are decomposable with join", }, }, }, @@ -228,16 +228,16 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "aggregation_push_down", assertRuleSteps: []assertTraceStep{ { - assertAction: "agg[8] pushed down, and union[5]'s children changed into[[id:11,tp:Aggregation],[id:12,tp:Aggregation]]", - assertReason: "agg[8] functions[sum(Column#28)] are decomposable with union", + assertAction: "Aggregation_8 pushed down, and Union_5's children changed into[Aggregation_11,Aggregation_12]", + assertReason: "Aggregation_8 functions[sum(Column#28)] are decomposable with Union_5", }, { - assertAction: "proj[6] is eliminated, and agg[11]'s functions changed into[sum(test.t.c),firstrow(test.t.d)]", - assertReason: "Proj[6] is directly below an agg[11] and has no side effects", + assertAction: "Projection_6 is eliminated, and Aggregation_11's functions changed into[sum(test.t.c),firstrow(test.t.d)]", + assertReason: "Projection_6 is directly below an Aggregation_11 and has no side effects", }, { - assertAction: "proj[7] is eliminated, and agg[12]'s functions changed into[sum(test.t.a),firstrow(test.t.b)]", - assertReason: "Proj[7] is directly below an agg[12] and has no side effects", + assertAction: "Projection_7 is eliminated, and Aggregation_12's functions changed into[sum(test.t.a),firstrow(test.t.b)]", + assertReason: "Projection_7 is directly below an Aggregation_12 and has no side effects", }, }, }, @@ -247,16 +247,16 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "max_min_eliminate", assertRuleSteps: []assertTraceStep{ { - assertAction: "add sort[8],add limit[9] during eliminating agg[4] max function", - assertReason: "agg[4] has only one function[max] without group by, the columns in agg[4] should be sorted", + assertAction: "add Sort_8,add Limit_9 during eliminating Aggregation_4 max function", + assertReason: "Aggregation_4 has only one function[max] without group by, the columns in Aggregation_4 should be sorted", }, { - assertAction: "add sort[10],add limit[11] during eliminating agg[6] min function", - assertReason: "agg[6] has only one function[min] without group by, the columns in agg[6] should be sorted", + assertAction: "add Sort_10,add Limit_11 during eliminating Aggregation_6 min function", + assertReason: "Aggregation_6 has only one function[min] without group by, the columns in Aggregation_6 should be sorted", }, { - assertAction: "agg[2] splited into aggs[4,6], and add joins[12] to connect them during eliminating agg[2] multi min/max functions", - assertReason: "each column is sorted and can benefit from index/primary key in agg[4,6] and none of them has group by clause", + assertAction: "Aggregation_2 splited into [Aggregation_4,Aggregation_6], and add [Join_12] to connect them during eliminating Aggregation_2 multi min/max functions", + assertReason: "each column is sorted and can benefit from index/primary key in [Aggregation_4,Aggregation_6] and none of them has group by clause", }, }, }, @@ -266,8 +266,8 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "max_min_eliminate", assertRuleSteps: []assertTraceStep{ { - assertAction: "add selection[4],add sort[5],add limit[6] during eliminating agg[2] max function", - assertReason: "agg[2] has only one function[max] without group by, the columns in agg[2] shouldn't be NULL and needs NULL to be filtered out, the columns in agg[2] should be sorted", + assertAction: "add Selection_4,add Sort_5,add Limit_6 during eliminating Aggregation_2 max function", + assertReason: "Aggregation_2 has only one function[max] without group by, the columns in Aggregation_2 shouldn't be NULL and needs NULL to be filtered out, the columns in Aggregation_2 should be sorted", }, }, }, @@ -277,7 +277,7 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "outer_join_eliminate", assertRuleSteps: []assertTraceStep{ { - assertAction: "Outer join[3] is eliminated and become DataSource[1]", + assertAction: "Outer Join_3 is eliminated and become DataSource_1", assertReason: "The columns[test.t.b,test.t.c] are from outer table, and the inner join keys[test.t.a] are unique", }, }, @@ -288,7 +288,7 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "outer_join_eliminate", assertRuleSteps: []assertTraceStep{ { - assertAction: "Outer join[3] is eliminated and become DataSource[1]", + assertAction: "Outer Join_3 is eliminated and become DataSource_1", assertReason: "The columns[test.t.a,test.t.b] in agg are from outer table, and the agg functions are duplicate agnostic", }, }, diff --git a/planner/core/optimizer.go b/planner/core/optimizer.go index 89b156e632cea..bed497aeb1ddd 100644 --- a/planner/core/optimizer.go +++ b/planner/core/optimizer.go @@ -107,7 +107,7 @@ func (op *logicalOptimizeOp) appendBeforeRuleOptimize(index int, name string, be if op.tracer == nil { return } - op.tracer.AppendRuleTracerBeforeRuleOptimize(index, name, before.buildLogicalPlanTrace(before)) + op.tracer.AppendRuleTracerBeforeRuleOptimize(index, name, before.buildLogicalPlanTrace()) } func (op *logicalOptimizeOp) appendStepToCurrent(id int, tp, reason, action string) { @@ -121,7 +121,7 @@ func (op *logicalOptimizeOp) recordFinalLogicalPlan(final LogicalPlan) { if op.tracer == nil { return } - op.tracer.RecordFinalLogicalPlan(final.buildLogicalPlanTrace(final)) + op.tracer.RecordFinalLogicalPlan(final.buildLogicalPlanTrace()) } // logicalOptRule means a logical optimizing rule, which contains decorrelate, ppd, column pruning, etc. diff --git a/planner/core/plan.go b/planner/core/plan.go index 3515f44e91750..2808235e11e13 100644 --- a/planner/core/plan.go +++ b/planner/core/plan.go @@ -308,7 +308,7 @@ type LogicalPlan interface { canPushToCop(store kv.StoreType) bool // buildLogicalPlanTrace clone necessary information from LogicalPlan - buildLogicalPlanTrace(p Plan) *tracing.LogicalPlanTrace + buildLogicalPlanTrace() *tracing.LogicalPlanTrace } // PhysicalPlan is a tree of the physical operators. @@ -382,10 +382,10 @@ func (p *baseLogicalPlan) ExplainInfo() string { } // buildLogicalPlanTrace implements LogicalPlan -func (p *baseLogicalPlan) buildLogicalPlanTrace(plan Plan) *tracing.LogicalPlanTrace { - planTrace := &tracing.LogicalPlanTrace{ID: p.ID(), TP: p.TP(), ExplainInfo: plan.ExplainInfo()} +func (p *baseLogicalPlan) buildLogicalPlanTrace() *tracing.LogicalPlanTrace { + planTrace := &tracing.LogicalPlanTrace{ID: p.ID(), TP: p.TP(), ExplainInfo: p.self.ExplainInfo()} for _, child := range p.Children() { - planTrace.Children = append(planTrace.Children, child.buildLogicalPlanTrace(child)) + planTrace.Children = append(planTrace.Children, child.buildLogicalPlanTrace()) } return planTrace } diff --git a/planner/core/rule_aggregation_elimination.go b/planner/core/rule_aggregation_elimination.go index 61d9e0f117e0d..b8713430003c6 100644 --- a/planner/core/rule_aggregation_elimination.go +++ b/planner/core/rule_aggregation_elimination.go @@ -67,7 +67,7 @@ func (a *aggregationEliminateChecker) tryToEliminateAggregation(agg *LogicalAggr // GroupByCols has unique key, so this aggregation can be removed. if ok, proj := ConvertAggToProj(agg, agg.schema); ok { proj.SetChildren(agg.children[0]) - appendAggregationEliminateTraceStep(agg, uniqueKey, opt) + appendAggregationEliminateTraceStep(agg, proj, uniqueKey, opt) return proj } } @@ -116,10 +116,10 @@ func (a *aggregationEliminateChecker) tryToEliminateDistinct(agg *LogicalAggrega } } -func appendAggregationEliminateTraceStep(agg *LogicalAggregation, uniqueKey expression.KeyInfo, opt *logicalOptimizeOp) { +func appendAggregationEliminateTraceStep(agg *LogicalAggregation, proj *LogicalProjection, uniqueKey expression.KeyInfo, opt *logicalOptimizeOp) { opt.appendStepToCurrent(agg.ID(), agg.TP(), fmt.Sprintf("%s is a unique key", uniqueKey.String()), - "aggregation is simplified to a projection") + fmt.Sprintf("%v_%v is simplified to a %v_%v", agg.TP(), agg.ID(), proj.TP(), proj.ID())) } func appendDistinctEliminateTraceStep(agg *LogicalAggregation, uniqueKey expression.KeyInfo, af *aggregation.AggFuncDesc, diff --git a/planner/core/rule_aggregation_push_down.go b/planner/core/rule_aggregation_push_down.go index 7cc0548a7f57d..1fab424173f95 100644 --- a/planner/core/rule_aggregation_push_down.go +++ b/planner/core/rule_aggregation_push_down.go @@ -517,7 +517,7 @@ func (*aggregationPushDownSolver) name() string { func appendAggPushDownAcrossJoinTraceStep(oldAgg, newAgg *LogicalAggregation, aggFuncs []*aggregation.AggFuncDesc, join *LogicalJoin, childIdx int, opt *logicalOptimizeOp) { reason := func() string { - buffer := bytes.NewBufferString(fmt.Sprintf("agg[%v]'s functions[", oldAgg.ID())) + buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v's functions[", oldAgg.TP(), oldAgg.ID())) for i, aggFunc := range aggFuncs { if i > 0 { buffer.WriteString(",") @@ -528,13 +528,13 @@ func appendAggPushDownAcrossJoinTraceStep(oldAgg, newAgg *LogicalAggregation, ag return buffer.String() }() action := func() string { - buffer := bytes.NewBufferString(fmt.Sprintf("agg[%v] pushed down across join[%v], ", oldAgg.ID(), join.ID())) - buffer.WriteString(fmt.Sprintf("and join %v path becomes agg[%v]", func() string { + buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v pushed down across %v_%v, ", oldAgg.TP(), oldAgg.ID(), join.TP(), join.ID())) + buffer.WriteString(fmt.Sprintf("and %v_%v %v path becomes %v_%v", join.TP(), join.ID(), func() string { if childIdx == 0 { return "left" } return "right" - }(), newAgg.ID())) + }(), newAgg.TP(), newAgg.ID())) return buffer.String() }() opt.appendStepToCurrent(join.ID(), join.TP(), reason, action) @@ -542,7 +542,7 @@ func appendAggPushDownAcrossJoinTraceStep(oldAgg, newAgg *LogicalAggregation, ag func appendAggPushDownAcrossProjTraceStep(agg *LogicalAggregation, proj *LogicalProjection, opt *logicalOptimizeOp) { action := func() string { - buffer := bytes.NewBufferString(fmt.Sprintf("proj[%v] is eliminated, and agg[%v]'s functions changed into[", proj.ID(), agg.ID())) + buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v is eliminated, and %v_%v's functions changed into[", proj.TP(), proj.ID(), agg.TP(), agg.ID())) for i, aggFunc := range agg.AggFuncs { if i > 0 { buffer.WriteString(",") @@ -552,29 +552,29 @@ func appendAggPushDownAcrossProjTraceStep(agg *LogicalAggregation, proj *Logical buffer.WriteString("]") return buffer.String() }() - reason := fmt.Sprintf("Proj[%v] is directly below an agg[%v] and has no side effects", proj.ID(), agg.ID()) + reason := fmt.Sprintf("%v_%v is directly below an %v_%v and has no side effects", proj.TP(), proj.ID(), agg.TP(), agg.ID()) opt.appendStepToCurrent(agg.ID(), agg.TP(), reason, action) } func appendAggPushDownAcrossUnionTraceStep(union *LogicalUnionAll, agg *LogicalAggregation, opt *logicalOptimizeOp) { reason := func() string { - buffer := bytes.NewBufferString(fmt.Sprintf("agg[%v] functions[", agg.ID())) + buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v functions[", agg.TP(), agg.ID())) for i, aggFunc := range agg.AggFuncs { if i > 0 { buffer.WriteString(",") } buffer.WriteString(aggFunc.String()) } - buffer.WriteString("] are decomposable with union") + buffer.WriteString(fmt.Sprintf("] are decomposable with %v_%v", union.TP(), union.ID())) return buffer.String() }() action := func() string { - buffer := bytes.NewBufferString(fmt.Sprintf("agg[%v] pushed down, and union[%v]'s children changed into[", agg.ID(), union.ID())) + buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v pushed down, and %v_%v's children changed into[", agg.TP(), agg.ID(), union.TP(), union.ID())) for i, child := range union.Children() { if i > 0 { buffer.WriteString(",") } - buffer.WriteString(fmt.Sprintf("[id:%v,tp:%s]", child.ID(), child.TP())) + buffer.WriteString(fmt.Sprintf("%v_%v", child.TP(), child.ID())) } buffer.WriteString("]") return buffer.String() diff --git a/planner/core/rule_eliminate_projection.go b/planner/core/rule_eliminate_projection.go index 0c377bd974703..7384779a1105f 100644 --- a/planner/core/rule_eliminate_projection.go +++ b/planner/core/rule_eliminate_projection.go @@ -300,7 +300,7 @@ func (*projectionEliminator) name() string { func appendDupProjEliminateTraceStep(parent, child *LogicalProjection, opt *logicalOptimizeOp) { action := func() string { buffer := bytes.NewBufferString( - fmt.Sprintf("Proj[%v] is eliminated, Proj[%v]'s expressions changed into[", child.ID(), parent.ID())) + fmt.Sprintf("%v_%v is eliminated, %v_%v's expressions changed into[", child.TP(), child.ID(), parent.TP(), parent.ID())) for i, expr := range parent.Exprs { if i > 0 { buffer.WriteString(",") @@ -310,12 +310,12 @@ func appendDupProjEliminateTraceStep(parent, child *LogicalProjection, opt *logi buffer.WriteString("]") return buffer.String() }() - reason := fmt.Sprintf("Proj[%v]'s child proj[%v] is redundant", parent.ID(), child.ID()) + reason := fmt.Sprintf("%v_%v's child %v_%v is redundant", parent.TP(), parent.ID(), child.TP(), child.ID()) opt.appendStepToCurrent(child.ID(), child.TP(), reason, action) } func appendProjEliminateTraceStep(proj *LogicalProjection, opt *logicalOptimizeOp) { - reason := fmt.Sprintf("Proj[%v]'s Exprs are all Columns", proj.ID()) - action := fmt.Sprintf("Proj[%v] is eliminated", proj.ID()) + reason := fmt.Sprintf("%v_%v's Exprs are all Columns", proj.TP(), proj.ID()) + action := fmt.Sprintf("%v_%v is eliminated", proj.TP(), proj.ID()) opt.appendStepToCurrent(proj.ID(), proj.TP(), reason, action) } diff --git a/planner/core/rule_join_elimination.go b/planner/core/rule_join_elimination.go index 6d4a750ea4356..f8cb166c1e80f 100644 --- a/planner/core/rule_join_elimination.go +++ b/planner/core/rule_join_elimination.go @@ -259,7 +259,7 @@ func appendOuterJoinEliminateTraceStep(join *LogicalJoin, outerPlan LogicalPlan, buffer.WriteString("] are unique") return buffer.String() }() - action := fmt.Sprintf("Outer join[%v] is eliminated and become %v[%v]", join.ID(), outerPlan.TP(), outerPlan.ID()) + action := fmt.Sprintf("Outer %v_%v is eliminated and become %v_%v", join.TP(), join.ID(), outerPlan.TP(), outerPlan.ID()) opt.appendStepToCurrent(join.ID(), join.TP(), reason, action) } @@ -275,6 +275,6 @@ func appendOuterJoinEliminateAggregationTraceStep(join *LogicalJoin, outerPlan L buffer.WriteString("] in agg are from outer table, and the agg functions are duplicate agnostic") return buffer.String() }() - action := fmt.Sprintf("Outer join[%v] is eliminated and become %v[%v]", join.ID(), outerPlan.TP(), outerPlan.ID()) + action := fmt.Sprintf("Outer %v_%v is eliminated and become %v_%v", join.TP(), join.ID(), outerPlan.TP(), outerPlan.ID()) opt.appendStepToCurrent(join.ID(), join.TP(), reason, action) } diff --git a/planner/core/rule_join_reorder.go b/planner/core/rule_join_reorder.go index dd29f7d3f1f30..10e60519c4435 100644 --- a/planner/core/rule_join_reorder.go +++ b/planner/core/rule_join_reorder.go @@ -323,16 +323,16 @@ func (t *joinReorderTrace) traceJoinReorder(p LogicalPlan) { return } if len(t.initial) > 0 { - t.final = allJoinOrderToString(extractJoinAndDataSource(p.buildLogicalPlanTrace(p))) + t.final = allJoinOrderToString(extractJoinAndDataSource(p.buildLogicalPlanTrace())) return } - t.initial = allJoinOrderToString(extractJoinAndDataSource(p.buildLogicalPlanTrace(p))) + t.initial = allJoinOrderToString(extractJoinAndDataSource(p.buildLogicalPlanTrace())) } func (t *joinReorderTrace) appendLogicalJoinCost(join LogicalPlan, cost float64) { if t == nil || t.opt == nil || t.opt.tracer == nil { return } - joinMapKey := allJoinOrderToString(extractJoinAndDataSource(join.buildLogicalPlanTrace(join))) + joinMapKey := allJoinOrderToString(extractJoinAndDataSource(join.buildLogicalPlanTrace())) t.cost[joinMapKey] = cost } diff --git a/planner/core/rule_max_min_eliminate.go b/planner/core/rule_max_min_eliminate.go index 858f9005c2273..a00b4b3dd0244 100644 --- a/planner/core/rule_max_min_eliminate.go +++ b/planner/core/rule_max_min_eliminate.go @@ -254,21 +254,21 @@ func appendEliminateSingleMaxMinTrace(agg *LogicalAggregation, sel *LogicalSelec action := func() string { buffer := bytes.NewBufferString("") if sel != nil { - buffer.WriteString(fmt.Sprintf("add selection[%v],", sel.ID())) + buffer.WriteString(fmt.Sprintf("add %v_%v,", sel.TP(), sel.ID())) } if sort != nil { - buffer.WriteString(fmt.Sprintf("add sort[%v],", sort.ID())) + buffer.WriteString(fmt.Sprintf("add %v_%v,", sort.TP(), sort.ID())) } - buffer.WriteString(fmt.Sprintf("add limit[%v] during eliminating agg[%v] %s function", limit.ID(), agg.ID(), agg.AggFuncs[0].Name)) + buffer.WriteString(fmt.Sprintf("add %v_%v during eliminating %v_%v %s function", limit.TP(), limit.ID(), agg.TP(), agg.ID(), agg.AggFuncs[0].Name)) return buffer.String() }() reason := func() string { - buffer := bytes.NewBufferString(fmt.Sprintf("agg[%v] has only one function[%s] without group by", agg.ID(), agg.AggFuncs[0].Name)) + buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v has only one function[%s] without group by", agg.TP(), agg.ID(), agg.AggFuncs[0].Name)) if sel != nil { - buffer.WriteString(fmt.Sprintf(", the columns in agg[%v] shouldn't be NULL and needs NULL to be filtered out", agg.ID())) + buffer.WriteString(fmt.Sprintf(", the columns in %v_%v shouldn't be NULL and needs NULL to be filtered out", agg.TP(), agg.ID())) } if sort != nil { - buffer.WriteString(fmt.Sprintf(", the columns in agg[%v] should be sorted", agg.ID())) + buffer.WriteString(fmt.Sprintf(", the columns in %v_%v should be sorted", agg.TP(), agg.ID())) } return buffer.String() }() @@ -277,30 +277,30 @@ func appendEliminateSingleMaxMinTrace(agg *LogicalAggregation, sel *LogicalSelec func appendEliminateMultiMinMaxTraceStep(originAgg *LogicalAggregation, aggs []*LogicalAggregation, joins []*LogicalJoin, opt *logicalOptimizeOp) { action := func() string { - buffer := bytes.NewBufferString(fmt.Sprintf("agg[%v] splited into aggs[", originAgg.ID())) + buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v splited into [", originAgg.TP(), originAgg.ID())) for i, agg := range aggs { if i > 0 { buffer.WriteString(",") } - buffer.WriteString(fmt.Sprintf("%v", agg.ID())) + buffer.WriteString(fmt.Sprintf("%v_%v", agg.TP(), agg.ID())) } - buffer.WriteString("], and add joins[") + buffer.WriteString("], and add [") for i, join := range joins { if i > 0 { buffer.WriteString(",") } - buffer.WriteString(fmt.Sprintf("%v", join.ID())) + buffer.WriteString(fmt.Sprintf("%v_%v", join.TP(), join.ID())) } - buffer.WriteString(fmt.Sprintf("] to connect them during eliminating agg[%v] multi min/max functions", originAgg.ID())) + buffer.WriteString(fmt.Sprintf("] to connect them during eliminating %v_%v multi min/max functions", originAgg.TP(), originAgg.ID())) return buffer.String() }() reason := func() string { - buffer := bytes.NewBufferString("each column is sorted and can benefit from index/primary key in agg[") + buffer := bytes.NewBufferString("each column is sorted and can benefit from index/primary key in [") for i, agg := range aggs { if i > 0 { buffer.WriteString(",") } - buffer.WriteString(fmt.Sprintf("%v", agg.ID())) + buffer.WriteString(fmt.Sprintf("%v_%v", agg.TP(), agg.ID())) } buffer.WriteString("] and none of them has group by clause") return buffer.String() diff --git a/planner/core/rule_partition_processor.go b/planner/core/rule_partition_processor.go index 04f572200232b..6a0b6ef7de4b6 100644 --- a/planner/core/rule_partition_processor.go +++ b/planner/core/rule_partition_processor.go @@ -1590,22 +1590,22 @@ func appendMakeUnionAllChildrenTranceStep(ds *DataSource, usedMap map[int64]mode return used[i].ID < used[j].ID }) if len(children) == 1 { - action = fmt.Sprintf("Datasource[%v] becomes %s[%v]", ds.ID(), plan.TP(), plan.ID()) - reason = fmt.Sprintf("Datasource[%v] has one needed partition[%s] after pruning", ds.ID(), used[0].Name) + action = fmt.Sprintf("%v_%v becomes %s_%v", ds.TP(), ds.ID(), plan.TP(), plan.ID()) + reason = fmt.Sprintf("%v_%v has one needed partition[%s] after pruning", ds.TP(), ds.ID(), used[0].Name) } else { action = func() string { - buffer := bytes.NewBufferString(fmt.Sprintf("Datasource[%v] becomes %s[%v] with children[", ds.ID(), plan.TP(), plan.ID())) + buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v becomes %s_%v with children[", ds.TP(), ds.ID(), plan.TP(), plan.ID())) for i, child := range children { if i > 0 { buffer.WriteString(",") } - buffer.WriteString(fmt.Sprintf("%s[%v]", child.TP(), child.ID())) + buffer.WriteString(fmt.Sprintf("%s_%v", child.TP(), child.ID())) } buffer.WriteString("]") return buffer.String() }() reason = func() string { - buffer := bytes.NewBufferString(fmt.Sprintf("Datasource[%v] has multiple needed partitions[", ds.ID())) + buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v has multiple needed partitions[", ds.TP(), ds.ID())) for i, u := range used { if i > 0 { buffer.WriteString(",") @@ -1620,7 +1620,7 @@ func appendMakeUnionAllChildrenTranceStep(ds *DataSource, usedMap map[int64]mode } func appendNoPartitionChildTraceStep(ds *DataSource, dual LogicalPlan, opt *logicalOptimizeOp) { - action := fmt.Sprintf("Datasource[%v] becomes %v[%v]", ds.ID(), dual.TP(), dual.ID()) - reason := fmt.Sprintf("Datasource[%v] doesn't have needed partition table after pruning", ds.ID()) + action := fmt.Sprintf("%v_%v becomes %v_%v", ds.TP(), ds.ID(), dual.TP(), dual.ID()) + reason := fmt.Sprintf("%v_%v doesn't have needed partition table after pruning", ds.TP(), ds.ID()) opt.appendStepToCurrent(dual.ID(), dual.TP(), reason, action) } From f26b1407947096e543e4febd9af3933ee141c7cf Mon Sep 17 00:00:00 2001 From: yisaer Date: Tue, 21 Dec 2021 12:29:00 +0800 Subject: [PATCH 2/4] lazy initial output Signed-off-by: yisaer --- planner/core/optimizer.go | 4 +-- planner/core/rule_aggregation_elimination.go | 21 ++++++++++----- planner/core/rule_aggregation_push_down.go | 14 +++++----- planner/core/rule_eliminate_projection.go | 14 +++++++--- planner/core/rule_join_elimination.go | 12 ++++++--- planner/core/rule_join_reorder.go | 6 +++-- planner/core/rule_max_min_eliminate.go | 8 +++--- planner/core/rule_partition_processor.go | 28 ++++++++++++++------ 8 files changed, 71 insertions(+), 36 deletions(-) diff --git a/planner/core/optimizer.go b/planner/core/optimizer.go index bed497aeb1ddd..36ef3b376bf55 100644 --- a/planner/core/optimizer.go +++ b/planner/core/optimizer.go @@ -110,11 +110,11 @@ func (op *logicalOptimizeOp) appendBeforeRuleOptimize(index int, name string, be op.tracer.AppendRuleTracerBeforeRuleOptimize(index, name, before.buildLogicalPlanTrace()) } -func (op *logicalOptimizeOp) appendStepToCurrent(id int, tp, reason, action string) { +func (op *logicalOptimizeOp) appendStepToCurrent(id int, tp string, reason, action func() string) { if op.tracer == nil { return } - op.tracer.AppendRuleTracerStepToCurrent(id, tp, reason, action) + op.tracer.AppendRuleTracerStepToCurrent(id, tp, reason(), action()) } func (op *logicalOptimizeOp) recordFinalLogicalPlan(final LogicalPlan) { diff --git a/planner/core/rule_aggregation_elimination.go b/planner/core/rule_aggregation_elimination.go index b8713430003c6..9adca6936099d 100644 --- a/planner/core/rule_aggregation_elimination.go +++ b/planner/core/rule_aggregation_elimination.go @@ -117,16 +117,25 @@ func (a *aggregationEliminateChecker) tryToEliminateDistinct(agg *LogicalAggrega } func appendAggregationEliminateTraceStep(agg *LogicalAggregation, proj *LogicalProjection, uniqueKey expression.KeyInfo, opt *logicalOptimizeOp) { - opt.appendStepToCurrent(agg.ID(), agg.TP(), - fmt.Sprintf("%s is a unique key", uniqueKey.String()), - fmt.Sprintf("%v_%v is simplified to a %v_%v", agg.TP(), agg.ID(), proj.TP(), proj.ID())) + reason := func() string { + return fmt.Sprintf("%s is a unique key", uniqueKey.String()) + } + action := func() string { + return fmt.Sprintf("%v_%v is simplified to a %v_%v", agg.TP(), agg.ID(), proj.TP(), proj.ID()) + } + + opt.appendStepToCurrent(agg.ID(), agg.TP(), reason, action) } func appendDistinctEliminateTraceStep(agg *LogicalAggregation, uniqueKey expression.KeyInfo, af *aggregation.AggFuncDesc, opt *logicalOptimizeOp) { - opt.appendStepToCurrent(agg.ID(), agg.TP(), - fmt.Sprintf("%s is a unique key", uniqueKey.String()), - fmt.Sprintf("%s(distinct ...) is simplified to %s(...)", af.Name, af.Name)) + reason := func() string { + return fmt.Sprintf("%s is a unique key", uniqueKey.String()) + } + action := func() string { + return fmt.Sprintf("%s(distinct ...) is simplified to %s(...)", af.Name, af.Name) + } + opt.appendStepToCurrent(agg.ID(), agg.TP(), reason, action) } // ConvertAggToProj convert aggregation to projection. diff --git a/planner/core/rule_aggregation_push_down.go b/planner/core/rule_aggregation_push_down.go index 1fab424173f95..5f927befb8ee3 100644 --- a/planner/core/rule_aggregation_push_down.go +++ b/planner/core/rule_aggregation_push_down.go @@ -526,7 +526,7 @@ func appendAggPushDownAcrossJoinTraceStep(oldAgg, newAgg *LogicalAggregation, ag } buffer.WriteString("] are decomposable with join") return buffer.String() - }() + } action := func() string { buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v pushed down across %v_%v, ", oldAgg.TP(), oldAgg.ID(), join.TP(), join.ID())) buffer.WriteString(fmt.Sprintf("and %v_%v %v path becomes %v_%v", join.TP(), join.ID(), func() string { @@ -536,7 +536,7 @@ func appendAggPushDownAcrossJoinTraceStep(oldAgg, newAgg *LogicalAggregation, ag return "right" }(), newAgg.TP(), newAgg.ID())) return buffer.String() - }() + } opt.appendStepToCurrent(join.ID(), join.TP(), reason, action) } @@ -551,8 +551,10 @@ func appendAggPushDownAcrossProjTraceStep(agg *LogicalAggregation, proj *Logical } buffer.WriteString("]") return buffer.String() - }() - reason := fmt.Sprintf("%v_%v is directly below an %v_%v and has no side effects", proj.TP(), proj.ID(), agg.TP(), agg.ID()) + } + reason := func() string { + return fmt.Sprintf("%v_%v is directly below an %v_%v and has no side effects", proj.TP(), proj.ID(), agg.TP(), agg.ID()) + } opt.appendStepToCurrent(agg.ID(), agg.TP(), reason, action) } @@ -567,7 +569,7 @@ func appendAggPushDownAcrossUnionTraceStep(union *LogicalUnionAll, agg *LogicalA } buffer.WriteString(fmt.Sprintf("] are decomposable with %v_%v", union.TP(), union.ID())) return buffer.String() - }() + } action := func() string { buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v pushed down, and %v_%v's children changed into[", agg.TP(), agg.ID(), union.TP(), union.ID())) for i, child := range union.Children() { @@ -578,6 +580,6 @@ func appendAggPushDownAcrossUnionTraceStep(union *LogicalUnionAll, agg *LogicalA } buffer.WriteString("]") return buffer.String() - }() + } opt.appendStepToCurrent(union.ID(), union.TP(), reason, action) } diff --git a/planner/core/rule_eliminate_projection.go b/planner/core/rule_eliminate_projection.go index 7384779a1105f..0daaf4616185a 100644 --- a/planner/core/rule_eliminate_projection.go +++ b/planner/core/rule_eliminate_projection.go @@ -309,13 +309,19 @@ func appendDupProjEliminateTraceStep(parent, child *LogicalProjection, opt *logi } buffer.WriteString("]") return buffer.String() - }() - reason := fmt.Sprintf("%v_%v's child %v_%v is redundant", parent.TP(), parent.ID(), child.TP(), child.ID()) + } + reason := func() string { + return fmt.Sprintf("%v_%v's child %v_%v is redundant", parent.TP(), parent.ID(), child.TP(), child.ID()) + } opt.appendStepToCurrent(child.ID(), child.TP(), reason, action) } func appendProjEliminateTraceStep(proj *LogicalProjection, opt *logicalOptimizeOp) { - reason := fmt.Sprintf("%v_%v's Exprs are all Columns", proj.TP(), proj.ID()) - action := fmt.Sprintf("%v_%v is eliminated", proj.TP(), proj.ID()) + reason := func() string { + return fmt.Sprintf("%v_%v's Exprs are all Columns", proj.TP(), proj.ID()) + } + action := func() string { + return fmt.Sprintf("%v_%v is eliminated", proj.TP(), proj.ID()) + } opt.appendStepToCurrent(proj.ID(), proj.TP(), reason, action) } diff --git a/planner/core/rule_join_elimination.go b/planner/core/rule_join_elimination.go index f8cb166c1e80f..c7ed935b8dc99 100644 --- a/planner/core/rule_join_elimination.go +++ b/planner/core/rule_join_elimination.go @@ -258,8 +258,10 @@ func appendOuterJoinEliminateTraceStep(join *LogicalJoin, outerPlan LogicalPlan, } buffer.WriteString("] are unique") return buffer.String() - }() - action := fmt.Sprintf("Outer %v_%v is eliminated and become %v_%v", join.TP(), join.ID(), outerPlan.TP(), outerPlan.ID()) + } + action := func() string { + return fmt.Sprintf("Outer %v_%v is eliminated and become %v_%v", join.TP(), join.ID(), outerPlan.TP(), outerPlan.ID()) + } opt.appendStepToCurrent(join.ID(), join.TP(), reason, action) } @@ -274,7 +276,9 @@ func appendOuterJoinEliminateAggregationTraceStep(join *LogicalJoin, outerPlan L } buffer.WriteString("] in agg are from outer table, and the agg functions are duplicate agnostic") return buffer.String() - }() - action := fmt.Sprintf("Outer %v_%v is eliminated and become %v_%v", join.TP(), join.ID(), outerPlan.TP(), outerPlan.ID()) + } + action := func() string { + return fmt.Sprintf("Outer %v_%v is eliminated and become %v_%v", join.TP(), join.ID(), outerPlan.TP(), outerPlan.ID()) + } opt.appendStepToCurrent(join.ID(), join.TP(), reason, action) } diff --git a/planner/core/rule_join_reorder.go b/planner/core/rule_join_reorder.go index 10e60519c4435..e1ff17d70fd98 100644 --- a/planner/core/rule_join_reorder.go +++ b/planner/core/rule_join_reorder.go @@ -209,7 +209,9 @@ func appendJoinReorderTraceStep(tracer *joinReorderTrace, plan LogicalPlan, opt if len(tracer.initial) < 1 || len(tracer.final) < 1 { return } - action := fmt.Sprintf("join order becomes %v from original %v", tracer.final, tracer.initial) + action := func() string { + return fmt.Sprintf("join order becomes %v from original %v", tracer.final, tracer.initial) + } reason := func() string { buffer := bytes.NewBufferString("join cost during reorder: [") var joins []string @@ -225,7 +227,7 @@ func appendJoinReorderTraceStep(tracer *joinReorderTrace, plan LogicalPlan, opt } buffer.WriteString("]") return buffer.String() - }() + } opt.appendStepToCurrent(plan.ID(), plan.TP(), reason, action) } diff --git a/planner/core/rule_max_min_eliminate.go b/planner/core/rule_max_min_eliminate.go index a00b4b3dd0244..20d6fdba2857f 100644 --- a/planner/core/rule_max_min_eliminate.go +++ b/planner/core/rule_max_min_eliminate.go @@ -261,7 +261,7 @@ func appendEliminateSingleMaxMinTrace(agg *LogicalAggregation, sel *LogicalSelec } buffer.WriteString(fmt.Sprintf("add %v_%v during eliminating %v_%v %s function", limit.TP(), limit.ID(), agg.TP(), agg.ID(), agg.AggFuncs[0].Name)) return buffer.String() - }() + } reason := func() string { buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v has only one function[%s] without group by", agg.TP(), agg.ID(), agg.AggFuncs[0].Name)) if sel != nil { @@ -271,7 +271,7 @@ func appendEliminateSingleMaxMinTrace(agg *LogicalAggregation, sel *LogicalSelec buffer.WriteString(fmt.Sprintf(", the columns in %v_%v should be sorted", agg.TP(), agg.ID())) } return buffer.String() - }() + } opt.appendStepToCurrent(agg.ID(), agg.TP(), reason, action) } @@ -293,7 +293,7 @@ func appendEliminateMultiMinMaxTraceStep(originAgg *LogicalAggregation, aggs []* } buffer.WriteString(fmt.Sprintf("] to connect them during eliminating %v_%v multi min/max functions", originAgg.TP(), originAgg.ID())) return buffer.String() - }() + } reason := func() string { buffer := bytes.NewBufferString("each column is sorted and can benefit from index/primary key in [") for i, agg := range aggs { @@ -304,6 +304,6 @@ func appendEliminateMultiMinMaxTraceStep(originAgg *LogicalAggregation, aggs []* } buffer.WriteString("] and none of them has group by clause") return buffer.String() - }() + } opt.appendStepToCurrent(originAgg.ID(), originAgg.TP(), reason, action) } diff --git a/planner/core/rule_partition_processor.go b/planner/core/rule_partition_processor.go index 6a0b6ef7de4b6..20a571b289397 100644 --- a/planner/core/rule_partition_processor.go +++ b/planner/core/rule_partition_processor.go @@ -1580,8 +1580,12 @@ func appendMakeUnionAllChildrenTranceStep(ds *DataSource, usedMap map[int64]mode appendNoPartitionChildTraceStep(ds, plan, opt) return } - action := "" - reason := "" + action := func() string { + return "" + } + reason := func() string { + return "" + } var used []model.PartitionDefinition for _, def := range usedMap { used = append(used, def) @@ -1590,8 +1594,12 @@ func appendMakeUnionAllChildrenTranceStep(ds *DataSource, usedMap map[int64]mode return used[i].ID < used[j].ID }) if len(children) == 1 { - action = fmt.Sprintf("%v_%v becomes %s_%v", ds.TP(), ds.ID(), plan.TP(), plan.ID()) - reason = fmt.Sprintf("%v_%v has one needed partition[%s] after pruning", ds.TP(), ds.ID(), used[0].Name) + action = func() string { + return fmt.Sprintf("%v_%v becomes %s_%v", ds.TP(), ds.ID(), plan.TP(), plan.ID()) + } + reason = func() string { + return fmt.Sprintf("%v_%v has one needed partition[%s] after pruning", ds.TP(), ds.ID(), used[0].Name) + } } else { action = func() string { buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v becomes %s_%v with children[", ds.TP(), ds.ID(), plan.TP(), plan.ID())) @@ -1603,7 +1611,7 @@ func appendMakeUnionAllChildrenTranceStep(ds *DataSource, usedMap map[int64]mode } buffer.WriteString("]") return buffer.String() - }() + } reason = func() string { buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v has multiple needed partitions[", ds.TP(), ds.ID())) for i, u := range used { @@ -1614,13 +1622,17 @@ func appendMakeUnionAllChildrenTranceStep(ds *DataSource, usedMap map[int64]mode } buffer.WriteString("] after pruning") return buffer.String() - }() + } } opt.appendStepToCurrent(ds.ID(), ds.TP(), reason, action) } func appendNoPartitionChildTraceStep(ds *DataSource, dual LogicalPlan, opt *logicalOptimizeOp) { - action := fmt.Sprintf("%v_%v becomes %v_%v", ds.TP(), ds.ID(), dual.TP(), dual.ID()) - reason := fmt.Sprintf("%v_%v doesn't have needed partition table after pruning", ds.TP(), ds.ID()) + action := func() string { + return fmt.Sprintf("%v_%v becomes %v_%v", ds.TP(), ds.ID(), dual.TP(), dual.ID()) + } + reason := func() string { + return fmt.Sprintf("%v_%v doesn't have needed partition table after pruning", ds.TP(), ds.ID()) + } opt.appendStepToCurrent(dual.ID(), dual.TP(), reason, action) } From 0643dd885a628cf563e0c4db15a1c0436a7f69aa Mon Sep 17 00:00:00 2001 From: yisaer Date: Tue, 21 Dec 2021 13:53:32 +0800 Subject: [PATCH 3/4] fix conflict Signed-off-by: yisaer --- planner/core/rule_topn_push_down.go | 45 ++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/planner/core/rule_topn_push_down.go b/planner/core/rule_topn_push_down.go index 73ed5749bc57c..ecbb30a9cb17b 100644 --- a/planner/core/rule_topn_push_down.go +++ b/planner/core/rule_topn_push_down.go @@ -87,8 +87,7 @@ func (ls *LogicalSort) pushDownTopN(topN *LogicalTopN, opt *logicalOptimizeOp) L func (p *LogicalLimit) convertToTopN(opt *logicalOptimizeOp) *LogicalTopN { topn := LogicalTopN{Offset: p.Offset, Count: p.Count, limitHints: p.limitHints}.Init(p.ctx, p.blockOffset) - opt.appendStepToCurrent(topn.ID(), topn.TP(), "", fmt.Sprintf("%v_%v is converted into %v_%v", - p.TP(), p.ID(), topn.TP(), topn.ID())) + appendConvertTopNTraceStep(p, topn, opt) return topn } @@ -109,9 +108,7 @@ func (p *LogicalUnionAll) pushDownTopN(topN *LogicalTopN, opt *logicalOptimizeOp newTopN.ByItems = append(newTopN.ByItems, &util.ByItems{Expr: by.Expr, Desc: by.Desc}) } // newTopN to push down Union's child - opt.appendStepToCurrent(newTopN.ID(), newTopN.TP(), "", - fmt.Sprintf("%v_%v is added and pushed down across %v_%v", - newTopN.TP(), newTopN.ID(), p.TP(), p.ID())) + appendNewTopNTraceStep(topN, p, opt) } p.children[i] = child.pushDownTopN(newTopN, opt) } @@ -202,8 +199,12 @@ func (*pushDownTopNOptimizer) name() string { } func appendTopNPushDownTraceStep(parent LogicalPlan, child LogicalPlan, opt *logicalOptimizeOp) { - action := fmt.Sprintf("%v_%v is added as %v_%v's parent", parent.TP(), parent.ID(), child.TP(), child.ID()) - reason := fmt.Sprintf("%v is pushed down", parent.TP()) + action := func() string { + return fmt.Sprintf("%v_%v is added as %v_%v's parent", parent.TP(), parent.ID(), child.TP(), child.ID()) + } + reason := func() string { + return fmt.Sprintf("%v is pushed down", parent.TP()) + } opt.appendStepToCurrent(parent.ID(), parent.TP(), reason, action) } @@ -218,7 +219,7 @@ func appendTopNPushDownJoinTraceStep(p *LogicalJoin, topN *LogicalTopN, idx int, } buffer.WriteString("table") return buffer.String() - }() + } reason := func() string { buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v's joinType is %v, and all ByItems[", p.TP(), p.ID(), p.JoinType.String())) for i, item := range topN.ByItems { @@ -235,7 +236,7 @@ func appendTopNPushDownJoinTraceStep(p *LogicalJoin, topN *LogicalTopN, idx int, } buffer.WriteString("table") return buffer.String() - }() + } opt.appendStepToCurrent(p.ID(), p.TP(), reason, action) } @@ -250,7 +251,29 @@ func appendSortPassByItemsTraceStep(sort *LogicalSort, topN *LogicalTopN, opt *l } buffer.WriteString(fmt.Sprintf("] to %v_%v", topN.TP(), topN.ID())) return buffer.String() - }() - reason := fmt.Sprintf("%v_%v is Limit originally", topN.TP(), topN.ID()) + } + reason := func() string { + return fmt.Sprintf("%v_%v is Limit originally", topN.TP(), topN.ID()) + } opt.appendStepToCurrent(sort.ID(), sort.TP(), reason, action) } + +func appendNewTopNTraceStep(topN *LogicalTopN, union *LogicalUnionAll, opt *logicalOptimizeOp) { + reason := func() string { + return "" + } + action := func() string { + return fmt.Sprintf("%v_%v is added and pushed down across %v_%v", topN.TP(), topN.ID(), union.TP(), union.ID()) + } + opt.appendStepToCurrent(topN.ID(), topN.TP(), reason, action) +} + +func appendConvertTopNTraceStep(p LogicalPlan, topN *LogicalTopN, opt *logicalOptimizeOp) { + reason := func() string { + return "" + } + action := func() string { + return fmt.Sprintf("%v_%v is converted into %v_%v", p.TP(), p.ID(), topN.TP(), topN.ID()) + } + opt.appendStepToCurrent(topN.ID(), topN.TP(), reason, action) +} From e01b15342f4e9f8a36a779462ce2b93704312aba Mon Sep 17 00:00:00 2001 From: yisaer Date: Tue, 21 Dec 2021 14:13:18 +0800 Subject: [PATCH 4/4] fix lint Signed-off-by: yisaer --- planner/core/rule_partition_processor.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/planner/core/rule_partition_processor.go b/planner/core/rule_partition_processor.go index 20a571b289397..53a655c5ed932 100644 --- a/planner/core/rule_partition_processor.go +++ b/planner/core/rule_partition_processor.go @@ -1580,12 +1580,7 @@ func appendMakeUnionAllChildrenTranceStep(ds *DataSource, usedMap map[int64]mode appendNoPartitionChildTraceStep(ds, plan, opt) return } - action := func() string { - return "" - } - reason := func() string { - return "" - } + var action, reason func() string var used []model.PartitionDefinition for _, def := range usedMap { used = append(used, def)