Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions ddl/ddl_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ func (s *testDBSuite) TestColumn(c *C) {
s.tk.MustExec("create table t2 (c1 int, c2 int, c3 int)")
s.testAddColumn(c)
s.testDropColumn(c)
s.testDropColumn2(c)
s.tk.MustExec("drop table t2")
}

Expand All @@ -812,6 +813,10 @@ func sessionExec(c *C, s kv.Storage, sql string) {
}

func sessionExecInGoroutine(c *C, s kv.Storage, sql string, done chan error) {
execMultiSQLInGoroutine(c, s, []string{sql}, done)
}

func execMultiSQLInGoroutine(c *C, s kv.Storage, multiSQL []string, done chan error) {
go func() {
se, err := tidb.CreateSession4Test(s)
if err != nil {
Expand All @@ -824,16 +829,18 @@ func sessionExecInGoroutine(c *C, s kv.Storage, sql string, done chan error) {
done <- errors.Trace(err)
return
}
rs, err := se.Execute(goctx.Background(), sql)
if err != nil {
done <- errors.Trace(err)
return
}
if rs != nil {
done <- errors.Errorf("RecordSet should be empty.")
return
for _, sql := range multiSQL {
rs, err := se.Execute(goctx.Background(), sql)
if err != nil {
done <- errors.Trace(err)
return
}
if rs != nil {
done <- errors.Errorf("RecordSet should be empty.")
return
}
done <- nil
}
done <- nil
}()
}

Expand Down Expand Up @@ -988,6 +995,28 @@ LOOP:
c.Assert(count, Greater, int64(0))
}

func (s *testDBSuite) testDropColumn2(c *C) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment for this test.

num := 100
dmlDone := make(chan error, num)
ddlDone := make(chan error, num)
s.mustExec(c, "delete from t2")

multiDDL := make([]string, 0, num)
for i := 0; i < num/2; i++ {
multiDDL = append(multiDDL, "alter table t2 add column c4 int", "alter table t2 drop column c4")
}
execMultiSQLInGoroutine(c, s.store, multiDDL, ddlDone)
for i := 0; i < num; i++ {
sessionExecInGoroutine(c, s.store, "insert into t2 set c1 = 1, c2 = 1, c3 = 1, c4 = 1", dmlDone)
}
for i := 0; i < num; i++ {
select {
case err := <-ddlDone:
c.Assert(err, IsNil, Commentf("err:%v", errors.ErrorStack(err)))
}
}
}

func (s *testDBSuite) TestPrimaryKey(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use " + s.schemaName)
Expand Down
3 changes: 3 additions & 0 deletions expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ func TableInfo2SchemaWithDBName(dbName model.CIStr, tbl *model.TableInfo) *Schem
func ColumnInfos2ColumnsWithDBName(dbName, tblName model.CIStr, colInfos []*model.ColumnInfo) []*Column {
columns := make([]*Column, 0, len(colInfos))
for i, col := range colInfos {
if col.State != model.StatePublic {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about write only column? @zimulala PTAL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the column is given by the client, we need the Public column.

continue
}
newCol := &Column{
ColName: col.Name,
TblName: tblName,
Expand Down