You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
Initialization:
set @@tidb_txn_mode=""; -- use optimistic transactioncreatetablet (id intnot null auto_increment unique key, idx int unique key, c int);
createtablesrc (a int);
Session1, Session2 execute for 100 times:
insert into t(idx, c) select1as idx, 1as c from src on duplicate key update c = %d;
Session3 executes for 100 times:
insert into src values (null);
When these sessions run concurrently:
session 1 and session 2 conflict each other on the record (null, 1, %d). This triggers the transaction retry.
The auto_increment ids are allocated before conflicts. They are reused in the following retry.
Since the number of row records in table src keep increasing, the auto ids that allocated before conflicts are not enough in retry. As a result, an index-out-of-range error is converted to Cannot get auto-id in retry.
The complete test code
func (s*seqTestSuite) TestInsertFromSelectConflictRetryAutoID(c*C) {
tk:=testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (id int not null auto_increment unique key, idx int unique key, c int);")
tk.MustExec("create table src (a int);")
concurrency:=2varwg sync.WaitGroupvarerr []errorwgCount:=concurrency+1wg.Add(wgCount)
err=make([]error, concurrency)
fori:=0; i<concurrency; i++ {
tk:=testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("set autocommit = 1")
gofunc(idxint) {
fori:=0; i<10; i++ {
sql:=fmt.Sprintf("insert into t(idx, c) select 1 as idx, 1 as c from src on duplicate key update c = %[1]d", i)
_, e:=tk.Exec(sql)
ife!=nil {
err[idx] =ewg.Done()
return
}
}
wg.Done()
}(i)
}
varinsertErrerrorgofunc() {
tk:=testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("set autocommit = 1")
fori:=0; i<10; i++ {
_, e:=tk.Exec("insert into src values (null);")
ife!=nil {
insertErr=ewg.Done()
return
}
}
wg.Done()
}()
wg.Wait()
for_, e:=rangeerr {
c.Assert(e, IsNil)
}
c.Assert(insertErr, IsNil)
}
2. What did you expect to see? (Required)
All of these statements should encounter no error.
3. What did you see instead (Required)
release-3.0:
cannot get valid auto-increment id in retry
release-4.0/master
Cannot get a valid auto-ID when retrying the statement
4. What is your TiDB version? (Required)
All of the TiDB versions.
The text was updated successfully, but these errors were encountered:
Please edit this comment to complete the following information
Bug
1. Root Cause Analysis (RCA) (optional)
When executing INSERT statement, the allocated auto-increment ids are cached for the future retries. However, it is possible that the retrying INSERT statement populates a different number of rows. As a result, auto-increment IDs in cache are not enough. For details, see #20629.
2. Symptom (optional)
TiDB reports Cannot get auto-id in retry 'INSERT INTO ... SELECT FROM' when inserting rows.
3. All Trigger Conditions (optional)
Concurrent INSERT .. ON DUPLICATE UPDATE triggers statements retry.
Another changing table is the source of the INSERT statement.
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
Initialization:
Session1, Session2 execute for 100 times:
Session3 executes for 100 times:
When these sessions run concurrently:
(null, 1, %d)
. This triggers the transaction retry.auto_increment
ids are allocated before conflicts. They are reused in the following retry.src
keep increasing, the auto ids that allocated before conflicts are not enough in retry. As a result, anindex-out-of-range
error is converted toCannot get auto-id in retry
.The complete test code
2. What did you expect to see? (Required)
All of these statements should encounter no error.
3. What did you see instead (Required)
release-3.0:
release-4.0/master
4. What is your TiDB version? (Required)
All of the TiDB versions.
The text was updated successfully, but these errors were encountered: