Skip to content

Commit

Permalink
drop primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiwei committed Apr 19, 2022
1 parent 35a5d21 commit e6f3b06
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions ddl/ddl_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func (c *testCase) generateDDLOps() error {
if err := c.generateModifyColumn2(5); err != nil {
return errors.Trace(err)
}
if err := c.generateAddPrimaryKey(defaultTime); err != nil {
return errors.Trace(err)
}
return nil
}

Expand Down Expand Up @@ -119,6 +122,7 @@ const (
ActionModifySchemaDefaultPlacement

ActionAddPrimaryKey
ActionDropPrimaryKey

ddlKindNil
)
Expand Down Expand Up @@ -153,6 +157,7 @@ var mapOfDDLKind = map[string]DDLKind{
"modify schema default placement": ActionModifySchemaDefaultPlacement,

"add primary key": ActionAddPrimaryKey,
"drop primary key": ActionDropPrimaryKey,
}

var mapOfDDLKindToString = map[DDLKind]string{
Expand Down Expand Up @@ -184,6 +189,7 @@ var mapOfDDLKindToString = map[DDLKind]string{
ActionModifySchemaDefaultPlacement: "modify schema default placement",

ActionAddPrimaryKey: "add primary key",
ActionDropPrimaryKey: "drop primary key",
}

// mapOfDDLKindProbability use to control every kind of ddl request execute probability.
Expand Down Expand Up @@ -279,6 +285,10 @@ func (c *testCase) updateTableInfo(task *ddlJobTask) error {
return c.modifyColumnJob(task)
case ActionModifySchemaCharsetAndCollate:
return c.setModifySchemaCharsetAndCollate(task)
case ActionAddPrimaryKey:
return c.setAddPrimaryKey(task)
case ActionDropPrimaryKey:
return c.setDropPrimaryKey(task)
}
return fmt.Errorf("unknow ddl task , %v", *task)
}
Expand Down Expand Up @@ -1269,6 +1279,39 @@ func (c *testCase) setAddPrimaryKey(task *ddlJobTask) error {
return nil
}


func (c *testCase) generateDropPrimaryKey(repeat int) error {
for i := 0; i < repeat; i++ {
c.ddlOps = append(c.ddlOps, ddlTestOpExecutor{c.prepareDropPrimaryKey, nil, ActionDropPrimaryKey})
}
return nil
}

func (c *testCase) prepareDropPrimaryKey(_ interface{}, taskCh chan *ddlJobTask) error {
table := c.pickupRandomTable()
if table == nil {
return nil
}
if !table.hasPK {
return nil
}

// build SQL
sql := fmt.Sprintf("ALTER TABLE `%s` DROP PRIMARY KEY", table.name)
taskCh <- &ddlJobTask{
k: ActionDropPrimaryKey,
sql: sql,
tblInfo: table,
}
return nil
}

func (c *testCase) setDropPrimaryKey(task *ddlJobTask) error {
tblInfo := task.tblInfo
tblInfo.hasPK = false
return nil
}

type ddlRenameIndexArg struct {
preIndex int
newIndex string
Expand Down

0 comments on commit e6f3b06

Please sign in to comment.