From 2708108fcd885872b19b33573d33aba3ead7fa1a Mon Sep 17 00:00:00 2001 From: yisaer Date: Mon, 20 Dec 2021 14:04:59 +0800 Subject: [PATCH] add testcase Signed-off-by: yisaer --- planner/core/logical_plan_trace_test.go | 26 ++++++++++++------------- planner/core/rule_topn_push_down.go | 16 +++++++-------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/planner/core/logical_plan_trace_test.go b/planner/core/logical_plan_trace_test.go index 700b60b026aad..0d4577bc1f107 100644 --- a/planner/core/logical_plan_trace_test.go +++ b/planner/core/logical_plan_trace_test.go @@ -92,23 +92,23 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "topn_push_down", assertRuleSteps: []assertTraceStep{ { - assertAction: "Limit[6] is converted into TopN[7]", - assertReason: "Limit can be converted into TopN", + assertAction: "Limit_6 is converted into TopN_7", + assertReason: "", }, { - assertAction: "Sort[5] passes ByItems[test.t.a] to TopN[7]", - assertReason: "TopN[7] is Limit originally", + assertAction: "Sort_5 passes ByItems[test.t.a] to TopN_7", + assertReason: "TopN_7 is Limit originally", }, { - assertAction: "TopN[8] is added and pushed into Join[3]'s left table", - assertReason: "Join[3]'s joinType is left outer join, and all ByItems[test.t.a] contained in left table", + assertAction: "TopN_8 is added and pushed into Join_3's left table", + assertReason: "Join_3's joinType is left outer join, and all ByItems[test.t.a] contained in left table", }, { - assertAction: "TopN[8] is added as DataSource[1]'s parent", + assertAction: "TopN_8 is added as DataSource_1's parent", assertReason: "TopN is pushed down", }, { - assertAction: "TopN[7] is added as Join[3]'s parent", + assertAction: "TopN_7 is added as Join_3's parent", assertReason: "TopN is pushed down", }, }, @@ -119,15 +119,15 @@ func (s *testPlanSuite) TestSingleRuleTraceStep(c *C) { assertRuleName: "topn_push_down", assertRuleSteps: []assertTraceStep{ { - assertAction: "Limit[4] is converted into TopN[5]", - assertReason: "Limit can be converted into TopN", + assertAction: "Limit_4 is converted into TopN_5", + assertReason: "", }, { - assertAction: "Sort[3] passes ByItems[test.t.a] to TopN[5]", - assertReason: "TopN[5] is Limit originally", + assertAction: "Sort_3 passes ByItems[test.t.a] to TopN_5", + assertReason: "TopN_5 is Limit originally", }, { - assertAction: "TopN[5] is added as DataSource[1]'s parent", + assertAction: "TopN_5 is added as DataSource_1's parent", assertReason: "TopN is pushed down", }, }, diff --git a/planner/core/rule_topn_push_down.go b/planner/core/rule_topn_push_down.go index 4a2a333eb7b45..73ed5749bc57c 100644 --- a/planner/core/rule_topn_push_down.go +++ b/planner/core/rule_topn_push_down.go @@ -87,7 +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(), "Limit can be converted into TopN", fmt.Sprintf("%v[%v] is converted into %v[%v]", + opt.appendStepToCurrent(topn.ID(), topn.TP(), "", fmt.Sprintf("%v_%v is converted into %v_%v", p.TP(), p.ID(), topn.TP(), topn.ID())) return topn } @@ -110,7 +110,7 @@ func (p *LogicalUnionAll) pushDownTopN(topN *LogicalTopN, opt *logicalOptimizeOp } // 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]", + fmt.Sprintf("%v_%v is added and pushed down across %v_%v", newTopN.TP(), newTopN.ID(), p.TP(), p.ID())) } p.children[i] = child.pushDownTopN(newTopN, opt) @@ -202,14 +202,14 @@ 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()) + 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()) opt.appendStepToCurrent(parent.ID(), parent.TP(), reason, action) } func appendTopNPushDownJoinTraceStep(p *LogicalJoin, topN *LogicalTopN, idx int, opt *logicalOptimizeOp) { action := func() string { - buffer := bytes.NewBufferString(fmt.Sprintf("%v[%v] is added and pushed into %v[%v]'s ", + buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v is added and pushed into %v_%v's ", topN.TP(), topN.ID(), p.TP(), p.ID())) if idx == 0 { buffer.WriteString("left ") @@ -220,7 +220,7 @@ func appendTopNPushDownJoinTraceStep(p *LogicalJoin, topN *LogicalTopN, idx int, 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())) + 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 { if i > 0 { buffer.WriteString(",") @@ -241,16 +241,16 @@ func appendTopNPushDownJoinTraceStep(p *LogicalJoin, topN *LogicalTopN, idx int, func appendSortPassByItemsTraceStep(sort *LogicalSort, topN *LogicalTopN, opt *logicalOptimizeOp) { action := func() string { - buffer := bytes.NewBufferString(fmt.Sprintf("%v[%v] passes ByItems[", sort.TP(), sort.ID())) + buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v passes ByItems[", sort.TP(), sort.ID())) for i, item := range sort.ByItems { if i > 0 { buffer.WriteString(",") } buffer.WriteString(item.String()) } - buffer.WriteString(fmt.Sprintf("] to %v[%v]", topN.TP(), topN.ID())) + 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 := fmt.Sprintf("%v_%v is Limit originally", topN.TP(), topN.ID()) opt.appendStepToCurrent(sort.ID(), sort.TP(), reason, action) }