From 66d8fd738aa1e23be8a49eea9a55ba322b6c2a28 Mon Sep 17 00:00:00 2001 From: bb7133 Date: Thu, 27 Sep 2018 10:26:29 +0800 Subject: [PATCH] fix stylecheck fix #4754, fix #3839 --- ddl/ddl_api.go | 4 ++-- ddl/table.go | 8 ++++---- executor/ddl.go | 3 ++- executor/show.go | 24 ++++++++++++------------ types/field_type.go | 5 ++++- types/field_type_test.go | 24 ++++++++++++++++++++++++ 6 files changed, 48 insertions(+), 20 deletions(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index e85ef7e777b0d..99a7c8aecd277 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -2306,7 +2306,7 @@ func (d *ddl) RenameIndex(ctx sessionctx.Context, ident ast.Ident, spec *ast.Alt } // DropTable will proceed even if some table in the list does not exists. -func (d *ddl) DropTable(ctx sessionctx.Context, ti ast.Ident, tableId int64) (err error) { +func (d *ddl) DropTable(ctx sessionctx.Context, ti ast.Ident, tableID int64) (err error) { is := d.GetInformationSchema(ctx) schema, ok := is.SchemaByName(ti.Schema) if !ok { @@ -2320,7 +2320,7 @@ func (d *ddl) DropTable(ctx sessionctx.Context, ti ast.Ident, tableId int64) (er job := &model.Job{ SchemaID: schema.ID, - TableID: tableId, + TableID: tableID, Type: model.ActionDropTable, BinlogInfo: &model.HistoryInfo{}, } diff --git a/ddl/table.go b/ddl/table.go index 25550f1d8f96b..19037fdb593d2 100644 --- a/ddl/table.go +++ b/ddl/table.go @@ -68,7 +68,7 @@ func onCreateTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) // TODO: Add restrictions to this operation. go splitTableRegion(d.store, tbInfo.ID) } - ver, err := updateVersionAndTableInfo(t, job, tbInfo, originalState != tbInfo.State) + ver, err = updateVersionAndTableInfo(t, job, tbInfo, originalState != tbInfo.State) if err != nil { job.State = model.JobStateCancelled return ver, err @@ -83,9 +83,9 @@ func onCreateTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) } } -func onRevealTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) { +func onRevealTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, err error) { tbInfo := &model.TableInfo{} - if err := job.DecodeArgs(tbInfo); err != nil { + if err = job.DecodeArgs(tbInfo); err != nil { // Invalid arguments, cancel this job. job.State = model.JobStateCancelled return ver, errors.Trace(err) @@ -98,7 +98,7 @@ func onRevealTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) tbInfo.State = model.StatePublic tbInfo.UpdateTS = t.StartTS // Finish this job. - ver, err := updateVersionAndTableInfo(t, job, tbInfo, originalState != tbInfo.State) + ver, err = updateVersionAndTableInfo(t, job, tbInfo, originalState != tbInfo.State) if err != nil { job.State = model.JobStateCancelled return ver, err diff --git a/executor/ddl.go b/executor/ddl.go index 8bcb7b8603a65..36c3632b3dabb 100644 --- a/executor/ddl.go +++ b/executor/ddl.go @@ -96,7 +96,8 @@ func (e *DDLExec) Next(ctx context.Context, req *chunk.RecordBatch) (err error) case *ast.CreateDatabaseStmt: err = e.executeCreateDatabase(x) case *ast.CreateTableStmt: - tableID, err := e.executeCreateTable(x) + var tableID int64 + tableID, err = e.executeCreateTable(x) if err != nil { return errors.Trace(e.toErr(err)) } diff --git a/executor/show.go b/executor/show.go index 7d14e60468c37..269c9939b5362 100644 --- a/executor/show.go +++ b/executor/show.go @@ -443,19 +443,19 @@ func (e *ShowExec) fetchShowIndex() error { subPart = col.Length } e.appendRow([]interface{}{ - tb.Meta().Name.O, // Table - nonUniq, // Non_unique - idx.Meta().Name.O, // Key_name - i + 1, // Seq_in_index - col.Name.O, // Column_name - "A", // Collation - 0, // Cardinality - subPart, // Sub_part - nil, // Packed - "YES", // Null + tb.Meta().Name.O, // Table + nonUniq, // Non_unique + idx.Meta().Name.O, // Key_name + i + 1, // Seq_in_index + col.Name.O, // Column_name + "A", // Collation + 0, // Cardinality + subPart, // Sub_part + nil, // Packed + "YES", // Null idx.Meta().Tp.String(), // Index_type - "", // Comment - idx.Meta().Comment, // Index_comment + "", // Comment + idx.Meta().Comment, // Index_comment }) } } diff --git a/types/field_type.go b/types/field_type.go index 15536248d3d6a..253d7fb90b542 100644 --- a/types/field_type.go +++ b/types/field_type.go @@ -40,7 +40,10 @@ func NewFieldType(tp byte) *FieldType { } } +// Clone makes a deep copy of FieldType func (ft *FieldType) Clone() *FieldType { + elems := make([]string, len(ft.Elems)) + copy(elems, ft.Elems) return &FieldType{ Tp: ft.Tp, Flag: ft.Flag, @@ -48,7 +51,7 @@ func (ft *FieldType) Clone() *FieldType { Decimal: ft.Decimal, Charset: ft.Charset, Collate: ft.Collate, - Elems: ft.Elems, + Elems: elems, } } diff --git a/types/field_type_test.go b/types/field_type_test.go index 04ec2e4b90aba..83d92da13a558 100644 --- a/types/field_type_test.go +++ b/types/field_type_test.go @@ -392,3 +392,27 @@ func (s *testFieldTypeSuite) TestAggregateEvalType(c *C) { } } } + +func (s *testFieldTypeSuite) TestClone(c *C) { + defer testleak.AfterTest(c)() + + ft := NewFieldType(mysql.TypeDecimal) + c.Assert(ft.Equal(ft.Clone()), IsTrue) + + ft = NewFieldType(mysql.TypeLong) + ft.Flen = 5 + ft.Flag = mysql.UnsignedFlag | mysql.ZerofillFlag + c.Assert(ft.Equal(ft.Clone()), IsTrue) + + ft = NewFieldType(mysql.TypeFloat) + ft.Flen = 7 + ft.Decimal = 3 + ft.Charset = charset.CharsetASCII + ft.Collate = charset.CharsetBin + ft.Elems = []string{"a", "b", "c"} + c.Assert(ft.Equal(ft.Clone()), IsTrue) + + ftc := ft.Clone() + ftc.Elems = append(ftc.Elems, "d") + c.Assert(ft.Equal(ftc), IsFalse) +}