Skip to content

Commit

Permalink
executor: MaxOneRow operator should keep its promise (#7375)
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-jason authored Aug 14, 2018
1 parent bfceb50 commit 9667eca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
12 changes: 9 additions & 3 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -899,11 +899,17 @@ func (e *MaxOneRowExec) Next(ctx context.Context, chk *chunk.Chunk) error {
chk.AppendNull(i)
}
return nil
} else if num == 1 {
return nil
} else if num != 1 {
return errors.New("subquery returns more than 1 row")
}

childChunk := e.children[0].newChunk()
err = e.children[0].Next(ctx, childChunk)
if childChunk.NumRows() != 0 {
return errors.New("subquery returns more than 1 row")
}

return errors.New("subquery returns more than 1 row")
return nil
}

// UnionExec pulls all it's children's result and returns to its parent directly.
Expand Down
20 changes: 20 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3068,3 +3068,23 @@ func (s *testSuite) TestUpdateJoin(c *C) {
tk.MustQuery("select k, v from t5").Check(testkit.Rows("0 0"))

}

func (s *testSuite) TestMaxOneRow(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec(`use test`)
tk.MustExec(`drop table if exists t1`)
tk.MustExec(`drop table if exists t2`)
tk.MustExec(`create table t1(a double, b double);`)
tk.MustExec(`create table t2(a double, b double);`)
tk.MustExec(`insert into t1 values(1, 1), (2, 2), (3, 3);`)
tk.MustExec(`insert into t2 values(0, 0);`)
tk.MustExec(`set @@tidb_max_chunk_size=1;`)
rs, err := tk.Exec(`select (select t1.a from t1 where t1.a > t2.a) as a from t2;`)
c.Assert(err, IsNil)

err = rs.Next(context.TODO(), rs.NewChunk())
c.Assert(err.Error(), Equals, "subquery returns more than 1 row")

err = rs.Close()
c.Assert(err, IsNil)
}

0 comments on commit 9667eca

Please sign in to comment.