@@ -15,6 +15,7 @@ package executor_test
1515
1616import (
1717 . "github.com/pingcap/check"
18+ "github.com/pingcap/tidb/meta/autoid"
1819 "github.com/pingcap/tidb/model"
1920 "github.com/pingcap/tidb/table/tables"
2021 "github.com/pingcap/tidb/types"
@@ -458,3 +459,45 @@ func (s *testSuite) TestAdminCheckTable(c *C) {
458459 tk .MustExec (`ALTER TABLE t1 ADD INDEX idx6 (c6)` )
459460 tk .MustExec (`admin check table t1` )
460461}
462+
463+ func (s * testSuite ) TestAdminShowNextID (c * C ) {
464+ step := int64 (10 )
465+ autoIDStep := autoid .GetStep ()
466+ autoid .SetStep (step )
467+ defer autoid .SetStep (autoIDStep )
468+ tk := testkit .NewTestKit (c , s .store )
469+ tk .MustExec ("use test" )
470+ tk .MustExec ("create table t(id int, c int)" )
471+ // Start handle is 1.
472+ r := tk .MustQuery ("admin show t next_row_id" )
473+ r .Check (testkit .Rows ("test t _tidb_rowid 1" ))
474+ // Row ID is step + 1.
475+ tk .MustExec ("insert into t values(1, 1)" )
476+ r = tk .MustQuery ("admin show t next_row_id" )
477+ r .Check (testkit .Rows ("test t _tidb_rowid 11" ))
478+ // Row ID is original + step.
479+ for i := 0 ; i < int (step ); i ++ {
480+ tk .MustExec ("insert into t values(10000, 1)" )
481+ }
482+ r = tk .MustQuery ("admin show t next_row_id" )
483+ r .Check (testkit .Rows ("test t _tidb_rowid 21" ))
484+
485+ // test for a table with the primary key
486+ tk .MustExec ("create table tt(id int primary key auto_increment, c int)" )
487+ // Start handle is 1.
488+ r = tk .MustQuery ("admin show tt next_row_id" )
489+ r .Check (testkit .Rows ("test tt id 1" ))
490+ // After rebasing auto ID, row ID is 20 + step + 1.
491+ tk .MustExec ("insert into tt values(20, 1)" )
492+ r = tk .MustQuery ("admin show tt next_row_id" )
493+ r .Check (testkit .Rows ("test tt id 31" ))
494+ // test for renaming the table
495+ tk .MustExec ("create database test1" )
496+ tk .MustExec ("rename table test.tt to test1.tt" )
497+ tk .MustExec ("use test1" )
498+ r = tk .MustQuery ("admin show tt next_row_id" )
499+ r .Check (testkit .Rows ("test1 tt id 31" ))
500+ tk .MustExec ("insert test1.tt values ()" )
501+ r = tk .MustQuery ("admin show tt next_row_id" )
502+ r .Check (testkit .Rows ("test1 tt id 41" ))
503+ }
0 commit comments