Skip to content

Commit

Permalink
ddl: speed up ddl tests (pingcap#13672)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala authored and XiaTianliang committed Dec 21, 2019
1 parent 0117c5b commit a71a8fe
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 32 deletions.
6 changes: 3 additions & 3 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ func (s *testIntegrationSuite5) TestModifyingColumnOption(c *C) {
assertErrCode("alter table t2 modify column c int references t1(a)", errMsg)
}

func (s *testIntegrationSuite1) TestIndexOnMultipleGeneratedColumn(c *C) {
func (s *testIntegrationSuite4) TestIndexOnMultipleGeneratedColumn(c *C) {
tk := testkit.NewTestKit(c, s.store)

tk.MustExec("create database if not exists test")
Expand Down Expand Up @@ -1874,7 +1874,7 @@ func (s *testIntegrationSuite4) TestDropAutoIncrementIndex(c *C) {
tk.MustGetErrCode(dropIndexSQL, mysql.ErrWrongAutoKey)
}

func (s *testIntegrationSuite3) TestInsertIntoGeneratedColumnWithDefaultExpr(c *C) {
func (s *testIntegrationSuite4) TestInsertIntoGeneratedColumnWithDefaultExpr(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("create database if not exists test")
tk.MustExec("use test")
Expand Down Expand Up @@ -1936,7 +1936,7 @@ func (s *testIntegrationSuite3) TestSqlFunctionsInGeneratedColumns(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("create database if not exists test")
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("drop table if exists t, t1")

// In generated columns expression, these items are not allowed:
// 1. Blocked function (for full function list, please visit https://github.com/mysql/mysql-server/blob/5.7/mysql-test/suite/gcol/inc/gcol_blocked_sql_funcs_main.inc)
Expand Down
30 changes: 21 additions & 9 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ func checkPartitionDelRangeDone(c *C, s *testIntegrationSuite, partitionPrefix k
return hasOldPartitionData
}

func (s *testIntegrationSuite5) TestTruncatePartitionAndDropTable(c *C) {
func (s *testIntegrationSuite4) TestTruncatePartitionAndDropTable(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
// Test truncate common table.
Expand Down Expand Up @@ -1250,7 +1250,7 @@ func (s *testIntegrationSuite2) TestPartitionCancelAddPrimaryKey(c *C) {
testPartitionCancelAddIndex(c, s.store, s.dom.DDL(), s.lease, idxName, addIdxSQL)
}

func (s *testIntegrationSuite3) TestPartitionCancelAddIndex(c *C) {
func (s *testIntegrationSuite4) TestPartitionCancelAddIndex(c *C) {
idxName := "idx1"
addIdxSQL := "create unique index c3_index on t1 (c1)"
testPartitionCancelAddIndex(c, s.store, s.dom.DDL(), s.lease, idxName, addIdxSQL)
Expand Down Expand Up @@ -1449,22 +1449,34 @@ func testPartitionAddIndexOrPK(c *C, tk *testkit.TestKit, key string) {
tk.MustExec("insert into t1 values (0,0);")
tk.MustExec(fmt.Sprintf("alter table t1 add %s idx(a)", key))
tk.MustExec("admin check table t1;")

}

func testPartitionAddIndex(tk *testkit.TestKit, c *C, key string) {
idxName1 := "idx1"

f := func(end int, isPK bool) string {
dml := fmt.Sprintf("insert into partition_add_idx values")
for i := 0; i < end; i++ {
dVal := 1988 + rand.Intn(30)
if isPK {
dVal = 1518 + i
}
dml += fmt.Sprintf("(%d, '%d-01-01')", i, dVal)
if i != end-1 {
dml += ","
}
}
return dml
}
var dml string
if key == "primary key" {
idxName1 = "primary"
// For the primary key, hired must be unique.
for i := 0; i < 500; i++ {
tk.MustExec(fmt.Sprintf("insert into partition_add_idx values (%d, '%d-01-01')", i, 1518+i))
}
dml = f(500, true)
} else {
for i := 0; i < 500; i++ {
tk.MustExec(fmt.Sprintf("insert into partition_add_idx values (%d, '%d-01-01')", i, 1988+rand.Intn(30)))
}
dml = f(500, false)
}
tk.MustExec(dml)

tk.MustExec(fmt.Sprintf("alter table partition_add_idx add %s idx1 (hired)", key))
tk.MustExec("alter table partition_add_idx add index idx2 (id, hired)")
Expand Down
25 changes: 7 additions & 18 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ LOOP:
if times >= 10 {
break
}
step := 10
step := 5
// delete some rows, and add some data
for i := count; i < count+step; i++ {
n := rand.Intn(count)
Expand All @@ -323,7 +323,7 @@ LOOP:
tk.MustExec("drop table t1")
}

func (s *testDBSuite2) TestCancelAddPrimaryKey(c *C) {
func (s *testDBSuite5) TestCancelAddPrimaryKey(c *C) {
idxName := "primary"
addIdxSQL := "alter table t1 add primary key idx_c2 (c2);"
testCancelAddIndex(c, s.store, s.dom.DDL(), s.lease, idxName, addIdxSQL, "")
Expand Down Expand Up @@ -402,7 +402,7 @@ LOOP:
if times >= 10 {
break
}
step := 10
step := 5
// delete some rows, and add some data
for i := count; i < count+step; i++ {
n := rand.Intn(count)
Expand Down Expand Up @@ -992,7 +992,7 @@ LOOP:
if num > defaultBatchSize*10 {
break
}
step := 10
step := 5
// delete some rows, and add some data
for i := num; i < num+step; i++ {
n := rand.Intn(num)
Expand Down Expand Up @@ -1024,22 +1024,11 @@ LOOP:
rows := tk.MustQuery(fmt.Sprintf("select c1 from test_add_index where c3 >= %d order by c1", start)).Rows()
matchRows(c, rows, expectedRows)

tk.MustExec("admin check table test_add_index")
if testPartition {
tk.MustExec("admin check table test_add_index")
return
}

// Test index range with lower/upper boundary and random inner cases
step := len(keys) / 20
for i := 0; i <= 20; i++ {
index := i * step
if index > len(keys)-3 {
index = len(keys) - 3
}
rows := tk.MustQuery("select c1 from test_add_index where c3 >= ? order by c1 limit 3", keys[index]).Rows()
matchRows(c, rows, [][]interface{}{{keys[index]}, {keys[index+1]}, {keys[index+2]}})
}

// TODO: Support explain in future.
// rows := s.mustQuery(c, "explain select c1 from test_add_index where c3 >= 100")

Expand Down Expand Up @@ -1238,7 +1227,7 @@ LOOP:
}
c.Assert(err, IsNil, Commentf("err:%v", errors.ErrorStack(err)))
case <-ticker.C:
step := 10
step := 5
// delete some rows, and add some data
for i := num; i < num+step; i++ {
n := rand.Intn(num)
Expand Down Expand Up @@ -2085,7 +2074,7 @@ func (s *testDBSuite2) TestTableForeignKey(c *C) {
s.tk.MustExec("drop table if exists t1,t2,t3;")
}

func (s *testDBSuite2) TestFKOnGeneratedColumns(c *C) {
func (s *testDBSuite3) TestFKOnGeneratedColumns(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use test")
// test add foreign key to generated column
Expand Down
2 changes: 1 addition & 1 deletion ddl/ddl_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func (s *testDDLSuite) checkCancelDropColumn(c *C, d *ddl, schemaID int64, table
c.Assert(notFound, Equals, success)
}

func (s *testDDLSuite) TestCancelJobx(c *C) {
func (s *testDDLSuite) TestCancelJob(c *C) {
store := testCreateStore(c, "test_cancel_job")
defer store.Close()
d := newDDL(
Expand Down
11 changes: 10 additions & 1 deletion ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ import (
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl"
ddlutil "github.com/pingcap/tidb/ddl/util"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/store/mockstore/mocktikv"
"github.com/pingcap/tidb/util/admin"
Expand Down Expand Up @@ -611,7 +613,14 @@ func (s *testSerialSuite) TestCancelJobByErrorCountLimit(c *C) {
}()
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
_, err := tk.Exec("create table t (a int)")

limit := variable.GetDDLErrorCountLimit()
tk.MustExec("set @@global.tidb_ddl_error_count_limit = 16")
err := ddlutil.LoadDDLVars(tk.Se)
c.Assert(err, IsNil)
defer tk.MustExec(fmt.Sprintf("set @@global.tidb_ddl_error_count_limit = %d", limit))

_, err = tk.Exec("create table t (a int)")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:8214]Cancelled DDL job")
}
Expand Down

0 comments on commit a71a8fe

Please sign in to comment.