@@ -1117,6 +1117,127 @@ var TransactionTests = []TransactionTest{
11171117 },
11181118 },
11191119 },
1120+ {
1121+ Name : "certain ddl queries on temporary tables are not implicitly committed" ,
1122+ Assertions : []ScriptTestAssertion {
1123+ {
1124+ Query : "/* client a */ create table t (pk int primary key);" ,
1125+ Expected : []sql.Row {{types.OkResult {}}},
1126+ },
1127+ {
1128+ Query : "/* client b */ select * from t;" ,
1129+ Expected : []sql.Row {},
1130+ },
1131+
1132+ {
1133+ Query : "/* client a */ set @@autocommit = 0;" ,
1134+ Expected : []sql.Row {{}},
1135+ },
1136+ {
1137+ Query : "/* client a */ start transaction;" ,
1138+ Expected : []sql.Row {},
1139+ },
1140+ {
1141+ // This should not appear for client b until a transaction is committed
1142+ Query : "/* client a */ insert into t values (1), (2), (3);" ,
1143+ Expected : []sql.Row {{types.OkResult {RowsAffected : 3 }}},
1144+ },
1145+ {
1146+ Query : "/* client b */ select * from t;" ,
1147+ Expected : []sql.Row {},
1148+ },
1149+
1150+ {
1151+ // This should not implicitly commit the transaction
1152+ Query : "/* client a */ create temporary table tmp (pk int primary key);" ,
1153+ Expected : []sql.Row {{types.OkResult {}}},
1154+ },
1155+ {
1156+ Query : "/* client b */ select * from t;" ,
1157+ Expected : []sql.Row {},
1158+ },
1159+
1160+ {
1161+ // This should not implicitly commit the transaction
1162+ Query : "/* client a */ insert into tmp values (1), (2), (3);" ,
1163+ Expected : []sql.Row {{types.OkResult {RowsAffected : 3 }}},
1164+ },
1165+ {
1166+ Query : "/* client b */ select * from t;" ,
1167+ Expected : []sql.Row {},
1168+ },
1169+
1170+ {
1171+ // This should not implicitly commit the transaction
1172+ Query : "/* client a */ drop temporary table tmp;" ,
1173+ Expected : []sql.Row {{types.OkResult {}}},
1174+ },
1175+ {
1176+ Query : "/* client b */ select * from t;" ,
1177+ Expected : []sql.Row {},
1178+ },
1179+
1180+ {
1181+ // This should not implicitly commit the transaction
1182+ Query : "/* client a */ create temporary table tmp (pk int primary key);" ,
1183+ Expected : []sql.Row {{types.OkResult {}}},
1184+ },
1185+ {
1186+ // Oddly, this does implicitly commit the transaction
1187+ Query : "/* client a */ drop table tmp;" ,
1188+ Expected : []sql.Row {{types.OkResult {}}},
1189+ },
1190+ {
1191+ Query : "/* client b */ select * from t;" ,
1192+ Expected : []sql.Row {
1193+ {1 },
1194+ {2 },
1195+ {3 },
1196+ },
1197+ },
1198+ {
1199+ Query : "/* client a */ delete from t where true;" ,
1200+ Expected : []sql.Row {{types.OkResult {RowsAffected : 3 }}},
1201+ },
1202+
1203+ {
1204+ // This should commit and reset table t
1205+ Query : "/* client a */ start transaction;" ,
1206+ Expected : []sql.Row {},
1207+ },
1208+ {
1209+ // This should not implicitly commit the transaction
1210+ Query : "/* client a */ insert into t values (1), (2), (3);" ,
1211+ Expected : []sql.Row {{types.OkResult {RowsAffected : 3 }}},
1212+ },
1213+ {
1214+ // This should not implicitly commit the transaction
1215+ Query : "/* client a */ create temporary table tmp (pk int primary key);" ,
1216+ Expected : []sql.Row {{types.OkResult {}}},
1217+ },
1218+ {
1219+ Query : "/* client b */ select * from t;" ,
1220+ Expected : []sql.Row {},
1221+ },
1222+ {
1223+ // TODO: turns out we can't alter temporary tables; unskip tests when that is fixed
1224+ // Oddly, this does implicitly commit the transaction
1225+ Skip : true ,
1226+ Query : "/* client a */ alter table tmp add column j int;" ,
1227+ Expected : []sql.Row {{types.OkResult {}}},
1228+ },
1229+ {
1230+ // TODO: turns out we can't alter temporary tables; unskip tests when that is fixed
1231+ Query : "/* client b */ select * from t;" ,
1232+ Skip : true ,
1233+ Expected : []sql.Row {
1234+ {1 },
1235+ {2 },
1236+ {3 },
1237+ },
1238+ },
1239+ },
1240+ },
11201241 {
11211242 Name : "alter table queries are implicitly committed" ,
11221243 Assertions : []ScriptTestAssertion {
0 commit comments