Skip to content

Commit

Permalink
add testcase
Browse files Browse the repository at this point in the history
Signed-off-by: yisaer <disxiaofei@163.com>
  • Loading branch information
Yisaer committed Dec 20, 2021
1 parent 5f0b91a commit 2708108
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
26 changes: 13 additions & 13 deletions planner/core/logical_plan_trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand All @@ -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",
},
},
Expand Down
16 changes: 8 additions & 8 deletions planner/core/rule_topn_push_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -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 ")
Expand All @@ -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(",")
Expand All @@ -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)
}

0 comments on commit 2708108

Please sign in to comment.