Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plan: fix predicate push down for UnionScan #7726

Merged
merged 2 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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