@@ -1059,6 +1059,54 @@ func (s *testStateChangeSuite) TestParallelAlterModifyColumn(c *C) {
1059
1059
s .testControlParallelExecSQL (c , sql , sql , f )
1060
1060
}
1061
1061
1062
+ func (s * testStateChangeSuite ) TestParallelAlterModifyColumnWithData (c * C ) {
1063
+ sql := "ALTER TABLE t MODIFY COLUMN c int;"
1064
+ f := func (c * C , err1 , err2 error ) {
1065
+ c .Assert (err1 , IsNil )
1066
+ c .Assert (err2 .Error (), Equals , "[ddl:1072]column c id 3 does not exist, this column may have been updated by other DDL ran in parallel" )
1067
+ rs , err := s .se .Execute (context .Background (), "select * from t" )
1068
+ c .Assert (err , IsNil )
1069
+ sRows , err := session .ResultSetToStringSlice (context .Background (), s .se , rs [0 ])
1070
+ c .Assert (err , IsNil )
1071
+ c .Assert (sRows [0 ][2 ], Equals , "3" )
1072
+ c .Assert (rs [0 ].Close (), IsNil )
1073
+ _ , err = s .se .Execute (context .Background (), "insert into t values(11, 22, 33.3, 44, 55)" )
1074
+ c .Assert (err , IsNil )
1075
+ rs , err = s .se .Execute (context .Background (), "select * from t" )
1076
+ c .Assert (err , IsNil )
1077
+ sRows , err = session .ResultSetToStringSlice (context .Background (), s .se , rs [0 ])
1078
+ c .Assert (err , IsNil )
1079
+ c .Assert (sRows [1 ][2 ], Equals , "33" )
1080
+ c .Assert (rs [0 ].Close (), IsNil )
1081
+ }
1082
+ s .testControlParallelExecSQL (c , sql , sql , f )
1083
+ }
1084
+
1085
+ func (s * testStateChangeSuite ) TestParallelAlterModifyColumnToNotNullWithData (c * C ) {
1086
+ sql := "ALTER TABLE t MODIFY COLUMN c int not null;"
1087
+ f := func (c * C , err1 , err2 error ) {
1088
+ c .Assert (err1 , IsNil )
1089
+ c .Assert (err2 .Error (), Equals , "[ddl:1072]column c id 3 does not exist, this column may have been updated by other DDL ran in parallel" )
1090
+ rs , err := s .se .Execute (context .Background (), "select * from t" )
1091
+ c .Assert (err , IsNil )
1092
+ sRows , err := session .ResultSetToStringSlice (context .Background (), s .se , rs [0 ])
1093
+ c .Assert (err , IsNil )
1094
+ c .Assert (sRows [0 ][2 ], Equals , "3" )
1095
+ c .Assert (rs [0 ].Close (), IsNil )
1096
+ _ , err = s .se .Execute (context .Background (), "insert into t values(11, 22, null, 44, 55)" )
1097
+ c .Assert (err , NotNil )
1098
+ _ , err = s .se .Execute (context .Background (), "insert into t values(11, 22, 33.3, 44, 55)" )
1099
+ c .Assert (err , IsNil )
1100
+ rs , err = s .se .Execute (context .Background (), "select * from t" )
1101
+ c .Assert (err , IsNil )
1102
+ sRows , err = session .ResultSetToStringSlice (context .Background (), s .se , rs [0 ])
1103
+ c .Assert (err , IsNil )
1104
+ c .Assert (sRows [1 ][2 ], Equals , "33" )
1105
+ c .Assert (rs [0 ].Close (), IsNil )
1106
+ }
1107
+ s .testControlParallelExecSQL (c , sql , sql , f )
1108
+ }
1109
+
1062
1110
func (s * testStateChangeSuite ) TestParallelAddGeneratedColumnAndAlterModifyColumn (c * C ) {
1063
1111
sql1 := "ALTER TABLE t ADD COLUMN f INT GENERATED ALWAYS AS(a+1);"
1064
1112
sql2 := "ALTER TABLE t MODIFY COLUMN a tinyint;"
@@ -1334,12 +1382,15 @@ func (s *testStateChangeSuiteBase) prepareTestControlParallelExecSQL(c *C) (sess
1334
1382
func (s * testStateChangeSuiteBase ) testControlParallelExecSQL (c * C , sql1 , sql2 string , f checkRet ) {
1335
1383
_ , err := s .se .Execute (context .Background (), "use test_db_state" )
1336
1384
c .Assert (err , IsNil )
1337
- _ , err = s .se .Execute (context .Background (), "create table t(a int, b int, c int , d int auto_increment,e int, index idx1(d), index idx2(d,e))" )
1385
+ _ , err = s .se .Execute (context .Background (), "create table t(a int, b int, c double default null , d int auto_increment,e int, index idx1(d), index idx2(d,e))" )
1338
1386
c .Assert (err , IsNil )
1339
1387
if len (s .preSQL ) != 0 {
1340
1388
_ , err := s .se .Execute (context .Background (), s .preSQL )
1341
1389
c .Assert (err , IsNil )
1342
1390
}
1391
+ _ , err = s .se .Execute (context .Background (), "insert into t values(1, 2, 3.1234, 4, 5)" )
1392
+ c .Assert (err , IsNil )
1393
+
1343
1394
defer func () {
1344
1395
_ , err := s .se .Execute (context .Background (), "drop table t" )
1345
1396
c .Assert (err , IsNil )
0 commit comments