Skip to content

Commit

Permalink
plan: fix predicate push down for UnionScan (#7726)
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood authored and zz-jason committed Sep 20, 2018
1 parent 3e9f830 commit 23baa75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions executor/union_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,16 @@ func (s *testSuite) TestDirtyTransaction(c *C) {
tk.MustQuery("select * from t use index(idx) where c > 1 and d = 4").Check(testkit.Rows("1 2 3 4"))
tk.MustExec("commit")
}

func (s *testSuite) TestUnionScanWithCastCondition(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("create table ta (a varchar(20))")
tk.MustExec("insert ta values ('1'), ('2')")
tk.MustExec("create table tb (a varchar(20))")
tk.MustExec("begin")
tk.MustQuery("select * from ta where a = 1").Check(testkit.Rows("1"))
tk.MustExec("insert tb values ('0')")
tk.MustQuery("select * from ta where a = 1").Check(testkit.Rows("1"))
tk.MustExec("rollback")
}
5 changes: 3 additions & 2 deletions plan/predicate_push_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ func (p *LogicalSelection) PredicatePushDown(predicates []expression.Expression)

// PredicatePushDown implements LogicalPlan PredicatePushDown interface.
func (p *LogicalUnionScan) PredicatePushDown(predicates []expression.Expression) ([]expression.Expression, LogicalPlan) {
p.children[0].PredicatePushDown(predicates)
retainedPredicates, _ := p.children[0].PredicatePushDown(predicates)
p.conditions = make([]expression.Expression, 0, len(predicates))
for _, cond := range predicates {
p.conditions = append(p.conditions, cond.Clone())
}
return nil, p
// The conditions in UnionScan is only used for added rows, so parent Selection should not be removed.
return retainedPredicates, p
}

// PredicatePushDown implements LogicalPlan PredicatePushDown interface.
Expand Down

0 comments on commit 23baa75

Please sign in to comment.