From 15795a3a93c43980f26382fd5249310582d9a17c Mon Sep 17 00:00:00 2001 From: imtbkcat Date: Tue, 4 Sep 2018 15:21:06 +0800 Subject: [PATCH 1/2] fix default float scale --- infoschema/tables.go | 36 ++++++++++++++++++++---------------- infoschema/tables_test.go | 3 +++ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/infoschema/tables.go b/infoschema/tables.go index bd2bda00cbd09..64638e5e8b525 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -833,7 +833,11 @@ func dataForColumnsInTable(schema *model.DBInfo, tbl *model.TableInfo) [][]types datetimePrecision = decimal } else if types.IsTypeNumeric(col.Tp) { numericPrecision = colLen - numericScale = decimal + if col.Tp != mysql.TypeFloat && col.Tp != mysql.TypeDouble { + numericScale = decimal + } else if decimal != -1 { + numericScale = decimal + } } columnType := col.FieldType.InfoSchemaStr() columnDesc := table.NewColDesc(table.ToColumn(col)) @@ -1006,24 +1010,24 @@ func dataForTableConstraints(schemas []*model.DBInfo) [][]types.Datum { func dataForPseudoProfiling() [][]types.Datum { var rows [][]types.Datum row := types.MakeDatums( - 0, // QUERY_ID - 0, // SEQ - "", // STATE + 0, // QUERY_ID + 0, // SEQ + "", // STATE types.NewDecFromInt(0), // DURATION types.NewDecFromInt(0), // CPU_USER types.NewDecFromInt(0), // CPU_SYSTEM - 0, // CONTEXT_VOLUNTARY - 0, // CONTEXT_INVOLUNTARY - 0, // BLOCK_OPS_IN - 0, // BLOCK_OPS_OUT - 0, // MESSAGES_SENT - 0, // MESSAGES_RECEIVED - 0, // PAGE_FAULTS_MAJOR - 0, // PAGE_FAULTS_MINOR - 0, // SWAPS - 0, // SOURCE_FUNCTION - 0, // SOURCE_FILE - 0, // SOURCE_LINE + 0, // CONTEXT_VOLUNTARY + 0, // CONTEXT_INVOLUNTARY + 0, // BLOCK_OPS_IN + 0, // BLOCK_OPS_OUT + 0, // MESSAGES_SENT + 0, // MESSAGES_RECEIVED + 0, // PAGE_FAULTS_MAJOR + 0, // PAGE_FAULTS_MINOR + 0, // SWAPS + 0, // SOURCE_FUNCTION + 0, // SOURCE_FILE + 0, // SOURCE_LINE ) rows = append(rows, row) return rows diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 82f08876f5982..c88c370f39ea0 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -40,6 +40,7 @@ func (s *testSuite) TestInfoschemaFielValue(c *C) { tk.MustExec("create table numschema(i int(2), f float(4,2), d decimal(4,3))") tk.MustExec("create table timeschema(d date, dt datetime(3), ts timestamp(3), t time(4), y year(4))") tk.MustExec("create table strschema(c char(3), c2 varchar(3), b blob(3), t text(3))") + tk.MustExec("create table floatschema(a float, b double(7, 3))") tk.MustQuery("select CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION from information_schema.COLUMNS where table_name='numschema'"). Check(testkit.Rows(" 2 0 ", " 4 2 ", " 4 3 ")) // FIXME: for mysql first one will be " 10 0 " @@ -47,6 +48,8 @@ func (s *testSuite) TestInfoschemaFielValue(c *C) { Check(testkit.Rows(" ", " 3", " 3", " 4", " ")) tk.MustQuery("select CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION from information_schema.COLUMNS where table_name='strschema'"). Check(testkit.Rows("3 3 ", "3 3 ", "3 3 ", "3 3 ")) // FIXME: for mysql last two will be "255 255 ", "255 255 " + tk.MustQuery("select NUMERIC_SCALE from information_schema.COLUMNS where table_name='floatschema'"). + Check(testkit.Rows("", "3")) } func (s *testSuite) TestDataForTableRowsCountField(c *C) { From 4dfe84ed62a98c34d91ab91c24c7e3445e52d1be Mon Sep 17 00:00:00 2001 From: imtbkcat Date: Tue, 4 Sep 2018 15:53:44 +0800 Subject: [PATCH 2/2] refmt --- infoschema/tables.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/infoschema/tables.go b/infoschema/tables.go index 64638e5e8b525..894129efbc157 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -1010,24 +1010,24 @@ func dataForTableConstraints(schemas []*model.DBInfo) [][]types.Datum { func dataForPseudoProfiling() [][]types.Datum { var rows [][]types.Datum row := types.MakeDatums( - 0, // QUERY_ID - 0, // SEQ - "", // STATE + 0, // QUERY_ID + 0, // SEQ + "", // STATE types.NewDecFromInt(0), // DURATION types.NewDecFromInt(0), // CPU_USER types.NewDecFromInt(0), // CPU_SYSTEM - 0, // CONTEXT_VOLUNTARY - 0, // CONTEXT_INVOLUNTARY - 0, // BLOCK_OPS_IN - 0, // BLOCK_OPS_OUT - 0, // MESSAGES_SENT - 0, // MESSAGES_RECEIVED - 0, // PAGE_FAULTS_MAJOR - 0, // PAGE_FAULTS_MINOR - 0, // SWAPS - 0, // SOURCE_FUNCTION - 0, // SOURCE_FILE - 0, // SOURCE_LINE + 0, // CONTEXT_VOLUNTARY + 0, // CONTEXT_INVOLUNTARY + 0, // BLOCK_OPS_IN + 0, // BLOCK_OPS_OUT + 0, // MESSAGES_SENT + 0, // MESSAGES_RECEIVED + 0, // PAGE_FAULTS_MAJOR + 0, // PAGE_FAULTS_MINOR + 0, // SWAPS + 0, // SOURCE_FUNCTION + 0, // SOURCE_FILE + 0, // SOURCE_LINE ) rows = append(rows, row) return rows