@@ -1429,6 +1429,15 @@ func TestTruncatePartitionWithGlobalIndex(t *testing.T) {
1429
1429
time .Sleep (10 * time .Millisecond )
1430
1430
}
1431
1431
}
1432
+ waitFor (4 , "write only" )
1433
+ tkTmp := testkit .NewTestKit (t , store )
1434
+ tkTmp .MustExec (`begin` )
1435
+ tkTmp .MustExec ("use test" )
1436
+ tkTmp .MustQuery (`select count(*) from test_global` ).Check (testkit .Rows ("5" ))
1437
+ tk2 .MustExec (`rollback` )
1438
+ tk2 .MustExec (`begin` )
1439
+ tk2 .MustExec (`insert into test_global values (5,5,5)` )
1440
+ tkTmp .MustExec (`rollback` )
1432
1441
waitFor (4 , "delete only" )
1433
1442
tk3 := testkit .NewTestKit (t , store )
1434
1443
tk3 .MustExec (`begin` )
@@ -1437,16 +1446,21 @@ func TestTruncatePartitionWithGlobalIndex(t *testing.T) {
1437
1446
tk3 .MustQuery (`explain format='brief' select c from test_global use index(idx_c) where c = 15` ).CheckContain ("Point_Get" )
1438
1447
tk3 .MustQuery (`select b from test_global use index(idx_b) where b = 15` ).Check (testkit .Rows ())
1439
1448
tk3 .MustQuery (`select c from test_global use index(idx_c) where c = 15` ).Check (testkit .Rows ())
1440
- // Here it will fail with
1441
- // the partition is not in public.
1442
1449
err := tk3 .ExecToErr (`insert into test_global values (15,15,15)` )
1443
1450
require .Error (t , err )
1444
- require .ErrorContains (t , err , "the partition is in not in public " )
1451
+ require .ErrorContains (t , err , "[kv:1062]Duplicate entry '15' for key 'test_global.idx_b' " )
1445
1452
tk2 .MustExec (`commit` )
1453
+ waitFor (4 , "delete reorganization" )
1454
+ tk2 .MustQuery (`select b from test_global use index(idx_b) where b = 15` ).Check (testkit .Rows ())
1455
+ tk2 .MustQuery (`select c from test_global use index(idx_c) where c = 15` ).Check (testkit .Rows ())
1456
+ err = tk2 .ExecToErr (`insert into test_global values (15,15,15)` )
1457
+ require .NoError (t , err )
1458
+ tk2 .MustExec (`begin` )
1446
1459
tk3 .MustExec (`commit` )
1460
+ tk .MustExec (`commit` )
1447
1461
<- syncChan
1448
1462
result := tk .MustQuery ("select * from test_global;" )
1449
- result .Sort ().Check (testkit .Rows (`1 1 1` , `2 2 2` , `5 5 5` ))
1463
+ result .Sort ().Check (testkit .Rows (`1 1 1` , `15 15 15` , ` 2 2 2` , `5 5 5` ))
1450
1464
1451
1465
tt = external .GetTableByName (t , tk , "test" , "test_global" )
1452
1466
idxInfo := tt .Meta ().FindIndexByName ("idx_b" )
@@ -1487,12 +1501,12 @@ func TestGlobalIndexUpdateInTruncatePartition(t *testing.T) {
1487
1501
tk1 := testkit .NewTestKit (t , store )
1488
1502
tk1 .MustExec ("use test" )
1489
1503
err := tk1 .ExecToErr ("update test_global set a = 2 where a = 11" )
1490
- assert .NotNil (t , err )
1504
+ assert .NoError (t , err )
1491
1505
}
1492
1506
})
1493
1507
1494
1508
tk .MustExec ("alter table test_global truncate partition p1" )
1495
- tk .MustQuery ("select * from test_global use index(idx_b) order by a" ).Check (testkit .Rows ("11 11 11" , "12 12 12" ))
1509
+ tk .MustQuery ("select * from test_global use index(idx_b) order by a" ).Check (testkit .Rows ("2 11 11" , "12 12 12" ))
1496
1510
}
1497
1511
1498
1512
func TestGlobalIndexUpdateInTruncatePartition4Hash (t * testing.T ) {
@@ -1515,7 +1529,7 @@ func TestGlobalIndexUpdateInTruncatePartition4Hash(t *testing.T) {
1515
1529
tk1 := testkit .NewTestKit (t , store )
1516
1530
tk1 .MustExec ("use test" )
1517
1531
err = tk1 .ExecToErr ("update test_global set a = 1 where a = 12" )
1518
- assert .NotNil (t , err )
1532
+ assert .NoError (t , err )
1519
1533
}
1520
1534
})
1521
1535
@@ -1577,7 +1591,7 @@ func TestGlobalIndexInsertInTruncatePartition(t *testing.T) {
1577
1591
tk1 := testkit .NewTestKit (t , store )
1578
1592
tk1 .MustExec ("use test" )
1579
1593
err = tk1 .ExecToErr ("insert into test_global values(2, 2, 2)" )
1580
- assert .NotNil (t , err )
1594
+ assert .NoError (t , err )
1581
1595
}
1582
1596
})
1583
1597
@@ -3168,6 +3182,8 @@ func TestRemovePartitioningAutoIDs(t *testing.T) {
3168
3182
tk2 .MustExec (`COMMIT` )
3169
3183
3170
3184
/*
3185
+ // Currently there is an duplicate entry issue, so it will rollback in WriteReorganization
3186
+ // instead of continuing.
3171
3187
waitFor(4, "t", "delete reorganization")
3172
3188
tk2.MustExec(`BEGIN`)
3173
3189
tk2.MustExec(`insert into t values (null, 24)`)
@@ -3655,3 +3671,23 @@ func checkGlobalAndPK(t *testing.T, tk *testkit.TestKit, name string, indexes in
3655
3671
require .True (t , idxInfo .Primary )
3656
3672
}
3657
3673
}
3674
+
3675
+ func TestTruncateNumberOfPhases (t * testing.T ) {
3676
+ store := testkit .CreateMockStore (t )
3677
+ tk := testkit .NewTestKit (t , store )
3678
+ tk .MustExec ("use test" )
3679
+ tk .MustExec (`create table t (a int primary key , b varchar(255)) partition by hash(a) partitions 3` )
3680
+ ctx := tk .Session ()
3681
+ dom := domain .GetDomain (ctx )
3682
+ schemaVersion := dom .InfoSchema ().SchemaMetaVersion ()
3683
+ tk .MustExec (`insert into t values (1,1),(2,2),(3,3)` )
3684
+ tk .MustExec (`alter table t truncate partition p1` )
3685
+ // Without global index, truncate partition should be a single state change
3686
+ require .Equal (t , int64 (4 ), dom .InfoSchema ().SchemaMetaVersion ()- schemaVersion )
3687
+ tk .MustExec (`drop table t` )
3688
+ tk .MustExec (`create table t (a int primary key , b varchar(255), unique key (b) global) partition by hash(a) partitions 3` )
3689
+ schemaVersion = dom .InfoSchema ().SchemaMetaVersion ()
3690
+ tk .MustExec (`insert into t values (1,1),(2,2),(3,3)` )
3691
+ tk .MustExec (`alter table t truncate partition p1` )
3692
+ require .Equal (t , int64 (4 ), dom .InfoSchema ().SchemaMetaVersion ()- schemaVersion )
3693
+ }
0 commit comments