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