From 975cb415cd10219fc6f01ee0d310768d1c9b7da7 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Fri, 26 Jun 2020 13:01:41 +0800 Subject: [PATCH 01/33] executor,ddl: update auto_random_base in 'show create table' after insertion Signed-off-by: Rustin-Liu --- ddl/reorg.go | 10 +++++----- executor/show.go | 11 ++++++----- executor/show_test.go | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/ddl/reorg.go b/ddl/reorg.go index a344950f15fa2..8b0056676cc04 100755 --- a/ddl/reorg.go +++ b/ddl/reorg.go @@ -314,9 +314,9 @@ func getColumnsTypes(columns []*model.ColumnInfo) []*types.FieldType { } // buildDescTableScan builds a desc table scan upon tblInfo. -func (d *ddlCtx) buildDescTableScan(ctx context.Context, startTS uint64, tbl table.PhysicalTable, +func (dc *ddlCtx) buildDescTableScan(ctx context.Context, startTS uint64, tbl table.PhysicalTable, handleCols []*model.ColumnInfo, limit uint64) (distsql.SelectResult, error) { - sctx := newContext(d.store) + sctx := newContext(dc.store) dagPB, err := buildDescTableScanDAG(sctx, tbl, handleCols, limit) if err != nil { return nil, errors.Trace(err) @@ -346,7 +346,7 @@ func (d *ddlCtx) buildDescTableScan(ctx context.Context, startTS uint64, tbl tab } // GetTableMaxHandle gets the max handle of a PhysicalTable. -func (d *ddlCtx) GetTableMaxHandle(startTS uint64, tbl table.PhysicalTable) (maxHandle kv.Handle, emptyTable bool, err error) { +func (dc *ddlCtx) GetTableMaxHandle(startTS uint64, tbl table.PhysicalTable) (maxHandle kv.Handle, emptyTable bool, err error) { var handleCols []*model.ColumnInfo tblInfo := tbl.Meta() switch { @@ -369,7 +369,7 @@ func (d *ddlCtx) GetTableMaxHandle(startTS uint64, tbl table.PhysicalTable) (max ctx := context.Background() // build a desc scan of tblInfo, which limit is 1, we can use it to retrieve the last handle of the table. - result, err := d.buildDescTableScan(ctx, startTS, tbl, handleCols, 1) + result, err := dc.buildDescTableScan(ctx, startTS, tbl, handleCols, 1) if err != nil { return nil, false, errors.Trace(err) } @@ -385,7 +385,7 @@ func (d *ddlCtx) GetTableMaxHandle(startTS uint64, tbl table.PhysicalTable) (max // empty table return nil, true, nil } - sessCtx := newContext(d.store) + sessCtx := newContext(dc.store) row := chk.GetRow(0) if tblInfo.IsCommonHandle { maxHandle, err = buildHandleFromChunkRow(sessCtx.GetSessionVars().StmtCtx, row, handleCols) diff --git a/executor/show.go b/executor/show.go index 78186f6184ccd..e8aa1da2fc23f 100644 --- a/executor/show.go +++ b/executor/show.go @@ -903,11 +903,12 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T fmt.Fprintf(buf, " COMPRESSION='%s'", tableInfo.Compression) } + autoIncID, err := allocator.NextGlobalAutoID(tableInfo.ID) + if err != nil { + return errors.Trace(err) + } + if hasAutoIncID { - autoIncID, err := allocator.NextGlobalAutoID(tableInfo.ID) - if err != nil { - return errors.Trace(err) - } // It's compatible with MySQL. if autoIncID > 1 { fmt.Fprintf(buf, " AUTO_INCREMENT=%d", autoIncID) @@ -919,7 +920,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T } if tableInfo.AutoRandID != 0 { - fmt.Fprintf(buf, " /*T![auto_rand_base] AUTO_RANDOM_BASE=%d */", tableInfo.AutoRandID) + fmt.Fprintf(buf, " /*T![auto_rand_base] AUTO_RANDOM_BASE=%d */", autoIncID) } if tableInfo.ShardRowIDBits > 0 { diff --git a/executor/show_test.go b/executor/show_test.go index ffe2d5eadf9c6..fdc47709b1d9a 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -808,6 +808,23 @@ func (s *testAutoRandomSuite) TestAutoIdCache(c *C) { )) } +func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + + tk.MustExec("drop table if exists t") + tk.MustExec("create table t (a bigint primary key auto_random(5), b int unique key auto_increment) auto_random_base = 100, auto_increment = 100") + tk.MustExec("insert into t values (1000)") + tk.MustQuery("show create table t").Check(testutil.RowsWithSep("|", + ""+ + "t CREATE TABLE `t` (\n"+ + " b` int(11) NOT NULL AUTO_INCREMENT,\n"+ + " PRIMARY KEY (`a`),\n"+ + " UNIQUE KEY `b` (`b`)\n"+ + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin1 AUTO_INCREMENT=2000100 /*T![auto_rand_base] AUTO_RANDOM_BASE=2000100 */", + )) +} + func (s *testSuite5) TestShowEscape(c *C) { tk := testkit.NewTestKit(c, s.store) From 57a48715948edc427b608816a9699fb641dd0944 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Fri, 26 Jun 2020 13:28:58 +0800 Subject: [PATCH 02/33] executor: fix logic Signed-off-by: Rustin-Liu --- executor/show.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/executor/show.go b/executor/show.go index e8aa1da2fc23f..8b85f0a771e32 100644 --- a/executor/show.go +++ b/executor/show.go @@ -920,7 +920,13 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T } if tableInfo.AutoRandID != 0 { - fmt.Fprintf(buf, " /*T![auto_rand_base] AUTO_RANDOM_BASE=%d */", autoIncID) + var autoRandomBase = tableInfo.AutoRandID + + if autoIncID > 1 { + autoRandomBase = autoIncID + } + + fmt.Fprintf(buf, " /*T![auto_rand_base] AUTO_RANDOM_BASE=%d */", autoRandomBase) } if tableInfo.ShardRowIDBits > 0 { From be8b55e6b4f84769168e8cda6ea0dba73dfb430c Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Fri, 26 Jun 2020 13:29:34 +0800 Subject: [PATCH 03/33] executor: remove var Signed-off-by: Rustin-Liu --- executor/show.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/show.go b/executor/show.go index 8b85f0a771e32..4c64f90bf8bc9 100644 --- a/executor/show.go +++ b/executor/show.go @@ -920,7 +920,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T } if tableInfo.AutoRandID != 0 { - var autoRandomBase = tableInfo.AutoRandID + autoRandomBase := tableInfo.AutoRandID if autoIncID > 1 { autoRandomBase = autoIncID From 117c6002cf0cdce5cf04773a39b189ced809210c Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Fri, 26 Jun 2020 14:28:24 +0800 Subject: [PATCH 04/33] executor: refine logic Signed-off-by: Rustin-Liu --- executor/show.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/executor/show.go b/executor/show.go index 4c64f90bf8bc9..30bbf45bae4c8 100644 --- a/executor/show.go +++ b/executor/show.go @@ -903,12 +903,11 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T fmt.Fprintf(buf, " COMPRESSION='%s'", tableInfo.Compression) } - autoIncID, err := allocator.NextGlobalAutoID(tableInfo.ID) - if err != nil { - return errors.Trace(err) - } - if hasAutoIncID { + autoIncID, err := allocator.NextGlobalAutoID(tableInfo.ID) + if err != nil { + return errors.Trace(err) + } // It's compatible with MySQL. if autoIncID > 1 { fmt.Fprintf(buf, " AUTO_INCREMENT=%d", autoIncID) @@ -920,6 +919,11 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T } if tableInfo.AutoRandID != 0 { + autoIncID, err := allocator.NextGlobalAutoID(tableInfo.ID) + if err != nil { + return errors.Trace(err) + } + autoRandomBase := tableInfo.AutoRandID if autoIncID > 1 { From d0b6606e928aeb50192d3962f9512d30a58bf475 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Fri, 26 Jun 2020 14:34:00 +0800 Subject: [PATCH 05/33] executor: refine logic Signed-off-by: Rustin-Liu --- executor/show.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/executor/show.go b/executor/show.go index 30bbf45bae4c8..bfdbbaa8797a7 100644 --- a/executor/show.go +++ b/executor/show.go @@ -919,15 +919,17 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T } if tableInfo.AutoRandID != 0 { - autoIncID, err := allocator.NextGlobalAutoID(tableInfo.ID) - if err != nil { - return errors.Trace(err) - } - autoRandomBase := tableInfo.AutoRandID - if autoIncID > 1 { - autoRandomBase = autoIncID + if hasAutoIncID { + autoIncID, err := allocator.NextGlobalAutoID(tableInfo.ID) + if err != nil { + return errors.Trace(err) + } + + if autoIncID > 1 { + autoRandomBase = autoIncID + } } fmt.Fprintf(buf, " /*T![auto_rand_base] AUTO_RANDOM_BASE=%d */", autoRandomBase) From 8a230bec2111e3c5f910aacf450514ee683869fe Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Fri, 26 Jun 2020 14:41:45 +0800 Subject: [PATCH 06/33] executor: fix sql Signed-off-by: Rustin-Liu --- executor/show_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/show_test.go b/executor/show_test.go index fdc47709b1d9a..d1a3c3da57287 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -814,7 +814,7 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { tk.MustExec("drop table if exists t") tk.MustExec("create table t (a bigint primary key auto_random(5), b int unique key auto_increment) auto_random_base = 100, auto_increment = 100") - tk.MustExec("insert into t values (1000)") + tk.MustExec("insert into t(`a`) values (1000)") tk.MustQuery("show create table t").Check(testutil.RowsWithSep("|", ""+ "t CREATE TABLE `t` (\n"+ From 62cb14aff0d94aa35a3b09d698549a0136063c76 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Fri, 26 Jun 2020 14:48:06 +0800 Subject: [PATCH 07/33] executor: fix sql Signed-off-by: Rustin-Liu --- executor/show_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/show_test.go b/executor/show_test.go index d1a3c3da57287..fdc47709b1d9a 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -814,7 +814,7 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { tk.MustExec("drop table if exists t") tk.MustExec("create table t (a bigint primary key auto_random(5), b int unique key auto_increment) auto_random_base = 100, auto_increment = 100") - tk.MustExec("insert into t(`a`) values (1000)") + tk.MustExec("insert into t values (1000)") tk.MustQuery("show create table t").Check(testutil.RowsWithSep("|", ""+ "t CREATE TABLE `t` (\n"+ From ce2fe25b71f704a82b4e8cde77085c7bd5cae24a Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Fri, 26 Jun 2020 14:50:45 +0800 Subject: [PATCH 08/33] executor: fix sql Signed-off-by: Rustin-Liu --- executor/show_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/executor/show_test.go b/executor/show_test.go index fdc47709b1d9a..b9d0ffe35847f 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -810,11 +810,12 @@ func (s *testAutoRandomSuite) TestAutoIdCache(c *C) { func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { tk := testkit.NewTestKit(c, s.store) + tk.MustExec("set @@allow_auto_random_explicit_insert = true") tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t (a bigint primary key auto_random(5), b int unique key auto_increment) auto_random_base = 100, auto_increment = 100") - tk.MustExec("insert into t values (1000)") + tk.MustExec("insert into t(`a`) values (1000)") tk.MustQuery("show create table t").Check(testutil.RowsWithSep("|", ""+ "t CREATE TABLE `t` (\n"+ From 7c2bf61b5e040eb44336b5119d915fadb0a0d720 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Fri, 26 Jun 2020 14:57:05 +0800 Subject: [PATCH 09/33] executor: fix assert Signed-off-by: Rustin-Liu --- executor/show_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/executor/show_test.go b/executor/show_test.go index b9d0ffe35847f..166d40f39a628 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -819,10 +819,11 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { tk.MustQuery("show create table t").Check(testutil.RowsWithSep("|", ""+ "t CREATE TABLE `t` (\n"+ - " b` int(11) NOT NULL AUTO_INCREMENT,\n"+ + " `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,\n"+ + " `b` int(11) NOT NULL AUTO_INCREMENT,\n"+ " PRIMARY KEY (`a`),\n"+ " UNIQUE KEY `b` (`b`)\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin1 AUTO_INCREMENT=2000100 /*T![auto_rand_base] AUTO_RANDOM_BASE=2000100 */", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2000100 /*T![auto_rand_base] AUTO_RANDOM_BASE=2000100 */", )) } From 20fe777cdb558e097b3c402354e1881fb7c625b4 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Fri, 26 Jun 2020 15:01:49 +0800 Subject: [PATCH 10/33] executor: fix assert Signed-off-by: Rustin-Liu --- executor/show_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/show_test.go b/executor/show_test.go index 166d40f39a628..1294265bdb929 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -823,7 +823,7 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { " `b` int(11) NOT NULL AUTO_INCREMENT,\n"+ " PRIMARY KEY (`a`),\n"+ " UNIQUE KEY `b` (`b`)\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2000100 /*T![auto_rand_base] AUTO_RANDOM_BASE=2000100 */", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2000100 /*T![auto_rand_base] AUTO_RANDOM_BASE=2000100 */", )) } From 84058292d32cb001c2a8c9eaf923ecc8dad02f66 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Fri, 26 Jun 2020 15:06:32 +0800 Subject: [PATCH 11/33] executor: add more cases Signed-off-by: Rustin-Liu --- executor/show_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/executor/show_test.go b/executor/show_test.go index 1294265bdb929..83de0170c0ead 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -815,6 +815,16 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { tk.MustExec("drop table if exists t") tk.MustExec("create table t (a bigint primary key auto_random(5), b int unique key auto_increment) auto_random_base = 100, auto_increment = 100") + tk.MustQuery("show create table t").Check(testutil.RowsWithSep("|", + ""+ + "t CREATE TABLE `t` (\n"+ + " `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(5) */,\n"+ + " `b` int(11) NOT NULL AUTO_INCREMENT,\n"+ + " PRIMARY KEY (`a`),\n"+ + " UNIQUE KEY `b` (`b`)\n"+ + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=100 /*T![auto_rand_base] AUTO_RANDOM_BASE=100 */", + )) + tk.MustExec("insert into t(`a`) values (1000)") tk.MustQuery("show create table t").Check(testutil.RowsWithSep("|", ""+ From 167cf8d164c27e9690cddf3e5c5b20d5b9b7a61f Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Sun, 28 Jun 2020 21:33:39 +0800 Subject: [PATCH 12/33] executor: use different Allocator Signed-off-by: Rustin-Liu --- executor/show.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/executor/show.go b/executor/show.go index bfdbbaa8797a7..a491d4071c785 100644 --- a/executor/show.go +++ b/executor/show.go @@ -719,7 +719,7 @@ func getDefaultCollate(charsetName string) string { } // ConstructResultOfShowCreateTable constructs the result for show create table. -func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.TableInfo, allocator autoid.Allocator, buf *bytes.Buffer) (err error) { +func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.TableInfo, incrementAllocator autoid.Allocator, randomAllocator autoid.Allocator, buf *bytes.Buffer) (err error) { if tableInfo.IsView() { fetchShowCreateTable4View(ctx, tableInfo, buf) return nil @@ -904,7 +904,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T } if hasAutoIncID { - autoIncID, err := allocator.NextGlobalAutoID(tableInfo.ID) + autoIncID, err := incrementAllocator.NextGlobalAutoID(tableInfo.ID) if err != nil { return errors.Trace(err) } @@ -921,15 +921,13 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T if tableInfo.AutoRandID != 0 { autoRandomBase := tableInfo.AutoRandID - if hasAutoIncID { - autoIncID, err := allocator.NextGlobalAutoID(tableInfo.ID) - if err != nil { - return errors.Trace(err) - } + autoRandID, err := incrementAllocator.NextGlobalAutoID(tableInfo.ID) + if err != nil { + return errors.Trace(err) + } - if autoIncID > 1 { - autoRandomBase = autoIncID - } + if autoRandID > 1 { + autoRandomBase = autoRandID } fmt.Fprintf(buf, " /*T![auto_rand_base] AUTO_RANDOM_BASE=%d */", autoRandomBase) @@ -1026,10 +1024,11 @@ func (e *ShowExec) fetchShowCreateTable() error { } tableInfo := tb.Meta() - allocator := tb.Allocators(e.ctx).Get(autoid.RowIDAllocType) + incrementAllocator := tb.Allocators(e.ctx).Get(autoid.AutoIncrementType) + randomAllocator := tb.Allocators(e.ctx).Get(autoid.AutoRandomType) var buf bytes.Buffer // TODO: let the result more like MySQL. - if err = ConstructResultOfShowCreateTable(e.ctx, tableInfo, allocator, &buf); err != nil { + if err = ConstructResultOfShowCreateTable(e.ctx, tableInfo, incrementAllocator, randomAllocator, &buf); err != nil { return err } if tableInfo.IsView() { From 1c35b2619ca8bd42cff8ed86afab9a218967d589 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Sun, 28 Jun 2020 21:42:42 +0800 Subject: [PATCH 13/33] executor: use different Allocator Signed-off-by: Rustin-Liu --- executor/show.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/executor/show.go b/executor/show.go index a491d4071c785..abab446d91438 100644 --- a/executor/show.go +++ b/executor/show.go @@ -921,13 +921,15 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T if tableInfo.AutoRandID != 0 { autoRandomBase := tableInfo.AutoRandID - autoRandID, err := incrementAllocator.NextGlobalAutoID(tableInfo.ID) - if err != nil { - return errors.Trace(err) - } + if hasAutoIncID { + autoRandID, err := incrementAllocator.NextGlobalAutoID(tableInfo.ID) + if err != nil { + return errors.Trace(err) + } - if autoRandID > 1 { - autoRandomBase = autoRandID + if autoRandID > 1 { + autoRandomBase = autoRandID + } } fmt.Fprintf(buf, " /*T![auto_rand_base] AUTO_RANDOM_BASE=%d */", autoRandomBase) From 6c3769ce230aa93d96a917ea4ca4f31252428fd5 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Sun, 28 Jun 2020 21:46:34 +0800 Subject: [PATCH 14/33] executor: use different Allocator Signed-off-by: Rustin-Liu --- executor/show.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/executor/show.go b/executor/show.go index abab446d91438..bca543836fde9 100644 --- a/executor/show.go +++ b/executor/show.go @@ -921,15 +921,13 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T if tableInfo.AutoRandID != 0 { autoRandomBase := tableInfo.AutoRandID - if hasAutoIncID { - autoRandID, err := incrementAllocator.NextGlobalAutoID(tableInfo.ID) - if err != nil { - return errors.Trace(err) - } + autoRandID, err := randomAllocator.NextGlobalAutoID(tableInfo.ID) + if err != nil { + return errors.Trace(err) + } - if autoRandID > 1 { - autoRandomBase = autoRandID - } + if autoRandID > 1 { + autoRandomBase = autoRandID } fmt.Fprintf(buf, " /*T![auto_rand_base] AUTO_RANDOM_BASE=%d */", autoRandomBase) From 13127ae24211482548b893374814af7b24b7420d Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Sun, 28 Jun 2020 21:52:22 +0800 Subject: [PATCH 15/33] executor: use different Allocator Signed-off-by: Rustin-Liu --- executor/show.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/executor/show.go b/executor/show.go index bca543836fde9..ef7cb08c6390e 100644 --- a/executor/show.go +++ b/executor/show.go @@ -921,13 +921,15 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T if tableInfo.AutoRandID != 0 { autoRandomBase := tableInfo.AutoRandID - autoRandID, err := randomAllocator.NextGlobalAutoID(tableInfo.ID) - if err != nil { - return errors.Trace(err) - } + if randomAllocator != nil { + autoRandID, err := randomAllocator.NextGlobalAutoID(tableInfo.ID) + if err != nil { + return errors.Trace(err) + } - if autoRandID > 1 { - autoRandomBase = autoRandID + if autoRandID > 1 { + autoRandomBase = autoRandID + } } fmt.Fprintf(buf, " /*T![auto_rand_base] AUTO_RANDOM_BASE=%d */", autoRandomBase) From e957c45a4a81178cc73a9ee83ddff3cb20748ea3 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Sun, 28 Jun 2020 22:01:42 +0800 Subject: [PATCH 16/33] executor: use different Allocator Signed-off-by: Rustin-Liu --- executor/show.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/executor/show.go b/executor/show.go index ef7cb08c6390e..9ed7402a2e9b9 100644 --- a/executor/show.go +++ b/executor/show.go @@ -903,7 +903,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T fmt.Fprintf(buf, " COMPRESSION='%s'", tableInfo.Compression) } - if hasAutoIncID { + if hasAutoIncID && incrementAllocator != nil { autoIncID, err := incrementAllocator.NextGlobalAutoID(tableInfo.ID) if err != nil { return errors.Trace(err) @@ -1026,7 +1026,7 @@ func (e *ShowExec) fetchShowCreateTable() error { } tableInfo := tb.Meta() - incrementAllocator := tb.Allocators(e.ctx).Get(autoid.AutoIncrementType) + incrementAllocator := tb.Allocators(e.ctx).Get(autoid.RowIDAllocType) randomAllocator := tb.Allocators(e.ctx).Get(autoid.AutoRandomType) var buf bytes.Buffer // TODO: let the result more like MySQL. From a60b9ced80a110323240f3f1bf227463cac31c86 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Sun, 28 Jun 2020 22:12:17 +0800 Subject: [PATCH 17/33] executor: fix test Signed-off-by: Rustin-Liu --- executor/show_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/show_test.go b/executor/show_test.go index 83de0170c0ead..990dc3a1ecbe9 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -833,7 +833,7 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { " `b` int(11) NOT NULL AUTO_INCREMENT,\n"+ " PRIMARY KEY (`a`),\n"+ " UNIQUE KEY `b` (`b`)\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2000100 /*T![auto_rand_base] AUTO_RANDOM_BASE=2000100 */", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2000100 /*T![auto_rand_base] AUTO_RANDOM_BASE=6001 */", )) } From 1519e56c9a5b6ee956e24b267cf48b93b23fd3f5 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Sun, 28 Jun 2020 22:17:33 +0800 Subject: [PATCH 18/33] executor: refine logic Signed-off-by: Rustin-Liu --- executor/show.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/executor/show.go b/executor/show.go index 9ed7402a2e9b9..dda42e0aff5f2 100644 --- a/executor/show.go +++ b/executor/show.go @@ -918,21 +918,15 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T fmt.Fprintf(buf, " /*T![auto_id_cache] AUTO_ID_CACHE=%d */", tableInfo.AutoIdCache) } - if tableInfo.AutoRandID != 0 { - autoRandomBase := tableInfo.AutoRandID - - if randomAllocator != nil { - autoRandID, err := randomAllocator.NextGlobalAutoID(tableInfo.ID) - if err != nil { - return errors.Trace(err) - } - - if autoRandID > 1 { - autoRandomBase = autoRandID - } + if randomAllocator != nil { + autoRandID, err := randomAllocator.NextGlobalAutoID(tableInfo.ID) + if err != nil { + return errors.Trace(err) } - fmt.Fprintf(buf, " /*T![auto_rand_base] AUTO_RANDOM_BASE=%d */", autoRandomBase) + if autoRandID > 1 { + fmt.Fprintf(buf, " /*T![auto_rand_base] AUTO_RANDOM_BASE=%d */", autoRandID) + } } if tableInfo.ShardRowIDBits > 0 { From a061b04542519c44a693436514675c2db4c9cea8 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 10:01:48 +0800 Subject: [PATCH 19/33] executor: refine logic Signed-off-by: Rustin-Liu --- executor/show.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/executor/show.go b/executor/show.go index dda42e0aff5f2..b99ce88308967 100644 --- a/executor/show.go +++ b/executor/show.go @@ -719,7 +719,7 @@ func getDefaultCollate(charsetName string) string { } // ConstructResultOfShowCreateTable constructs the result for show create table. -func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.TableInfo, incrementAllocator autoid.Allocator, randomAllocator autoid.Allocator, buf *bytes.Buffer) (err error) { +func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.TableInfo, allocators autoid.Allocators, buf *bytes.Buffer) (err error) { if tableInfo.IsView() { fetchShowCreateTable4View(ctx, tableInfo, buf) return nil @@ -903,6 +903,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T fmt.Fprintf(buf, " COMPRESSION='%s'", tableInfo.Compression) } + incrementAllocator := allocators.Get(autoid.AutoIncrementType) if hasAutoIncID && incrementAllocator != nil { autoIncID, err := incrementAllocator.NextGlobalAutoID(tableInfo.ID) if err != nil { @@ -918,6 +919,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T fmt.Fprintf(buf, " /*T![auto_id_cache] AUTO_ID_CACHE=%d */", tableInfo.AutoIdCache) } + randomAllocator := allocators.Get(autoid.AutoRandomType) if randomAllocator != nil { autoRandID, err := randomAllocator.NextGlobalAutoID(tableInfo.ID) if err != nil { @@ -1020,11 +1022,9 @@ func (e *ShowExec) fetchShowCreateTable() error { } tableInfo := tb.Meta() - incrementAllocator := tb.Allocators(e.ctx).Get(autoid.RowIDAllocType) - randomAllocator := tb.Allocators(e.ctx).Get(autoid.AutoRandomType) var buf bytes.Buffer // TODO: let the result more like MySQL. - if err = ConstructResultOfShowCreateTable(e.ctx, tableInfo, incrementAllocator, randomAllocator, &buf); err != nil { + if err = ConstructResultOfShowCreateTable(e.ctx, tableInfo, tb.Allocators(e.ctx), &buf); err != nil { return err } if tableInfo.IsView() { From 79b6a2da3c52cdba34f08a8fad704a4814ff575e Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 10:30:13 +0800 Subject: [PATCH 20/33] executor: fix type Signed-off-by: Rustin-Liu --- executor/show.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/show.go b/executor/show.go index b99ce88308967..50ce2f3d26449 100644 --- a/executor/show.go +++ b/executor/show.go @@ -903,7 +903,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T fmt.Fprintf(buf, " COMPRESSION='%s'", tableInfo.Compression) } - incrementAllocator := allocators.Get(autoid.AutoIncrementType) + incrementAllocator := allocators.Get(autoid.RowIDAllocType) if hasAutoIncID && incrementAllocator != nil { autoIncID, err := incrementAllocator.NextGlobalAutoID(tableInfo.ID) if err != nil { From 51f8084359adfa16dfe8dccdcfcd81aff4b0aa31 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 10:37:59 +0800 Subject: [PATCH 21/33] executor: add blank line Signed-off-by: Rustin-Liu --- executor/show.go | 1 + 1 file changed, 1 insertion(+) diff --git a/executor/show.go b/executor/show.go index 50ce2f3d26449..16263a9c948cc 100644 --- a/executor/show.go +++ b/executor/show.go @@ -909,6 +909,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T if err != nil { return errors.Trace(err) } + // It's compatible with MySQL. if autoIncID > 1 { fmt.Fprintf(buf, " AUTO_INCREMENT=%d", autoIncID) From f10b42fb2a70926c49c3215fbf3e58f7fb439c02 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 10:54:36 +0800 Subject: [PATCH 22/33] executor: add test config Signed-off-by: Rustin-Liu --- executor/show_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/executor/show_test.go b/executor/show_test.go index 990dc3a1ecbe9..fc1171712ab2d 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -813,6 +813,9 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { tk.MustExec("set @@allow_auto_random_explicit_insert = true") tk.MustExec("use test") + testutil.ConfigTestUtils.SetupAutoRandomTestConfig() + defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() + tk.MustExec("drop table if exists t") tk.MustExec("create table t (a bigint primary key auto_random(5), b int unique key auto_increment) auto_random_base = 100, auto_increment = 100") tk.MustQuery("show create table t").Check(testutil.RowsWithSep("|", From a72f5bd65c4551eebbc411ed16d10ec31d7150ef Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 17:40:07 +0800 Subject: [PATCH 23/33] executor: add test setup and Teardown Signed-off-by: Rustin-Liu --- executor/ddl_test.go | 9 +++++++++ executor/show_test.go | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/executor/ddl_test.go b/executor/ddl_test.go index c4f0eb3921239..4853a33a4e842 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -834,7 +834,16 @@ type testAutoRandomSuite struct { *baseTestSuite } +func (s *testAutoRandomSuite)SetupTest() { + testutil.ConfigTestUtils.SetupAutoRandomTestConfig() +} + +func(s *testAutoRandomSuite)TeardownTest(){ + testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() +} + func (s *testAutoRandomSuite) TestAutoRandomBitsData(c *C) { + s.SetUpSuite(c); tk := testkit.NewTestKit(c, s.store) tk.MustExec("create database if not exists test_auto_random_bits") diff --git a/executor/show_test.go b/executor/show_test.go index fc1171712ab2d..d9d2222b4ad03 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -813,8 +813,8 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { tk.MustExec("set @@allow_auto_random_explicit_insert = true") tk.MustExec("use test") - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() + s.SetupTest() + defer s.TeardownTest() tk.MustExec("drop table if exists t") tk.MustExec("create table t (a bigint primary key auto_random(5), b int unique key auto_increment) auto_random_base = 100, auto_increment = 100") From 582f249dc821ccd5ab6d9bd2f5d824ac5417a0fb Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 17:43:38 +0800 Subject: [PATCH 24/33] executor: use test setup and Teardown Signed-off-by: Rustin-Liu --- executor/ddl_test.go | 12 ++++++------ executor/show_test.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/executor/ddl_test.go b/executor/ddl_test.go index 4853a33a4e842..54e423c472c85 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -857,8 +857,8 @@ func (s *testAutoRandomSuite) TestAutoRandomBitsData(c *C) { return allHds } - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() + s.SetupTest() + defer s.TeardownTest() tk.MustExec("set @@allow_auto_random_explicit_insert = true") tk.MustExec("create table t (a bigint primary key auto_random(15), b int)") @@ -980,8 +980,8 @@ func (s *testAutoRandomSuite) TestAutoRandomTableOption(c *C) { tk.MustExec("use test") // test table option is auto-random - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() + s.SetupTest() + defer s.TeardownTest() tk.MustExec("drop table if exists auto_random_table_option") tk.MustExec("create table auto_random_table_option (a bigint auto_random(5) key) auto_random_base = 1000") @@ -1051,8 +1051,8 @@ func (s *testAutoRandomSuite) TestFilterDifferentAllocators(c *C) { tk.MustExec("drop table if exists t") tk.MustExec("drop table if exists t1") - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() + s.SetupTest() + defer s.TeardownTest() tk.MustExec("create table t(a bigint auto_random(5) key, b int auto_increment unique)") tk.MustExec("insert into t values()") diff --git a/executor/show_test.go b/executor/show_test.go index d9d2222b4ad03..060c0303fa3bb 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -707,8 +707,8 @@ func (s *testAutoRandomSuite) TestShowCreateTableAutoRandom(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") - testutil.ConfigTestUtils.SetupAutoRandomTestConfig() - defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() + s.SetupTest() + defer s.TeardownTest() // Basic show create table. tk.MustExec("create table auto_random_tbl1 (a bigint primary key auto_random(3), b varchar(255))") From b83070314ec37b59026831920b492b8be923d9d2 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 18:13:28 +0800 Subject: [PATCH 25/33] executor: remove useless code Signed-off-by: Rustin-Liu --- executor/ddl_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/executor/ddl_test.go b/executor/ddl_test.go index 54e423c472c85..48e24620df775 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -843,7 +843,6 @@ func(s *testAutoRandomSuite)TeardownTest(){ } func (s *testAutoRandomSuite) TestAutoRandomBitsData(c *C) { - s.SetUpSuite(c); tk := testkit.NewTestKit(c, s.store) tk.MustExec("create database if not exists test_auto_random_bits") From 5e56a80648c08298cd74925f0bde81bea82f5c54 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 19:05:15 +0800 Subject: [PATCH 26/33] executor: add failed point mock Signed-off-by: Rustin-Liu --- executor/show_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/executor/show_test.go b/executor/show_test.go index 060c0303fa3bb..4dd74190d67b4 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -16,6 +16,7 @@ package executor_test import ( "context" "fmt" + "github.com/pingcap/failpoint" . "github.com/pingcap/check" "github.com/pingcap/errors" @@ -809,6 +810,11 @@ func (s *testAutoRandomSuite) TestAutoIdCache(c *C) { } func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { + c.Assert(failpoint.Enable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange", `return(true)`), IsNil) + defer func() { + c.Assert(failpoint.Disable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange"), IsNil) + }() + tk := testkit.NewTestKit(c, s.store) tk.MustExec("set @@allow_auto_random_explicit_insert = true") tk.MustExec("use test") From b1560532e4559cdfdea6b64606e2de72e2799fed Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 19:16:57 +0800 Subject: [PATCH 27/33] executor: remove failed point mock Signed-off-by: Rustin-Liu --- executor/show_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/executor/show_test.go b/executor/show_test.go index 4dd74190d67b4..5422d6234dc9e 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -810,11 +810,6 @@ func (s *testAutoRandomSuite) TestAutoIdCache(c *C) { } func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { - c.Assert(failpoint.Enable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange", `return(true)`), IsNil) - defer func() { - c.Assert(failpoint.Disable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange"), IsNil) - }() - tk := testkit.NewTestKit(c, s.store) tk.MustExec("set @@allow_auto_random_explicit_insert = true") tk.MustExec("use test") From 606e3cf69fbb2d4105288b2849ab0c58abd877f8 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 19:22:13 +0800 Subject: [PATCH 28/33] executor: fix fmt Signed-off-by: Rustin-Liu --- executor/ddl_test.go | 4 ++-- executor/show_test.go | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/executor/ddl_test.go b/executor/ddl_test.go index 48e24620df775..58b9133634e7a 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -834,11 +834,11 @@ type testAutoRandomSuite struct { *baseTestSuite } -func (s *testAutoRandomSuite)SetupTest() { +func (s *testAutoRandomSuite) SetupTest() { testutil.ConfigTestUtils.SetupAutoRandomTestConfig() } -func(s *testAutoRandomSuite)TeardownTest(){ +func (s *testAutoRandomSuite) TeardownTest() { testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() } diff --git a/executor/show_test.go b/executor/show_test.go index 5422d6234dc9e..70449e42b9c5e 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -16,8 +16,6 @@ package executor_test import ( "context" "fmt" - "github.com/pingcap/failpoint" - . "github.com/pingcap/check" "github.com/pingcap/errors" "github.com/pingcap/parser/auth" @@ -814,7 +812,7 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { tk.MustExec("set @@allow_auto_random_explicit_insert = true") tk.MustExec("use test") - s.SetupTest() + s.SetupTest() defer s.TeardownTest() tk.MustExec("drop table if exists t") From d12e6c380330216612a4a9197166ce1e1fe6f082 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 19:38:31 +0800 Subject: [PATCH 29/33] executor: fix fmt Signed-off-by: Rustin-Liu --- executor/show_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/executor/show_test.go b/executor/show_test.go index 70449e42b9c5e..fdfad5541e49b 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -16,6 +16,7 @@ package executor_test import ( "context" "fmt" + . "github.com/pingcap/check" "github.com/pingcap/errors" "github.com/pingcap/parser/auth" From 7f07d693047f06889f57a9f5101964964524b56d Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 20:36:22 +0800 Subject: [PATCH 30/33] executor: add failed point mock Signed-off-by: Rustin-Liu --- executor/show_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/executor/show_test.go b/executor/show_test.go index fdfad5541e49b..dfb8aab6bf44a 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -16,6 +16,7 @@ package executor_test import ( "context" "fmt" + "github.com/pingcap/failpoint" . "github.com/pingcap/check" "github.com/pingcap/errors" @@ -809,6 +810,11 @@ func (s *testAutoRandomSuite) TestAutoIdCache(c *C) { } func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { + c.Assert(failpoint.Enable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange", `return(true)`), IsNil) + defer func() { + c.Assert(failpoint.Disable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange"), IsNil) + }() + tk := testkit.NewTestKit(c, s.store) tk.MustExec("set @@allow_auto_random_explicit_insert = true") tk.MustExec("use test") @@ -836,7 +842,7 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { " `b` int(11) NOT NULL AUTO_INCREMENT,\n"+ " PRIMARY KEY (`a`),\n"+ " UNIQUE KEY `b` (`b`)\n"+ - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=2000100 /*T![auto_rand_base] AUTO_RANDOM_BASE=6001 */", + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=5100 /*T![auto_rand_base] AUTO_RANDOM_BASE=6001 */", )) } From 11cd87ee3c11a6f46829b36247b23ef4bce5e8e6 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 20:40:02 +0800 Subject: [PATCH 31/33] executor: fix fmt Signed-off-by: Rustin-Liu --- executor/show_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/show_test.go b/executor/show_test.go index dfb8aab6bf44a..a3df937e6137f 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -16,10 +16,10 @@ package executor_test import ( "context" "fmt" - "github.com/pingcap/failpoint" . "github.com/pingcap/check" "github.com/pingcap/errors" + "github.com/pingcap/failpoint" "github.com/pingcap/parser/auth" "github.com/pingcap/parser/model" "github.com/pingcap/parser/mysql" From 77cb5040e985cd6a0b24b2ffdb412a2dd89cab04 Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 22:09:15 +0800 Subject: [PATCH 32/33] executor: using fixtures Signed-off-by: Rustin-Liu --- executor/ddl_test.go | 12 ++---------- executor/show_test.go | 6 ------ 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/executor/ddl_test.go b/executor/ddl_test.go index 58b9133634e7a..677cdccf54d96 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -834,11 +834,11 @@ type testAutoRandomSuite struct { *baseTestSuite } -func (s *testAutoRandomSuite) SetupTest() { +func (s *testAutoRandomSuite) SetUpTest() { testutil.ConfigTestUtils.SetupAutoRandomTestConfig() } -func (s *testAutoRandomSuite) TeardownTest() { +func (s *testAutoRandomSuite) TearDownTest() { testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() } @@ -856,8 +856,6 @@ func (s *testAutoRandomSuite) TestAutoRandomBitsData(c *C) { return allHds } - s.SetupTest() - defer s.TeardownTest() tk.MustExec("set @@allow_auto_random_explicit_insert = true") tk.MustExec("create table t (a bigint primary key auto_random(15), b int)") @@ -979,9 +977,6 @@ func (s *testAutoRandomSuite) TestAutoRandomTableOption(c *C) { tk.MustExec("use test") // test table option is auto-random - s.SetupTest() - defer s.TeardownTest() - tk.MustExec("drop table if exists auto_random_table_option") tk.MustExec("create table auto_random_table_option (a bigint auto_random(5) key) auto_random_base = 1000") t, err := domain.GetDomain(tk.Se).InfoSchema().TableByName(model.NewCIStr("test"), model.NewCIStr("auto_random_table_option")) @@ -1050,9 +1045,6 @@ func (s *testAutoRandomSuite) TestFilterDifferentAllocators(c *C) { tk.MustExec("drop table if exists t") tk.MustExec("drop table if exists t1") - s.SetupTest() - defer s.TeardownTest() - tk.MustExec("create table t(a bigint auto_random(5) key, b int auto_increment unique)") tk.MustExec("insert into t values()") tk.MustQuery("select b from t").Check(testkit.Rows("1")) diff --git a/executor/show_test.go b/executor/show_test.go index a3df937e6137f..28a033b9d1941 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -708,9 +708,6 @@ func (s *testAutoRandomSuite) TestShowCreateTableAutoRandom(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") - s.SetupTest() - defer s.TeardownTest() - // Basic show create table. tk.MustExec("create table auto_random_tbl1 (a bigint primary key auto_random(3), b varchar(255))") tk.MustQuery("show create table `auto_random_tbl1`").Check(testutil.RowsWithSep("|", @@ -819,9 +816,6 @@ func (s *testAutoRandomSuite) TestAutoRandomBase(c *C) { tk.MustExec("set @@allow_auto_random_explicit_insert = true") tk.MustExec("use test") - s.SetupTest() - defer s.TeardownTest() - tk.MustExec("drop table if exists t") tk.MustExec("create table t (a bigint primary key auto_random(5), b int unique key auto_increment) auto_random_base = 100, auto_increment = 100") tk.MustQuery("show create table t").Check(testutil.RowsWithSep("|", From b5094f3d5e663c0f6e64d0f99a656d852abd5deb Mon Sep 17 00:00:00 2001 From: Rustin-Liu Date: Mon, 29 Jun 2020 22:14:15 +0800 Subject: [PATCH 33/33] executor: using fixtures Signed-off-by: Rustin-Liu --- executor/ddl_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/executor/ddl_test.go b/executor/ddl_test.go index 677cdccf54d96..eec049e51f3d1 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -834,11 +834,11 @@ type testAutoRandomSuite struct { *baseTestSuite } -func (s *testAutoRandomSuite) SetUpTest() { +func (s *testAutoRandomSuite) SetUpTest(c *C) { testutil.ConfigTestUtils.SetupAutoRandomTestConfig() } -func (s *testAutoRandomSuite) TearDownTest() { +func (s *testAutoRandomSuite) TearDownTest(c *C) { testutil.ConfigTestUtils.RestoreAutoRandomTestConfig() }