Skip to content

Commit

Permalink
executor: fix update join result when join table order changed (#7571)
Browse files Browse the repository at this point in the history
  • Loading branch information
lysu authored Sep 3, 2018
1 parent 621ca43 commit 3d891d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ func (b *executorBuilder) buildUpdate(v *plan.Update) Executor {
b.err = errors.Trace(b.err)
return nil
}
columns2Handle := buildColumns2Handle(v.Schema(), tblID2table)
columns2Handle := buildColumns2Handle(v.SelectPlan.Schema(), tblID2table)
updateExec := &UpdateExec{
baseExecutor: newBaseExecutor(b.ctx, nil, v.ExplainID(), selExec),
SelectExec: selExec,
Expand Down
8 changes: 7 additions & 1 deletion executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3024,14 +3024,16 @@ func (s *testSuite) TestUnionAutoSignedCast(c *C) {
func (s *testSuite) TestUpdateJoin(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1, t2, t3, t4, t5")
tk.MustExec("drop table if exists t1, t2, t3, t4, t5, t6, t7")
tk.MustExec("create table t1(k int, v int)")
tk.MustExec("create table t2(k int, v int)")
tk.MustExec("create table t3(id int auto_increment, k int, v int, primary key(id))")
tk.MustExec("create table t4(k int, v int)")
tk.MustExec("create table t5(v int, k int, primary key(k))")
tk.MustExec("insert into t1 values (1, 1)")
tk.MustExec("insert into t4 values (3, 3)")
tk.MustExec("create table t6 (id int, v longtext)")
tk.MustExec("create table t7 (x int, id int, v longtext, primary key(id))")

// test the normal case that update one row for a single table.
tk.MustExec("update t1 set v = 0 where k = 1")
Expand Down Expand Up @@ -3086,6 +3088,10 @@ func (s *testSuite) TestUpdateJoin(c *C) {
tk.MustQuery("select k, v from t1").Check(testkit.Rows("<nil> 2"))
tk.MustQuery("select k, v from t5").Check(testkit.Rows("0 0"))

tk.MustExec("insert into t6 values (1, NULL)")
tk.MustExec("insert into t7 values (5, 1, 'a')")
tk.MustExec("update t6, t7 set t6.v = t7.v where t6.id = t7.id and t7.x = 5")
tk.MustQuery("select v from t6").Check(testkit.Rows("a"))
}

func (s *testSuite) TestMaxOneRow(c *C) {
Expand Down

0 comments on commit 3d891d9

Please sign in to comment.