Skip to content

Commit

Permalink
planner: fold constant in TopN push down (#14944)
Browse files Browse the repository at this point in the history
  • Loading branch information
eurekaka authored Feb 26, 2020
1 parent 037b369 commit 094d6b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,11 @@ func (s *testIntegrationSuite) TestMaxMinEliminate(c *C) {
tk.MustQuery(tt).Check(testkit.Rows(output[i].Plan...))
}
}

func (s *testIntegrationSuite) TestTopNByConstFunc(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustQuery("select max(t.col) from (select 'a' as col union all select '' as col) as t").Check(testkit.Rows(
"a",
))
}
2 changes: 1 addition & 1 deletion planner/core/rule_topn_push_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (p *LogicalUnionAll) pushDownTopN(topN *LogicalTopN) LogicalPlan {
func (p *LogicalProjection) pushDownTopN(topN *LogicalTopN) LogicalPlan {
if topN != nil {
for _, by := range topN.ByItems {
by.Expr = expression.ColumnSubstitute(by.Expr, p.schema, p.Exprs)
by.Expr = expression.FoldConstant(expression.ColumnSubstitute(by.Expr, p.schema, p.Exprs))
}

// remove meaningless constant sort items.
Expand Down

0 comments on commit 094d6b5

Please sign in to comment.