diff --git a/executor/join_test.go b/executor/join_test.go index 6564107605c48..9a2c521e20ca3 100644 --- a/executor/join_test.go +++ b/executor/join_test.go @@ -252,6 +252,15 @@ func (s *testSuite) TestJoin(c *C) { } result = tk.MustQuery("select /*+ TIDB_HJ(s, r) */ * from t as s join t as r on s.a = r.a limit 1;") result.Check(testkit.Rows("1 1")) + + tk.MustExec("drop table if exists user, aa, bb") + tk.MustExec("create table aa(id int)") + tk.MustExec("insert into aa values(1)") + tk.MustExec("create table bb(id int)") + tk.MustExec("insert into bb values(1)") + tk.MustExec("create table user(id int, name varchar(20))") + tk.MustExec("insert into user values(1, 'a'), (2, 'b')") + tk.MustQuery("select user.id,user.name from user left join aa on aa.id = user.id left join bb on aa.id = bb.id where bb.id < 10;").Check(testkit.Rows("1 a")) } func (s *testSuite) TestJoinCast(c *C) { diff --git a/plan/predicate_push_down.go b/plan/predicate_push_down.go index 5de0c8d8b63e1..5eacb5b8a9b43 100644 --- a/plan/predicate_push_down.go +++ b/plan/predicate_push_down.go @@ -133,8 +133,14 @@ func (p *LogicalJoin) PredicatePushDown(predicates []expression.Expression) (ret case InnerJoin: p.LeftConditions = nil p.RightConditions = nil - p.EqualConditions = equalCond - p.OtherConditions = otherCond + p.EqualConditions = make([]*expression.ScalarFunction, 0, len(equalCond)) + for _, cond := range equalCond { + p.EqualConditions = append(p.EqualConditions, cond.Clone().(*expression.ScalarFunction)) + } + p.OtherConditions = make([]expression.Expression, 0, len(otherCond)) + for _, cond := range otherCond { + p.OtherConditions = append(p.OtherConditions, cond.Clone()) + } leftCond = leftPushCond rightCond = rightPushCond }