Skip to content

Commit

Permalink
test:add control parallel execsql tests (pingcap#6615)
Browse files Browse the repository at this point in the history
* add control parallel execsql tests
  • Loading branch information
ciscoxll authored Jul 10, 2018
1 parent 26a0338 commit c94414d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
15 changes: 11 additions & 4 deletions ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ func onAddColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) {
if offset != 0 {
job.Args = []interface{}{columnInfo, pos, offset}
}
if err = checkAddColumnTooManyColumns(len(tblInfo.Columns)); err != nil {
job.State = model.JobStateCancelled
return ver, errors.Trace(err)
}
}

originalState := columnInfo.State
Expand All @@ -175,10 +179,6 @@ func onAddColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) {
// reorganization -> public
// Adjust table column offset.
adjustColumnInfoInAddColumn(tblInfo, offset)
if err = checkAddColumnTooManyColumns(tblInfo.Columns); err != nil {
job.State = model.JobStateCancelled
return ver, errors.Trace(err)
}
columnInfo.State = model.StatePublic
ver, err = updateVersionAndTableInfo(t, job, tblInfo, originalState != columnInfo.State)
if err != nil {
Expand Down Expand Up @@ -416,3 +416,10 @@ func allocateColumnID(tblInfo *model.TableInfo) int64 {
tblInfo.MaxColumnID++
return tblInfo.MaxColumnID
}

func checkAddColumnTooManyColumns(oldCols int) error {
if oldCols > TableColumnCountLimit {
return errTooManyFields
}
return nil
}
12 changes: 3 additions & 9 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func (d *ddl) DropSchema(ctx sessionctx.Context, schema model.CIStr) (err error)
if !ok {
return errors.Trace(infoschema.ErrDatabaseNotExists)
}

job := &model.Job{
SchemaID: old.ID,
Type: model.ActionDropSchema,
Expand Down Expand Up @@ -539,13 +538,6 @@ func checkTooManyColumns(colDefs []*ast.ColumnDef) error {
return nil
}

func checkAddColumnTooManyColumns(oldCols []*model.ColumnInfo) error {
if len(oldCols) > TableColumnCountLimit {
return errTooManyFields
}
return nil
}

// checkPointTypeColumns checks multiple decimal/float/double columns.
func checkPointTypeColumns(colDefs []*ast.ColumnDef) error {
for _, colDef := range colDefs {
Expand Down Expand Up @@ -1138,7 +1130,9 @@ func (d *ddl) AddColumn(ctx sessionctx.Context, ti ast.Ident, spec *ast.AlterTab
if err != nil {
return errors.Trace(infoschema.ErrTableNotExists.GenByArgs(ti.Schema, ti.Name))
}

if err = checkAddColumnTooManyColumns(len(t.Cols()) + 1); err != nil {
return errors.Trace(err)
}
// Check whether added column has existed.
col := table.FindCol(t.Cols(), colName)
if col != nil {
Expand Down
20 changes: 20 additions & 0 deletions ddl/ddl_db_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,29 @@ func (s *testStateChangeSuite) TestParallelChangeColumnName(c *C) {
s.testControlParallelExecSQL(c, sql1, sql2, f)
}

func (s *testStateChangeSuite) TestParallelAlterAddIndex(c *C) {
sql1 := "ALTER TABLE t add index index_b(b);"
sql2 := "CREATE INDEX index_b ON t (c);"
f := func(c *C, err1, err2 error) {
c.Assert(err1, IsNil)
c.Assert(err2.Error(), Equals, "[ddl:1061]index already exist index_b")
}
s.testControlParallelExecSQL(c, sql1, sql2, f)
}

func (s *testStateChangeSuite) TestParallelDropColumn(c *C) {
sql := "ALTER TABLE t drop COLUMN c ;"
f := func(c *C, err1, err2 error) {
c.Assert(err1, IsNil)
c.Assert(err2.Error(), Equals, "[ddl:1091]column c doesn't exist")
}
s.testControlParallelExecSQL(c, sql, sql, f)
}

func (s *testStateChangeSuite) TestParallelCreateAndRename(c *C) {
sql1 := "create table t_exists(c int);"
sql2 := "alter table t rename to t_exists;"
defer s.se.Execute(context.Background(), "drop table t_exists")
f := func(c *C, err1, err2 error) {
c.Assert(err1, IsNil)
c.Assert(err2.Error(), Equals, "[schema:1050]Table 't_exists' already exists")
Expand Down
5 changes: 3 additions & 2 deletions ddl/ddl_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,12 +932,13 @@ func (s *testDBSuite) TestAddColumnTooMany(c *C) {
s.tk.MustExec("use test")
count := ddl.TableColumnCountLimit - 1
var cols []string
for i := 0; i <= count; i++ {
for i := 0; i < count; i++ {
cols = append(cols, fmt.Sprintf("a%d int", i))
}
createSQL := fmt.Sprintf("create table t_column_too_many (%s)", strings.Join(cols, ","))
s.tk.MustExec(createSQL)
alterSQL := "alter table t_column_too_many add column a_512 int"
s.tk.MustExec("alter table t_column_too_many add column a_512 int")
alterSQL := "alter table t_column_too_many add column a_513 int"
s.testErrorCode(c, alterSQL, tmysql.ErrTooManyFields)
}

Expand Down

0 comments on commit c94414d

Please sign in to comment.