@@ -2088,8 +2088,8 @@ func TestExplainAnalyzeDMLWithFKInfo(t *testing.T) {
2088
2088
{
2089
2089
sql : "explain analyze insert ignore into t6 values (1,1,10)" ,
2090
2090
plan : "Insert_.* root time:.* loops:.* prepare:.* check_insert.* fk_check:.*" +
2091
- "├─Foreign_Key_Check.* 0 root table:t5 total:0s , foreign_keys:1 foreign_key:fk_1, check_exist N/A N/A.*" +
2092
- "├─Foreign_Key_Check.* 0 root table:t5, index:idx2 total:0s , foreign_keys:1 foreign_key:fk_2, check_exist N/A N/A.*" +
2091
+ "├─Foreign_Key_Check.* 0 root table:t5 total:.*, lock:.* , foreign_keys:1 foreign_key:fk_1, check_exist N/A N/A.*" +
2092
+ "├─Foreign_Key_Check.* 0 root table:t5, index:idx2 total:.*, lock:.* , foreign_keys:1 foreign_key:fk_2, check_exist N/A N/A.*" +
2093
2093
"└─Foreign_Key_Check.* 0 root table:t5, index:idx3 total:0s, foreign_keys:1 foreign_key:fk_3, check_exist N/A N/A" ,
2094
2094
},
2095
2095
{
@@ -2527,3 +2527,42 @@ func TestLockKeysInDML(t *testing.T) {
2527
2527
tk .MustQuery ("SELECT * FROM t1" ).Check (testkit .Rows ("1" ))
2528
2528
tk .MustQuery ("SELECT * FROM t2" ).Check (testkit .Rows ("1" ))
2529
2529
}
2530
+
2531
+ func TestLockKeysInInsertIgnore (t * testing.T ) {
2532
+ store := realtikvtest .CreateMockStoreAndSetup (t )
2533
+ tk := testkit .NewTestKit (t , store )
2534
+ tk .MustExec ("use test" )
2535
+ tk .MustExec ("create table t1 (id int primary key);" )
2536
+ tk .MustExec ("create table t2 (id int primary key, foreign key fk (id) references t1(id));" )
2537
+ tk .MustExec ("insert into t1 values (1)" )
2538
+
2539
+ tk .MustExec ("BEGIN" )
2540
+ tk .MustExec ("INSERT IGNORE INTO t2 VALUES (1)" )
2541
+
2542
+ var wg sync.WaitGroup
2543
+ var tk2CommitTime time.Time
2544
+ tk2StartTime := time .Now ()
2545
+ wg .Add (1 )
2546
+ go func () {
2547
+ defer wg .Done ()
2548
+
2549
+ tk2 := testkit .NewTestKit (t , store )
2550
+ // unistore has a bug to handle the fair locking mechanism. We need to disable it to pass this test.
2551
+ // Ref: https://github.com/pingcap/tidb/issues/56663
2552
+ tk2 .MustExec ("set tidb_pessimistic_txn_fair_locking = 'OFF'" )
2553
+ tk2 .MustExec ("use test" )
2554
+ tk2 .MustExec ("BEGIN" )
2555
+ require .NotNil (t , tk2 .ExecToErr ("UPDATE t1 SET id = 2 WHERE id = 1" ))
2556
+ tk2 .MustExec ("COMMIT" )
2557
+ tk2CommitTime = time .Now ()
2558
+ }()
2559
+
2560
+ sleepDuration := 500 * time .Millisecond
2561
+ time .Sleep (sleepDuration )
2562
+ tk .MustExec ("COMMIT" )
2563
+ wg .Wait ()
2564
+
2565
+ require .Greater (t , tk2CommitTime .Sub (tk2StartTime ), sleepDuration )
2566
+ tk .MustQuery ("SELECT * FROM t1" ).Check (testkit .Rows ("1" ))
2567
+ tk .MustQuery ("SELECT * FROM t2" ).Check (testkit .Rows ("1" ))
2568
+ }
0 commit comments