@@ -1016,26 +1016,14 @@ func TestMDLPreparePlanCacheExecuteInsert(t *testing.T) {
1016
1016
tk := testkit .NewTestKitWithSession (t , store , conn1 .Context ().Session )
1017
1017
conn2 := server .CreateMockConn (t , sv )
1018
1018
tkDDL := testkit .NewTestKitWithSession (t , store , conn2 .Context ().Session )
1019
- conn3 := server .CreateMockConn (t , sv )
1020
- tk3 := testkit .NewTestKitWithSession (t , store , conn3 .Context ().Session )
1021
1019
tk .MustExec ("use test" )
1022
1020
tk .MustExec ("set global tidb_enable_metadata_lock=1" )
1023
1021
tk .MustExec ("create table t(a int primary key, b int);" )
1024
1022
tk .MustExec ("create table t2(a int);" )
1025
1023
tk .MustExec ("insert into t values(1, 1), (2, 2), (3, 3), (4, 4);" )
1026
1024
1027
- tk .MustExec (`begin` )
1028
- tk .MustExec (`prepare delete_stmt from 'delete from t where a = ?'` )
1029
1025
tk .MustExec (`prepare insert_stmt from 'insert into t values (?, ?)'` )
1030
- tk .MustExec (`commit` )
1031
-
1032
- tk .MustExec (`begin` )
1033
- tk .MustExec (`set @a = 4, @b= 4;` )
1034
- tk .MustExec (`execute delete_stmt using @a;` )
1035
- tk .MustExec (`execute insert_stmt using @a, @b;` )
1036
- tk .MustExec (`commit` )
1037
-
1038
- tk .MustExec ("begin" )
1026
+ tk .MustExec (`set @a=4, @b=4;` )
1039
1027
1040
1028
ch := make (chan struct {})
1041
1029
@@ -1048,19 +1036,10 @@ func TestMDLPreparePlanCacheExecuteInsert(t *testing.T) {
1048
1036
switch idx .BackfillState {
1049
1037
case model .BackfillStateRunning :
1050
1038
if first {
1039
+ // generate plan, cache it, and make some row change to make
1040
+ // sure backfill state 'merging' is not skipped.
1051
1041
tk .MustExec (`begin` )
1052
- tk .MustExec (`set @a=9;` )
1053
- tk .MustExec (`execute delete_stmt using @a;` )
1054
- tk .MustQuery ("select @@last_plan_from_cache;" ).Check (testkit .Rows ("0" ))
1055
- tk .MustExec (`set @a=6, @b=4;` )
1056
- tk .MustExec (`execute insert_stmt using @a, @b;` )
1057
- tk .MustQuery ("select @@last_plan_from_cache;" ).Check (testkit .Rows ("0" ))
1058
- tk .MustExec (`commit` )
1059
- tk .MustExec (`begin` )
1060
- tk .MustExec (`set @a=4;` )
1061
- tk .MustExec (`execute delete_stmt using @a;` )
1062
- tk .MustQuery ("select @@last_plan_from_cache;" ).Check (testkit .Rows ("1" ))
1063
- tk .MustExec (`set @a=4, @b=4;` )
1042
+ tk .MustExec (`delete from t where a = 4;` )
1064
1043
tk .MustExec (`execute insert_stmt using @a, @b;` )
1065
1044
tk .MustQuery ("select @@last_plan_from_cache;" ).Check (testkit .Rows ("0" ))
1066
1045
tk .MustExec (`commit` )
@@ -1069,17 +1048,18 @@ func TestMDLPreparePlanCacheExecuteInsert(t *testing.T) {
1069
1048
// Activate txn.
1070
1049
tk .MustExec ("select * from t2" )
1071
1050
first = false
1072
- tk3 .MustExec ("insert into test.t values(10000, 1000)" )
1073
1051
return
1074
1052
}
1075
1053
}
1076
1054
}
1077
1055
})
1078
1056
1079
1057
ddl .MockDMLExecutionMerging = func () {
1080
- tk .MustExec (`execute delete_stmt using @a;` )
1081
- tk .MustQuery ("select @@last_plan_from_cache;" ).Check (testkit .Rows ("0" ))
1058
+ tk .MustExec (`delete from t where a = 4;` )
1059
+ // we must generate a new plan here, because the schema has changed since
1060
+ // the last plan was generated.
1082
1061
tk .MustExec (`execute insert_stmt using @a, @b;` )
1062
+ tk .MustQuery ("select @@last_plan_from_cache;" ).Check (testkit .Rows ("0" ))
1083
1063
tk .MustExec ("commit" )
1084
1064
}
1085
1065
require .NoError (t , failpoint .Enable ("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionMerging" , "1*return(true)->return(false)" ))
0 commit comments