plan: fix a bug when applying top-n push down rule. (#6187)
This commit is contained in:
@ -184,6 +184,10 @@ func (s *testPlanSuite) TestDAGPlanBuilderSimpleCase(c *C) {
|
||||
sql: "select * from t use index(e_d_c_str_prefix) where t.e_str = b'1110000'",
|
||||
best: "IndexLookUp(Index(t.e_d_c_str_prefix)[[p,p]], Table(t))",
|
||||
},
|
||||
{
|
||||
sql: "select * from (select * from t use index() order by b) t left join t t1 on t.a=t1.a limit 10",
|
||||
best: "IndexJoin{TableReader(Table(t)->TopN([test.t.b],0,10))->TopN([test.t.b],0,10)->TableReader(Table(t))}(test.t.a,t1.a)->Limit",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
comment := Commentf("for %s", tt.sql)
|
||||
|
||||
@ -61,6 +61,8 @@ func (ls *LogicalSort) pushDownTopN(topN *LogicalTopN) LogicalPlan {
|
||||
} else if topN.isLimit() {
|
||||
topN.ByItems = ls.ByItems
|
||||
// If a Limit is pushed down, the LogicalSort should be converted to topN and be pushed again.
|
||||
// Since the limit is combined with the sort operator. It's not a partial one any more.
|
||||
topN.partial = false
|
||||
return ls.children[0].pushDownTopN(topN)
|
||||
}
|
||||
// If a TopN is pushed down, this sort is useless.
|
||||
|
||||
Reference in New Issue
Block a user