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 a bug in predicate push down phase. #6809

Merged
merged 6 commits into from Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions executor/join_test.go
Expand Up @@ -266,6 +266,17 @@ func (s *testSuite) TestJoin(c *C) {
tk.MustExec(`insert into t values (1);`)
tk.MustQuery(`select t2.a, t1.a from t t1 inner join (select "1" as a) t2 on t2.a = t1.a;`).Check(testkit.Rows("1 1"))
tk.MustQuery(`select t2.a, t1.a from t t1 inner join (select "2" as b, "1" as a) t2 on t2.a = t1.a;`).Check(testkit.Rows("1 1"))

tk.MustExec("drop table if exists t1, t2, t3, t4")
tk.MustExec("create table t1(a int, b int)")
tk.MustExec("create table t2(a int, b int)")
tk.MustExec("create table t3(a int, b int)")
tk.MustExec("create table t4(a int, b int)")
tk.MustExec("insert into t1 values(1, 1)")
tk.MustExec("insert into t2 values(1, 1)")
tk.MustExec("insert into t3 values(1, 1)")
tk.MustExec("insert into t4 values(1, 1)")
tk.MustQuery("select min(t2.b) from t1 right join t2 on t2.a=t1.a right join t3 on t2.a=t3.a left join t4 on t3.a=t4.a").Check(testkit.Rows("1"))
}

func (s *testSuite) TestJoinCast(c *C) {
Expand Down
6 changes: 6 additions & 0 deletions plan/rule_predicate_push_down.go
Expand Up @@ -144,6 +144,12 @@ func (p *LogicalJoin) PredicatePushDown(predicates []expression.Expression) (ret
leftCond = leftPushCond
rightCond = rightPushCond
}
for i := range leftCond {
leftCond[i] = leftCond[i].Clone()
}
for i := range rightCond {
rightCond[i] = rightCond[i].Clone()
}
leftRet, lCh := leftPlan.PredicatePushDown(leftCond)
rightRet, rCh := rightPlan.PredicatePushDown(rightCond)
addSelection(p, lCh, leftRet, 0)
Expand Down