func testCreateTable(c *C, ctx context.Context, d *ddl, dbInfo *model.DBInfo, tblInfo *model.TableInfo) *model.Job { job := &model.Job{ SchemaID: dbInfo.ID, TableID: tblInfo.ID, Type: model.ActionCreateTable, Args: []interface{}{tblInfo}, } err := d.doDDLJob(ctx, job) c.Assert(err, IsNil) v := getSchemaVer(c, ctx) tblInfo.State = model.StatePublic checkHistoryJobArgs(c, ctx, job.ID, &historyJobArgs{ver: v, tbl: tblInfo}) tblInfo.State = model.StateNone return job }
// If create table with auto_increment option, we should rebase tableAutoIncID value. func (d *ddl) handleAutoIncID(tbInfo *model.TableInfo, schemaID int64) error { alloc := autoid.NewAllocator(d.store, schemaID) tbInfo.State = model.StatePublic tb, err := table.TableFromMeta(alloc, tbInfo) if err != nil { return errors.Trace(err) } // The operation of the minus 1 to make sure that the current value doesn't be used, // the next Alloc operation will get this value. // Its behavior is consistent with MySQL. if err = tb.RebaseAutoID(tbInfo.AutoIncID-1, false); err != nil { return errors.Trace(err) } return nil }
func (d *ddl) handleTableOptions(options []*ast.TableOption, tbInfo *model.TableInfo, schemaID int64) error { for _, op := range options { if op.Tp == ast.TableOptionAutoIncrement { alloc := autoid.NewAllocator(d.store, schemaID) tbInfo.State = model.StatePublic tb, err := table.TableFromMeta(alloc, tbInfo) if err != nil { return errors.Trace(err) } // The operation of the minus 1 to make sure that the current value doesn't be used, // the next Alloc operation will get this value. // Its behavior is consistent with MySQL. if err = tb.RebaseAutoID(int64(op.UintValue-1), false); err != nil { return errors.Trace(err) } } } return nil }