@@ -304,6 +304,51 @@ func TestAdminRecoverIndex(t *testing.T) {
304
304
tk .MustExec ("admin check table admin_test" )
305
305
}
306
306
307
+ func TestAdminCleanupMVIndex (t * testing.T ) {
308
+ store , domain := testkit .CreateMockStoreAndDomain (t )
309
+
310
+ tk := testkit .NewTestKit (t , store )
311
+ tk .MustExec ("use test" )
312
+ tk .MustExec ("drop table if exists t" )
313
+ tk .MustExec ("create table t(pk int primary key, a json, index idx((cast(a as signed array))))" )
314
+ tk .MustExec ("insert into t values (0, '[0,1,2]')" )
315
+ tk .MustExec ("insert into t values (1, '[1,2,3]')" )
316
+ tk .MustExec ("insert into t values (2, '[2,3,4]')" )
317
+ tk .MustExec ("insert into t values (3, '[3,4,5]')" )
318
+ tk .MustExec ("insert into t values (4, '[4,5,6]')" )
319
+ tk .MustExec ("admin check table t" )
320
+
321
+ // Make some corrupted index. Build the index information.
322
+ ctx := mock .NewContext ()
323
+ ctx .Store = store
324
+ is := domain .InfoSchema ()
325
+ dbName := model .NewCIStr ("test" )
326
+ tblName := model .NewCIStr ("t" )
327
+ tbl , err := is .TableByName (dbName , tblName )
328
+ require .NoError (t , err )
329
+ tblInfo := tbl .Meta ()
330
+ idxInfo := tblInfo .Indices [0 ]
331
+ tk .Session ().GetSessionVars ().IndexLookupSize = 3
332
+ tk .Session ().GetSessionVars ().MaxChunkSize = 3
333
+
334
+ cpIdx := idxInfo .Clone ()
335
+ cpIdx .MVIndex = false
336
+ indexOpr := tables .NewIndex (tblInfo .ID , tblInfo , cpIdx )
337
+
338
+ txn , err := store .Begin ()
339
+ require .NoError (t , err )
340
+ _ , err = indexOpr .Create (ctx , txn , types .MakeDatums (9 ), kv .IntHandle (9 ), nil )
341
+ require .NoError (t , err )
342
+ err = txn .Commit (context .Background ())
343
+ require .NoError (t , err )
344
+ err = tk .ExecToErr ("admin check table t" )
345
+ require .Error (t , err )
346
+
347
+ r := tk .MustQuery ("admin cleanup index t idx" )
348
+ r .Check (testkit .Rows ("1" ))
349
+ tk .MustExec ("admin check table t" )
350
+ }
351
+
307
352
func TestClusteredIndexAdminRecoverIndex (t * testing.T ) {
308
353
store , domain := testkit .CreateMockStoreAndDomain (t )
309
354
0 commit comments