Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: separate auto_increment ID allocator from _tidb_rowid allocator when AUTO_ID_CACHE=1 #39041

Merged
merged 33 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8b23a8a
save
tiancaiamao Nov 9, 2022
416e758
save
tiancaiamao Nov 9, 2022
e3cf9f3
save again
tiancaiamao Nov 9, 2022
4aca589
add tests
tiancaiamao Nov 10, 2022
ccc647e
update test
tiancaiamao Nov 10, 2022
f3f14ff
cleanup
tiancaiamao Nov 10, 2022
b5fc7b4
handle 'admin show next_row_id'
tiancaiamao Nov 11, 2022
bd43d92
fix case TestAutoRandomChangeFromAutoInc
tiancaiamao Nov 11, 2022
166a4c9
fix TestExchangePartitionAutoID
tiancaiamao Nov 11, 2022
5e3e7b3
fix test case TestAdminShowNextID
tiancaiamao Nov 12, 2022
1a073fa
Merge branch 'master' into autoid-not-rowid
tiancaiamao Nov 12, 2022
402ab20
make bazel_prepare
tiancaiamao Nov 12, 2022
976f54b
fix case TestAutoIncrementIDOnTemporaryTable
tiancaiamao Nov 12, 2022
877a86d
fix mysql-test
tiancaiamao Nov 15, 2022
6419f7c
Merge branch 'master' into autoid-not-rowid
tiancaiamao Nov 15, 2022
a2b9cb6
fix build
tiancaiamao Nov 15, 2022
7ca9505
make fmt
tiancaiamao Nov 15, 2022
069a858
address comment
tiancaiamao Nov 28, 2022
acd5e48
Merge branch 'master' into autoid-not-rowid
tiancaiamao Nov 28, 2022
3f4c3b6
Merge branch 'master' into autoid-not-rowid
tiancaiamao Nov 28, 2022
14b7bf9
fix CI
tiancaiamao Nov 28, 2022
d11e237
update test case for the changes
tiancaiamao Nov 29, 2022
e9c0fb5
Merge branch 'master' into autoid-not-rowid
tiancaiamao Nov 29, 2022
b08b9fb
fix build
tiancaiamao Nov 29, 2022
fded827
fix build
tiancaiamao Nov 29, 2022
90ab5fa
fix CI
tiancaiamao Nov 29, 2022
e5daacf
Merge branch 'master' into autoid-not-rowid
ti-chi-bot Nov 29, 2022
c02f95e
Merge branch 'master' into autoid-not-rowid
ti-chi-bot Nov 29, 2022
0d4a0b9
Merge branch 'master' into autoid-not-rowid
ti-chi-bot Nov 29, 2022
3ce5231
Merge branch 'master' into autoid-not-rowid
ti-chi-bot Nov 29, 2022
09674e5
Merge branch 'master' into autoid-not-rowid
ti-chi-bot Nov 29, 2022
9fff691
Merge branch 'master' into autoid-not-rowid
ti-chi-bot Nov 29, 2022
3627e40
Merge branch 'master' into autoid-not-rowid
ti-chi-bot Nov 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions autoid_service/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
"//meta",
"//metrics",
"//owner",
"//parser/model",
"//util/logutil",
"//util/mathutil",
"@com_github_pingcap_errors//:errors",
Expand Down
11 changes: 6 additions & 5 deletions autoid_service/autoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/owner"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/mathutil"
clientv3 "go.etcd.io/etcd/client/v3"
Expand Down Expand Up @@ -76,7 +77,7 @@ func (alloc *autoIDValue) alloc4Unsigned(ctx context.Context, store kv.Storage,

ctx = kv.WithInternalSourceType(ctx, kv.InternalTxnMeta)
err := kv.RunInNewTxn(ctx, store, true, func(ctx context.Context, txn kv.Transaction) error {
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).RowID()
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).IncrementID(model.TableInfoVersion5)
var err1 error
newBase, err1 = idAcc.Get()
if err1 != nil {
Expand Down Expand Up @@ -137,7 +138,7 @@ func (alloc *autoIDValue) alloc4Signed(ctx context.Context,

ctx = kv.WithInternalSourceType(ctx, kv.InternalTxnMeta)
err := kv.RunInNewTxn(ctx, store, true, func(ctx context.Context, txn kv.Transaction) error {
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).RowID()
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).IncrementID(model.TableInfoVersion5)
var err1 error
newBase, err1 = idAcc.Get()
if err1 != nil {
Expand Down Expand Up @@ -188,7 +189,7 @@ func (alloc *autoIDValue) rebase4Unsigned(ctx context.Context,
startTime := time.Now()
ctx = kv.WithInternalSourceType(ctx, kv.InternalTxnMeta)
err := kv.RunInNewTxn(ctx, store, true, func(ctx context.Context, txn kv.Transaction) error {
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).RowID()
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).IncrementID(model.TableInfoVersion5)
currentEnd, err1 := idAcc.Get()
if err1 != nil {
return err1
Expand Down Expand Up @@ -221,7 +222,7 @@ func (alloc *autoIDValue) rebase4Signed(ctx context.Context, store kv.Storage, d
var newBase, newEnd int64
ctx = kv.WithInternalSourceType(ctx, kv.InternalTxnMeta)
err := kv.RunInNewTxn(ctx, store, true, func(ctx context.Context, txn kv.Transaction) error {
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).RowID()
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).IncrementID(model.TableInfoVersion5)
currentEnd, err1 := idAcc.Get()
if err1 != nil {
return err1
Expand Down Expand Up @@ -451,7 +452,7 @@ func (s *Service) allocAutoID(ctx context.Context, req *autoid.AutoIDRequest) (*
func (alloc *autoIDValue) forceRebase(ctx context.Context, store kv.Storage, dbID, tblID, requiredBase int64, isUnsigned bool) error {
ctx = kv.WithInternalSourceType(ctx, kv.InternalTxnMeta)
err := kv.RunInNewTxn(ctx, store, true, func(ctx context.Context, txn kv.Transaction) error {
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).RowID()
idAcc := meta.NewMeta(txn).GetAutoIDAccessors(dbID, tblID).IncrementID(model.TableInfoVersion5)
currentEnd, err1 := idAcc.Get()
if err1 != nil {
return err1
Expand Down
1 change: 1 addition & 0 deletions br/pkg/lightning/backend/kv/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type panickingAllocator struct {
func NewPanickingAllocators(base int64) autoid.Allocators {
sharedBase := &base
return autoid.NewAllocators(
false,
&panickingAllocator{base: sharedBase, ty: autoid.RowIDAllocType},
&panickingAllocator{base: sharedBase, ty: autoid.AutoIncrementType},
&panickingAllocator{base: sharedBase, ty: autoid.AutoRandomType},
Expand Down
10 changes: 7 additions & 3 deletions ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@ func checkAndApplyAutoRandomBits(d *ddlCtx, m *meta.Meta, dbInfo *model.DBInfo,
return nil
}
idAcc := m.GetAutoIDAccessors(dbInfo.ID, tblInfo.ID)
err := checkNewAutoRandomBits(idAcc, oldCol, newCol, newAutoRandBits, tblInfo.AutoRandomRangeBits, tblInfo.Version)
err := checkNewAutoRandomBits(idAcc, oldCol, newCol, newAutoRandBits, tblInfo.AutoRandomRangeBits, tblInfo.SepAutoInc())
if err != nil {
return err
}
Expand All @@ -1534,13 +1534,17 @@ func checkAndApplyAutoRandomBits(d *ddlCtx, m *meta.Meta, dbInfo *model.DBInfo,

// checkNewAutoRandomBits checks whether the new auto_random bits number can cause overflow.
func checkNewAutoRandomBits(idAccessors meta.AutoIDAccessors, oldCol *model.ColumnInfo,
newCol *model.ColumnInfo, newShardBits, newRangeBits uint64, tblVer uint16) error {
newCol *model.ColumnInfo, newShardBits, newRangeBits uint64, sepAutoInc bool) error {
shardFmt := autoid.NewShardIDFormat(&newCol.FieldType, newShardBits, newRangeBits)

idAcc := idAccessors.RandomID()
convertedFromAutoInc := mysql.HasAutoIncrementFlag(oldCol.GetFlag())
if convertedFromAutoInc {
idAcc = idAccessors.IncrementID(tblVer)
if sepAutoInc {
idAcc = idAccessors.IncrementID(model.TableInfoVersion5)
} else {
idAcc = idAccessors.RowID()
}
}
// Generate a new auto ID first to prevent concurrent update in DML.
_, err := idAcc.Inc(1)
Expand Down
8 changes: 4 additions & 4 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,11 +898,11 @@ func TestAutoIncrementIDOnTemporaryTable(t *testing.T) {
tk.MustExec("drop table if exists global_temp_auto_id")
tk.MustExec("create global temporary table global_temp_auto_id(id int primary key auto_increment) on commit delete rows")
tk.MustExec("begin")
tk.MustQuery("show table global_temp_auto_id next_row_id").Check(testkit.Rows("test global_temp_auto_id id 1 AUTO_INCREMENT"))
tk.MustQuery("show table global_temp_auto_id next_row_id").Check(testkit.Rows("test global_temp_auto_id id 1 _TIDB_ROWID"))
tk.MustExec("insert into global_temp_auto_id value(null)")
tk.MustQuery("select @@last_insert_id").Check(testkit.Rows("1"))
tk.MustQuery("select id from global_temp_auto_id").Check(testkit.Rows("1"))
tk.MustQuery("show table global_temp_auto_id next_row_id").Check(testkit.Rows("test global_temp_auto_id id 2 AUTO_INCREMENT"))
tk.MustQuery("show table global_temp_auto_id next_row_id").Check(testkit.Rows("test global_temp_auto_id id 2 _TIDB_ROWID"))
tk.MustExec("commit")
tk.MustExec("drop table global_temp_auto_id")

Expand All @@ -914,12 +914,12 @@ func TestAutoIncrementIDOnTemporaryTable(t *testing.T) {
" `id` int(11) NOT NULL AUTO_INCREMENT,\n" +
" PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=100 ON COMMIT DELETE ROWS"))
tk.MustQuery("show table global_temp_auto_id next_row_id").Check(testkit.Rows("test global_temp_auto_id id 100 AUTO_INCREMENT"))
tk.MustQuery("show table global_temp_auto_id next_row_id").Check(testkit.Rows("test global_temp_auto_id id 100 _TIDB_ROWID"))
tk.MustExec("begin")
tk.MustExec("insert into global_temp_auto_id value(null)")
tk.MustQuery("select @@last_insert_id").Check(testkit.Rows("100"))
tk.MustQuery("select id from global_temp_auto_id").Check(testkit.Rows("100"))
tk.MustQuery("show table global_temp_auto_id next_row_id").Check(testkit.Rows("test global_temp_auto_id id 101 AUTO_INCREMENT"))
tk.MustQuery("show table global_temp_auto_id next_row_id").Check(testkit.Rows("test global_temp_auto_id id 101 _TIDB_ROWID"))
tk.MustExec("commit")
}
tk.MustExec("drop table global_temp_auto_id")
Expand Down
12 changes: 10 additions & 2 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2147,7 +2147,7 @@ func checkPartitionDefinitionConstraints(ctx sessionctx.Context, tbInfo *model.T

// checkTableInfoValid uses to check table info valid. This is used to validate table info.
func checkTableInfoValid(tblInfo *model.TableInfo) error {
_, err := tables.TableFromMeta(nil, tblInfo)
_, err := tables.TableFromMeta(autoid.NewAllocators(false), tblInfo)
if err != nil {
return err
}
Expand Down Expand Up @@ -2484,7 +2484,13 @@ func (d *ddl) createTableWithInfoPost(
// Default tableAutoIncID base is 0.
// If the first ID is expected to greater than 1, we need to do rebase.
newEnd := tbInfo.AutoIncID - 1
if err = d.handleAutoIncID(tbInfo, schemaID, newEnd, autoid.RowIDAllocType); err != nil {
var allocType autoid.AllocatorType
if tbInfo.SepAutoInc() {
allocType = autoid.AutoIncrementType
} else {
allocType = autoid.RowIDAllocType
}
if err = d.handleAutoIncID(tbInfo, schemaID, newEnd, allocType); err != nil {
return errors.Trace(err)
}
}
Expand Down Expand Up @@ -3446,6 +3452,8 @@ func (d *ddl) RebaseAutoID(ctx sessionctx.Context, ident ast.Ident, newBase int6
actionType = model.ActionRebaseAutoRandomBase
case autoid.RowIDAllocType:
actionType = model.ActionRebaseAutoID
default:
panic(fmt.Sprintf("unimplemented rebase autoid type %s", tp))
}

if !force {
Expand Down
2 changes: 1 addition & 1 deletion ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ func (w *worker) runDDLJob(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64,
case model.ActionTruncateTable:
ver, err = onTruncateTable(d, t, job)
case model.ActionRebaseAutoID:
ver, err = onRebaseRowIDType(d, t, job)
ver, err = onRebaseAutoIncrementIDType(d, t, job)
case model.ActionRebaseAutoRandomBase:
ver, err = onRebaseAutoRandomType(d, t, job)
case model.ActionRenameTable:
Expand Down
2 changes: 1 addition & 1 deletion ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -2077,7 +2077,7 @@ func (w *worker) onExchangeTablePartition(d *ddlCtx, t *meta.Meta, job *model.Jo
failpoint.Return(ver, err)
}
sess := newSession(se)
_, err = sess.execute(context.Background(), "insert into test.pt values (40000000)", "exchange_partition_test")
_, err = sess.execute(context.Background(), "insert ignore into test.pt values (40000000)", "exchange_partition_test")
if err != nil {
failpoint.Return(ver, err)
}
Expand Down
6 changes: 3 additions & 3 deletions ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,8 @@ func onTruncateTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ erro
return ver, nil
}

func onRebaseRowIDType(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) {
return onRebaseAutoID(d, d.store, t, job, autoid.RowIDAllocType)
func onRebaseAutoIncrementIDType(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) {
return onRebaseAutoID(d, d.store, t, job, autoid.AutoIncrementType)
}

func onRebaseAutoRandomType(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) {
Expand Down Expand Up @@ -862,7 +862,7 @@ func onRebaseAutoID(d *ddlCtx, store kv.Storage, t *meta.Meta, job *model.Job, t
newBase = newBaseTemp
}

if tp == autoid.RowIDAllocType {
if tp == autoid.AutoIncrementType {
tblInfo.AutoIncID = newBase
} else {
tblInfo.AutoRandID = newBase
Expand Down
2 changes: 1 addition & 1 deletion ddl/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func testGetTableWithError(store kv.Storage, schemaID, tableID int64) (table.Tab
return nil, errors.New("table not found")
}
alloc := autoid.NewAllocator(store, schemaID, tblInfo.ID, false, autoid.RowIDAllocType)
tbl, err := table.TableFromMeta(autoid.NewAllocators(alloc), tblInfo)
tbl, err := table.TableFromMeta(autoid.NewAllocators(false, alloc), tblInfo)
if err != nil {
return nil, errors.Trace(err)
}
Expand Down
13 changes: 11 additions & 2 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,24 @@ func (e *ShowNextRowIDExec) Next(ctx context.Context, req *chunk.Chunk) error {
tblMeta := tbl.Meta()

allocators := tbl.Allocators(e.ctx)
for _, alloc := range allocators {
for _, alloc := range allocators.Allocs {
nextGlobalID, err := alloc.NextGlobalAutoID()
if err != nil {
return err
}

var colName, idType string
switch alloc.GetType() {
case autoid.RowIDAllocType, autoid.AutoIncrementType:
case autoid.RowIDAllocType:
idType = "_TIDB_ROWID"
if tblMeta.PKIsHandle {
if col := tblMeta.GetAutoIncrementColInfo(); col != nil {
colName = col.Name.O
}
} else {
colName = model.ExtraHandleName.O
}
case autoid.AutoIncrementType:
idType = "AUTO_INCREMENT"
if tblMeta.PKIsHandle {
if col := tblMeta.GetAutoIncrementColInfo(); col != nil {
Expand Down
43 changes: 43 additions & 0 deletions executor/executor_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1237,3 +1237,46 @@ func TestIssue33214(t *testing.T) {
}
}
}

func TestIssue982(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (c int auto_increment, key(c)) auto_id_cache 1;")
tk.MustExec("insert into t values();")
tk.MustExec("insert into t values();")
tk.MustQuery("select * from t;").Check(testkit.Rows("1", "2"))
}

func TestIssue24627(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
for _, sql := range []string{
"create table test(id float primary key clustered AUTO_INCREMENT, col1 int);",
"create table test(id float primary key nonclustered AUTO_INCREMENT, col1 int) AUTO_ID_CACHE 1;",
} {
tk.MustExec("drop table if exists test;")
tk.MustExec(sql)
tk.MustExec("replace into test(col1) values(1);")
tk.MustExec("replace into test(col1) values(2);")
tk.MustQuery("select * from test;").Check(testkit.Rows("1 1", "2 2"))
tk.MustExec("drop table test")
}

for _, sql := range []string{
"create table test2(id double primary key clustered AUTO_INCREMENT, col1 int);",
"create table test2(id double primary key nonclustered AUTO_INCREMENT, col1 int) AUTO_ID_CACHE 1;",
} {
tk.MustExec(sql)
tk.MustExec("replace into test2(col1) values(1);")
tk.MustExec("insert into test2(col1) values(1);")
tk.MustExec("replace into test2(col1) values(1);")
tk.MustExec("insert into test2(col1) values(1);")
tk.MustExec("replace into test2(col1) values(1);")
tk.MustExec("replace into test2(col1) values(1);")
tk.MustQuery("select * from test2").Check(testkit.Rows("1 1", "2 1", "3 1", "4 1", "5 1", "6 1"))
tk.MustExec("drop table test2")
}
}
2 changes: 1 addition & 1 deletion executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ func TestCheckIndex(t *testing.T) {
tbInfo := tbl.Meta()

alloc := autoid.NewAllocator(store, dbInfo.ID, tbInfo.ID, false, autoid.RowIDAllocType)
tb, err := tables.TableFromMeta(autoid.NewAllocators(alloc), tbInfo)
tb, err := tables.TableFromMeta(autoid.NewAllocators(false, alloc), tbInfo)
require.NoError(t, err)

_, err = se.Execute(context.Background(), "admin check index t c")
Expand Down
2 changes: 1 addition & 1 deletion executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func getAutoIncrementID(ctx sessionctx.Context, schema *model.DBInfo, tblInfo *m
if err != nil {
return 0, err
}
return tbl.Allocators(ctx).Get(autoid.RowIDAllocType).Base() + 1, nil
return tbl.Allocators(ctx).Get(autoid.AutoIncrementType).Base() + 1, nil
}

func hasPriv(ctx sessionctx.Context, priv mysql.PrivilegeType) bool {
Expand Down
5 changes: 3 additions & 2 deletions executor/insert_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,8 @@ func (e *InsertValues) lazyAdjustAutoIncrementDatum(ctx context.Context, rows []
}
// Use the value if it's not null and not 0.
if recordID != 0 {
err = e.Table.Allocators(e.ctx).Get(autoid.RowIDAllocType).Rebase(ctx, recordID, true)
alloc := e.Table.Allocators(e.ctx).Get(autoid.AutoIncrementType)
err = alloc.Rebase(ctx, recordID, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -871,7 +872,7 @@ func (e *InsertValues) adjustAutoIncrementDatum(ctx context.Context, d types.Dat
}
// Use the value if it's not null and not 0.
if recordID != 0 {
err = e.Table.Allocators(e.ctx).Get(autoid.RowIDAllocType).Rebase(ctx, recordID, true)
err = e.Table.Allocators(e.ctx).Get(autoid.AutoIncrementType).Rebase(ctx, recordID, true)
if err != nil {
return types.Datum{}, err
}
Expand Down
26 changes: 14 additions & 12 deletions executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,43 +773,45 @@ func HelperTestAdminShowNextID(t *testing.T, store kv.Storage, str string) {
tk.MustExec("create table t(id int, c int)")
// Start handle is 1.
r := tk.MustQuery(str + " t next_row_id")
r.Check(testkit.Rows("test t _tidb_rowid 1 AUTO_INCREMENT"))
r.Check(testkit.Rows("test t _tidb_rowid 1 _TIDB_ROWID"))
// Row ID is step + 1.
tk.MustExec("insert into t values(1, 1)")
r = tk.MustQuery(str + " t next_row_id")
r.Check(testkit.Rows("test t _tidb_rowid 11 AUTO_INCREMENT"))
r.Check(testkit.Rows("test t _tidb_rowid 11 _TIDB_ROWID"))
// Row ID is original + step.
for i := 0; i < int(step); i++ {
tk.MustExec("insert into t values(10000, 1)")
}
r = tk.MustQuery(str + " t next_row_id")
r.Check(testkit.Rows("test t _tidb_rowid 21 AUTO_INCREMENT"))
r.Check(testkit.Rows("test t _tidb_rowid 21 _TIDB_ROWID"))
tk.MustExec("drop table t")

// test for a table with the primary key
tk.MustExec("create table tt(id int primary key auto_increment, c int)")
// Start handle is 1.
r = tk.MustQuery(str + " tt next_row_id")
r.Check(testkit.Rows("test tt id 1 AUTO_INCREMENT"))
r.Check(testkit.Rows("test tt id 1 _TIDB_ROWID", "test tt id 1 AUTO_INCREMENT"))
// After rebasing auto ID, row ID is 20 + step + 1.
tk.MustExec("insert into tt values(20, 1)")
r = tk.MustQuery(str + " tt next_row_id")
r.Check(testkit.Rows("test tt id 31 AUTO_INCREMENT"))
r.Check(testkit.Rows("test tt id 31 _TIDB_ROWID", "test tt id 1 AUTO_INCREMENT"))
// test for renaming the table
tk.MustExec("drop database if exists test1")
tk.MustExec("create database test1")
tk.MustExec("rename table test.tt to test1.tt")
tk.MustExec("use test1")
r = tk.MustQuery(str + " tt next_row_id")
r.Check(testkit.Rows("test1 tt id 31 AUTO_INCREMENT"))
r.Check(testkit.Rows("test1 tt id 31 _TIDB_ROWID", "test1 tt id 1 AUTO_INCREMENT"))
tk.MustExec("insert test1.tt values ()")
r = tk.MustQuery(str + " tt next_row_id")
r.Check(testkit.Rows("test1 tt id 41 AUTO_INCREMENT"))
r.Check(testkit.Rows("test1 tt id 41 _TIDB_ROWID", "test1 tt id 1 AUTO_INCREMENT"))
tk.MustExec("drop table tt")

tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (a int auto_increment primary key nonclustered, b int);")
tk.MustQuery("show table t next_row_id;").Check(testkit.Rows("test1 t _tidb_rowid 1 AUTO_INCREMENT"))
tk.MustQuery("show table t next_row_id;").Check(testkit.Rows(
"test1 t _tidb_rowid 1 _TIDB_ROWID",
"test1 t _tidb_rowid 1 AUTO_INCREMENT"))

tk.MustExec("set @@allow_auto_random_explicit_insert = true")

Expand All @@ -830,19 +832,19 @@ func HelperTestAdminShowNextID(t *testing.T, store kv.Storage, str string) {
// Test for a sequence.
tk.MustExec("create sequence seq1 start 15 cache 57")
r = tk.MustQuery(str + " seq1 next_row_id")
r.Check(testkit.Rows("test1 seq1 _tidb_rowid 1 AUTO_INCREMENT", "test1 seq1 15 SEQUENCE"))
r.Check(testkit.Rows("test1 seq1 _tidb_rowid 1 _TIDB_ROWID", "test1 seq1 15 SEQUENCE"))
r = tk.MustQuery("select nextval(seq1)")
r.Check(testkit.Rows("15"))
r = tk.MustQuery(str + " seq1 next_row_id")
r.Check(testkit.Rows("test1 seq1 _tidb_rowid 1 AUTO_INCREMENT", "test1 seq1 72 SEQUENCE"))
r.Check(testkit.Rows("test1 seq1 _tidb_rowid 1 _TIDB_ROWID", "test1 seq1 72 SEQUENCE"))
r = tk.MustQuery("select nextval(seq1)")
r.Check(testkit.Rows("16"))
r = tk.MustQuery(str + " seq1 next_row_id")
r.Check(testkit.Rows("test1 seq1 _tidb_rowid 1 AUTO_INCREMENT", "test1 seq1 72 SEQUENCE"))
r.Check(testkit.Rows("test1 seq1 _tidb_rowid 1 _TIDB_ROWID", "test1 seq1 72 SEQUENCE"))
r = tk.MustQuery("select setval(seq1, 96)")
r.Check(testkit.Rows("96"))
r = tk.MustQuery(str + " seq1 next_row_id")
r.Check(testkit.Rows("test1 seq1 _tidb_rowid 1 AUTO_INCREMENT", "test1 seq1 97 SEQUENCE"))
r.Check(testkit.Rows("test1 seq1 _tidb_rowid 1 _TIDB_ROWID", "test1 seq1 97 SEQUENCE"))
}

func TestNoHistoryWhenDisableRetry(t *testing.T) {
Expand Down
Loading