Skip to content

Commit

Permalink
executor,util/testkit: fix data race in test TestOnlyFullGroupBy (pin…
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored Nov 6, 2017
1 parent 363957b commit 6334705
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 40 deletions.
72 changes: 36 additions & 36 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (s *testSuite) TestOnlyFullGroupBy(c *C) {
tk.MustExec("create table x(a int not null primary key, b int not null, c int default null, d int not null, unique key I_b_c (b,c), unique key I_b_d (b,d))")

// test AggregateFunc
tk.MustExec("select max(a) from t group by d")
tk.MustQuery("select max(a) from t group by d")
// test incompatible with sql_mode = ONLY_FULL_GROUP_BY
var err error
_, err = tk.Exec("select * from t group by d")
Expand Down Expand Up @@ -389,58 +389,58 @@ func (s *testSuite) TestOnlyFullGroupBy(c *C) {
_, err = tk.Exec("select -b from t group by c")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue)
// test compatible with sql_mode = ONLY_FULL_GROUP_BY
tk.MustExec("select a from t group by a,b,c")
tk.MustExec("select b from t group by b")
tk.MustExec("select b as e from t group by b")
tk.MustExec("select b+c from t group by b+c")
tk.MustExec("select b+c, min(a) from t group by b+c, b-c")
tk.MustExec("select b+c, min(a) from t group by b, c")
tk.MustExec("select b+c from t group by b,c")
tk.MustExec("select b between c and d from t group by b,c,d")
tk.MustExec("select case b when 1 then c when 2 then d else d end from t group by b,c,d")
tk.MustExec("select c > (select b from t) from t group by c")
tk.MustExec("select exists (select * from t) from t group by d;")
tk.MustExec("select c is null from t group by c")
tk.MustExec("select c is true from t group by c")
tk.MustExec("select (c+b)*d from t group by c,b,d")
tk.MustExec("select b in (c,d) from t group by b,c,d")
tk.MustExec("select b like '%a' from t group by b")
tk.MustExec("select c REGEXP '1.*' from t group by c")
tk.MustExec("select -b from t group by b")
tk.MustQuery("select a from t group by a,b,c")
tk.MustQuery("select b from t group by b")
tk.MustQuery("select b as e from t group by b")
tk.MustQuery("select b+c from t group by b+c")
tk.MustQuery("select b+c, min(a) from t group by b+c, b-c")
tk.MustQuery("select b+c, min(a) from t group by b, c")
tk.MustQuery("select b+c from t group by b,c")
tk.MustQuery("select b between c and d from t group by b,c,d")
tk.MustQuery("select case b when 1 then c when 2 then d else d end from t group by b,c,d")
tk.MustQuery("select c > (select b from t) from t group by c")
tk.MustQuery("select exists (select * from t) from t group by d;")
tk.MustQuery("select c is null from t group by c")
tk.MustQuery("select c is true from t group by c")
tk.MustQuery("select (c+b)*d from t group by c,b,d")
tk.MustQuery("select b in (c,d) from t group by b,c,d")
tk.MustQuery("select b like '%a' from t group by b")
tk.MustQuery("select c REGEXP '1.*' from t group by c")
tk.MustQuery("select -b from t group by b")
// test functinal depend on primary key
tk.MustExec("select * from t group by a")
tk.MustQuery("select * from t group by a")
// test functional depend on unique not null columns
tk.MustExec("select * from t group by b,d")
tk.MustQuery("select * from t group by b,d")
// test functional depend on a unique null column
_, err = tk.Exec("select * from t group by b,c")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue)
// test functional dependency derived from keys in where condition
tk.MustExec("select * from t where c = d group by b, c")
tk.MustExec("select t.*, x.* from t, x where t.a = x.a group by t.a")
tk.MustExec("select t.*, x.* from t, x where t.b = x.b and t.d = x.d group by t.b, t.d")
tk.MustExec("select t.*, x.* from t, x where t.b = x.a group by t.b, t.d")
tk.MustExec("select t.b, x.* from t, x where t.b = x.a group by t.b")
tk.MustQuery("select * from t where c = d group by b, c")
tk.MustQuery("select t.*, x.* from t, x where t.a = x.a group by t.a")
tk.MustQuery("select t.*, x.* from t, x where t.b = x.b and t.d = x.d group by t.b, t.d")
tk.MustQuery("select t.*, x.* from t, x where t.b = x.a group by t.b, t.d")
tk.MustQuery("select t.b, x.* from t, x where t.b = x.a group by t.b")
_, err = tk.Exec("select t.*, x.* from t, x where t.c = x.a group by t.b, t.c")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue)
// test functional dependency derived from keys in join
tk.MustExec("select t.*, x.* from t inner join x on t.a = x.a group by t.a")
tk.MustExec("select t.*, x.* from t inner join x on (t.b = x.b and t.d = x.d) group by t.b, x.d")
tk.MustExec("select t.b, x.* from t inner join x on t.b = x.b group by t.b, x.d")
tk.MustExec("select t.b, x.* from t left join x on t.b = x.b group by t.b, x.d")
tk.MustExec("select t.b, x.* from t left join x on x.b = t.b group by t.b, x.d")
tk.MustExec("select x.b, t.* from t right join x on x.b = t.b group by x.b, t.d")
tk.MustExec("select x.b, t.* from t right join x on t.b = x.b group by x.b, t.d")
tk.MustQuery("select t.*, x.* from t inner join x on t.a = x.a group by t.a")
tk.MustQuery("select t.*, x.* from t inner join x on (t.b = x.b and t.d = x.d) group by t.b, x.d")
tk.MustQuery("select t.b, x.* from t inner join x on t.b = x.b group by t.b, x.d")
tk.MustQuery("select t.b, x.* from t left join x on t.b = x.b group by t.b, x.d")
tk.MustQuery("select t.b, x.* from t left join x on x.b = t.b group by t.b, x.d")
tk.MustQuery("select x.b, t.* from t right join x on x.b = t.b group by x.b, t.d")
tk.MustQuery("select x.b, t.* from t right join x on t.b = x.b group by x.b, t.d")
_, err = tk.Exec("select t.b, x.* from t right join x on t.b = x.b group by t.b, x.d")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue)
_, err = tk.Exec("select t.b, x.* from t right join x on t.b = x.b group by t.b, x.d")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue)
// test functional dependency of derived table
tk.MustExec("select * from (select * from t) as e group by a")
tk.MustExec("select * from (select * from t) as e group by b,d")
tk.MustQuery("select * from (select * from t) as e group by a")
tk.MustQuery("select * from (select * from t) as e group by b,d")
_, err = tk.Exec("select * from (select * from t) as e group by b,c")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue)
// test order by
tk.MustExec("select c from t group by c,d order by d")
tk.MustQuery("select c from t group by c,d order by d")
_, err = tk.Exec("select c from t group by c order by d")
c.Assert(terror.ErrorEqual(err, plan.ErrFieldNotInGroupBy), IsTrue)
// test ambiguous column
Expand Down
5 changes: 2 additions & 3 deletions structure/structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type testTxStructureSuite struct {
}

