@@ -1306,6 +1306,44 @@ func TestAddPartitioning(t *testing.T) {
1306
1306
)
1307
1307
}
1308
1308
1309
+ func TestDropSchema (t * testing.T ) {
1310
+ store , dom := testkit .CreateMockStoreAndDomain (t )
1311
+ tk := testkit .NewTestKit (t , store )
1312
+
1313
+ tk .MustExec ("use test" )
1314
+ tk .MustExec ("create table t (c1 int)" )
1315
+ h := dom .StatsHandle ()
1316
+ tk .MustExec ("insert into t values (1)" )
1317
+ require .NoError (t , h .DumpStatsDeltaToKV (true ))
1318
+
1319
+ is := dom .InfoSchema ()
1320
+ tbl , err := is .TableByName (context .Background (), pmodel .NewCIStr ("test" ), pmodel .NewCIStr ("t" ))
1321
+ require .NoError (t , err )
1322
+ tableInfo := tbl .Meta ()
1323
+ // Check the current stats meta version.
1324
+ rows := tk .MustQuery (
1325
+ "select version from mysql.stats_meta where table_id = ?" ,
1326
+ tableInfo .ID ,
1327
+ ).Rows ()
1328
+ require .Len (t , rows , 1 )
1329
+ version := rows [0 ][0 ].(string )
1330
+
1331
+ tk .MustExec ("drop database test" )
1332
+
1333
+ // Handle the drop schema event.
1334
+ dropSchemaEvent := findEvent (h .DDLEventCh (), model .ActionDropSchema )
1335
+ err = h .HandleDDLEvent (dropSchemaEvent )
1336
+ require .NoError (t , err )
1337
+
1338
+ // Check the stats meta version after drop schema.
1339
+ rows = tk .MustQuery (
1340
+ "select version from mysql.stats_meta where table_id = ?" ,
1341
+ tableInfo .ID ,
1342
+ ).Rows ()
1343
+ require .Len (t , rows , 1 )
1344
+ require .NotEqual (t , version , rows [0 ][0 ].(string ))
1345
+ }
1346
+
1309
1347
func findEvent (eventCh <- chan * notifier.SchemaChangeEvent , eventType model.ActionType ) * notifier.SchemaChangeEvent {
1310
1348
// Find the target event.
1311
1349
for {
0 commit comments