@@ -18,6 +18,7 @@ import (
18
18
"testing"
19
19
"time"
20
20
21
+ "github.com/pingcap/failpoint"
21
22
"github.com/pingcap/tidb/ddl"
22
23
"github.com/pingcap/tidb/ddl/ingest"
23
24
"github.com/pingcap/tidb/domain"
@@ -415,6 +416,70 @@ func TestAddIndexMergeDeleteUniqueOnWriteOnly(t *testing.T) {
415
416
tk .MustExec ("admin check table t;" )
416
417
}
417
418
419
+ func TestAddIndexMergeDeleteNullUnique (t * testing.T ) {
420
+ store := testkit .CreateMockStore (t )
421
+
422
+ tk := testkit .NewTestKit (t , store )
423
+ tk .MustExec ("use test" )
424
+ tk .MustExec ("create table t(id int primary key, a int default 0);" )
425
+ tk .MustExec ("insert into t values (1, 1), (2, null);" )
426
+
427
+ tk1 := testkit .NewTestKit (t , store )
428
+ tk1 .MustExec ("use test" )
429
+
430
+ ddl .MockDMLExecution = func () {
431
+ _ , err := tk1 .Exec ("delete from t where id = 2;" )
432
+ assert .NoError (t , err )
433
+ }
434
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/ddl/mockDMLExecution" , "1*return(true)->return(false)" ))
435
+ tk .MustExec ("alter table t add unique index idx(a);" )
436
+ tk .MustQuery ("select count(1) from t;" ).Check (testkit .Rows ("1" ))
437
+ tk .MustExec ("admin check table t;" )
438
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/ddl/mockDMLExecution" ))
439
+ }
440
+
441
+ func TestAddIndexMergeDoubleDelete (t * testing.T ) {
442
+ store , dom := testkit .CreateMockStoreAndDomain (t )
443
+
444
+ tk := testkit .NewTestKit (t , store )
445
+ tk .MustExec ("use test" )
446
+ tk .MustExec ("create table t(id int primary key, a int default 0);" )
447
+
448
+ tk1 := testkit .NewTestKit (t , store )
449
+ tk1 .MustExec ("use test" )
450
+
451
+ d := dom .DDL ()
452
+ originalCallback := d .GetHook ()
453
+ defer d .SetHook (originalCallback )
454
+ callback := & ddl.TestDDLCallback {}
455
+ onJobUpdatedExportedFunc := func (job * model.Job ) {
456
+ if t .Failed () {
457
+ return
458
+ }
459
+ switch job .SchemaState {
460
+ case model .StateWriteOnly :
461
+ _ , err := tk1 .Exec ("insert into t values (1, 1);" )
462
+ assert .NoError (t , err )
463
+ }
464
+ }
465
+ callback .OnJobUpdatedExported .Store (& onJobUpdatedExportedFunc )
466
+ d .SetHook (callback )
467
+
468
+ ddl .MockDMLExecution = func () {
469
+ _ , err := tk1 .Exec ("delete from t where id = 1;" )
470
+ assert .NoError (t , err )
471
+ _ , err = tk1 .Exec ("insert into t values (2, 1);" )
472
+ assert .NoError (t , err )
473
+ _ , err = tk1 .Exec ("delete from t where id = 2;" )
474
+ assert .NoError (t , err )
475
+ }
476
+ require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/ddl/mockDMLExecution" , "1*return(true)->return(false)" ))
477
+ tk .MustExec ("alter table t add unique index idx(a);" )
478
+ tk .MustQuery ("select count(1) from t;" ).Check (testkit .Rows ("0" ))
479
+ tk .MustExec ("admin check table t;" )
480
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/ddl/mockDMLExecution" ))
481
+ }
482
+
418
483
func TestAddIndexMergeConflictWithPessimistic (t * testing.T ) {
419
484
store , dom := testkit .CreateMockStoreAndDomain (t )
420
485
tk := testkit .NewTestKit (t , store )
0 commit comments