func (s *testTxStructureSuite) SetUpSuite(c *C) {
testleak.BeforeTest()
store, err := tikv.NewMockTikvStore()
c.Assert(err, IsNil)
s.store = store
Expand All @@ -44,10 +45,10 @@ func (s *testTxStructureSuite) SetUpSuite(c *C) {
func (s *testTxStructureSuite) TearDownSuite(c *C) {
err := s.store.Close()
c.Assert(err, IsNil)
testleak.AfterTest(c)
}

func (s *testTxStructureSuite) TestString(c *C) {
defer testleak.AfterTest(c)()
txn, err := s.store.Begin()
c.Assert(err, IsNil)
defer txn.Rollback()
Expand Down Expand Up @@ -87,7 +88,6 @@ func (s *testTxStructureSuite) TestString(c *C) {
}

func (s *testTxStructureSuite) TestList(c *C) {
defer testleak.AfterTest(c)()
txn, err := s.store.Begin()
c.Assert(err, IsNil)
defer txn.Rollback()
Expand Down Expand Up @@ -170,7 +170,6 @@ func (s *testTxStructureSuite) TestList(c *C) {
}

func (s *testTxStructureSuite) TestHash(c *C) {
defer testleak.AfterTest(c)()
txn, err := s.store.Begin()
c.Assert(err, IsNil)
defer txn.Rollback()
Expand Down
5 changes: 4 additions & 1 deletion util/testkit/testkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@ func (tk *TestKit) CheckExecResult(affectedRows, insertID int64) {

// MustExec executes a sql statement and asserts nil error.
func (tk *TestKit) MustExec(sql string, args ...interface{}) {
_, err := tk.Exec(sql, args...)
res, err := tk.Exec(sql, args...)
tk.c.Assert(err, check.IsNil, check.Commentf("sql:%s, %v, error stack %v", sql, args, errors.ErrorStack(err)))
if res != nil {
tk.c.Assert(res.Close(), check.IsNil)
}
}

// MustQuery query the statements and returns result rows.
Expand Down

0 comments on commit 6334705

Please sign in to comment.