TiDB-OPS

TiDB Online DDL 测试

DDL 测试

支持的 DDL type

switch job.Type {
	case model.ActionCreateSchema:
		ver, err = onCreateSchema(t, job)
	case model.ActionDropSchema:
		ver, err = onDropSchema(t, job)
	case model.ActionCreateTable:
		ver, err = onCreateTable(d, t, job)
	case model.ActionDropTable:
		ver, err = onDropTable(t, job)
	case model.ActionDropTablePartition:
		ver, err = onDropTablePartition(t, job)
	case model.ActionAddColumn:
		ver, err = onAddColumn(d, t, job)
	case model.ActionDropColumn:
		ver, err = onDropColumn(t, job)
	case model.ActionModifyColumn:
		ver, err = onModifyColumn(t, job)
	case model.ActionSetDefaultValue:
		ver, err = onSetDefaultValue(t, job)
	case model.ActionAddIndex:
		ver, err = w.onCreateIndex(d, t, job)
	case model.ActionDropIndex:
		ver, err = onDropIndex(t, job)
	case model.ActionRenameIndex:
		ver, err = onRenameIndex(t, job)
	case model.ActionAddForeignKey:
		ver, err = onCreateForeignKey(t, job)
	case model.ActionDropForeignKey:
		ver, err = onDropForeignKey(t, job)
	case model.ActionTruncateTable:
		ver, err = onTruncateTable(d, t, job)
	case model.ActionRebaseAutoID:
		ver, err = onRebaseAutoID(d.store, t, job)
	case model.ActionRenameTable:
		ver, err = onRenameTable(t, job)
	case model.ActionShardRowID:
		ver, err = onShardRowID(t, job)
	case model.ActionModifyTableComment:
		ver, err = onModifyTableComment(t, job)
	case model.ActionAddTablePartition:
		ver, err = onAddTablePartition(t, job)

DDL 工作过程

DDL 查询与管理


DDL FAQ

各类型 DDL 语句测试记录

测试版本为 TiDB 2.0

Create Table

2017/08/15 16:11:35 ddl.go:421: [info] [ddl] start DDL job ID:34, Type:create table, State:none, SchemaState:none, SchemaID:29, TableID:33, RowCount:0, ArgLen:1, Query:
CREATE TABLE world.t2 (id INT, name VARCHAR(256), PRIMARY KEY(id)) ENGINE=InnoDB
2017/08/15 16:11:35 ddl_worker.go:253: [info] [ddl] run DDL job ID:34, Type:create table, State:none, SchemaState:none, SchemaID:29, TableID:33, RowCount:0, ArgLen:0
2017/08/15 16:11:35 domain.go:93: [info] [ddl] diff load InfoSchema from version 16 to 17, in 2.471353ms
2017/08/15 16:11:35 ddl_worker.go:359: [info] [ddl] wait latest schema version 17 changed, take time 52.091016ms
2017/08/15 16:11:35 ddl_worker.go:140: [info] [ddl] finish DDL job ID:34, Type:create table, State:synced, SchemaState:public, SchemaID:29, TableID:33, RowCount:0, ArgLen:0
2017/08/15 16:11:35 ddl.go:457: [info] [ddl] DDL job 34 is finished
2017/08/15 16:11:35 domain.go:365: [info] [ddl] on DDL change, must reload

Drop Table

2017/08/15 16:22:22 ddl.go:421: [info] [ddl] start DDL job ID:35, Type:drop table, State:none, SchemaState:none, SchemaID:29, TableID:33, RowCount:0, ArgLen:0, Query:
drop table world.t2
2017/08/15 16:22:22 ddl_worker.go:253: [info] [ddl] run DDL job ID:35, Type:drop table, State:none, SchemaState:none, SchemaID:29, TableID:33, RowCount:0, ArgLen:0
2017/08/15 16:22:22 domain.go:93: [info] [ddl] diff load InfoSchema from version 17 to 18, in 1.187145ms
2017/08/15 16:22:22 ddl_worker.go:359: [info] [ddl] wait latest schema version 18 changed, take time 52.04002ms
2017/08/15 16:22:22 ddl_worker.go:253: [info] [ddl] run DDL job ID:35, Type:drop table, State:running, SchemaState:write only, SchemaID:29, TableID:33, RowCount:0, ArgLen:0
2017/08/15 16:22:22 domain.go:93: [info] [ddl] diff load InfoSchema from version 18 to 19, in 999.369µs
2017/08/15 16:22:22 ddl_worker.go:359: [info] [ddl] wait latest schema version 19 changed, take time 51.84345ms
2017/08/15 16:22:22 ddl_worker.go:253: [info] [ddl] run DDL job ID:35, Type:drop table, State:running, SchemaState:delete only, SchemaID:29, TableID:33, RowCount:0, ArgLen:0
2017/08/15 16:22:22 domain.go:93: [info] [ddl] diff load InfoSchema from version 19 to 20, in 1.228868ms
2017/08/15 16:22:22 ddl_worker.go:359: [info] [ddl] wait latest schema version 20 changed, take time 51.969018ms
2017/08/15 16:22:22 delete_range.go:253: [info] [ddl] insert into delete-range table with key: (35,33)
2017/08/15 16:22:22 delete_range.go:93: [info] [ddl] add job (35,drop table) into delete-range table
2017/08/15 16:22:22 ddl_worker.go:140: [info] [ddl] finish DDL job ID:35, Type:drop table, State:synced, SchemaState:none, SchemaID:29, TableID:33, RowCount:0, ArgLen:0
2017/08/15 16:22:22 ddl.go:457: [info] [ddl] DDL job 35 is finished
2017/08/15 16:22:22 domain.go:365: [info] [ddl] on DDL change, must reload

ALTER Table Modify Column

  2018/01/05 10:31:37 ddl.go:410: [info] [ddl] start DDL job ID:540, Type:modify column, State:none, SchemaState:none, SchemaID:530, TableID:532, RowCount:0, ArgLen:3, Query:
  ALTER TABLE `ip_banner`
  MODIFY COLUMN `timestamp`  varchar(80) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '' AFTER `ip`
  2018/01/05 10:31:37 ddl_worker.go:262: [info] [ddl] run DDL job ID:540, Type:modify column, State:none, SchemaState:none, SchemaID:530, TableID:532, RowCount:0, ArgLen:0
  2018/01/05 10:31:38 domain.go:93: [info] [ddl] diff load InfoSchema from version 456 to 457, in 3.475215ms
  2018/01/05 10:31:38 ddl_worker.go:368: [info] [ddl] wait latest schema version 457 changed, take time 72.370341ms
  2018/01/05 10:31:38 ddl_worker.go:117: [info] [ddl] finish DDL job ID:540, Type:modify column, State:synced, SchemaState:public, SchemaID:530, TableID:532, RowCount:0, ArgLen:0
  2018/01/05 10:31:38 ddl.go:447: [info] [ddl] DDL job 540 is finished
  2018/01/05 10:31:38 domain.go:365: [info] [ddl] on DDL change, must reload