Skip to content

Commit 1a607e2

Browse files
author
James Cor
committed
more ddl statements
1 parent b707510 commit 1a607e2

File tree

4 files changed

+128
-1
lines changed

4 files changed

+128
-1
lines changed

enginetest/queries/transaction_queries.go

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,4 +1201,129 @@ var TransactionTests = []TransactionTest{
12011201
},
12021202
},
12031203
},
1204+
{
1205+
Name: "create trigger queries are implicitly committed",
1206+
Assertions: []ScriptTestAssertion{
1207+
{
1208+
Query: "/* client a */ set @@autocommit = 0;",
1209+
Expected: []sql.Row{{}},
1210+
},
1211+
{
1212+
Query: "/* client a */ start transaction;",
1213+
Expected: []sql.Row{},
1214+
},
1215+
{
1216+
// This implicitly commits the transaction
1217+
Query: "/* client a */ create table t (i int primary key);",
1218+
Expected: []sql.Row{{types.OkResult{}}},
1219+
},
1220+
{
1221+
Query: "/* client b */ show create table t;",
1222+
Expected: []sql.Row{{"t", "CREATE TABLE `t` (\n" +
1223+
" `i` int NOT NULL,\n" +
1224+
" PRIMARY KEY (`i`)\n" +
1225+
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
1226+
},
1227+
1228+
{
1229+
Query: "/* client a */ start transaction;",
1230+
Expected: []sql.Row{},
1231+
},
1232+
{
1233+
Query: "/* client a */ create trigger trig before insert on t for each row set i = 0;",
1234+
Expected: []sql.Row{{types.OkResult{RowsAffected: 0}}},
1235+
},
1236+
{
1237+
Query: "/* client b */ select trigger_schema, trigger_name from information_schema.triggers where trigger_name = 'trig';",
1238+
Expected: []sql.Row{{"mydb", "trig"}},
1239+
},
1240+
},
1241+
},
1242+
{
1243+
Name: "create view queries are implicitly committed",
1244+
Assertions: []ScriptTestAssertion{
1245+
{
1246+
Query: "/* client a */ set @@autocommit = 0;",
1247+
Expected: []sql.Row{{}},
1248+
},
1249+
{
1250+
Query: "/* client a */ start transaction;",
1251+
Expected: []sql.Row{},
1252+
},
1253+
{
1254+
Query: "/* client a */ create view v as select 1;",
1255+
Expected: []sql.Row{{types.OkResult{RowsAffected: 0}}},
1256+
},
1257+
{
1258+
Query: "/* client b */ show create view v;",
1259+
Expected: []sql.Row{{"v", "CREATE VIEW `v` AS select 1", "utf8mb4", "utf8mb4_0900_bin"}},
1260+
},
1261+
},
1262+
},
1263+
{
1264+
Name: "create procedure queries are implicitly committed",
1265+
Assertions: []ScriptTestAssertion{
1266+
{
1267+
Query: "/* client a */ set @@autocommit = 0;",
1268+
Expected: []sql.Row{{}},
1269+
},
1270+
{
1271+
Query: "/* client a */ start transaction;",
1272+
Expected: []sql.Row{},
1273+
},
1274+
{
1275+
// This implicitly commits the transaction
1276+
Query: "/* client a */ create procedure p() begin select 1; end;",
1277+
Expected: []sql.Row{{types.OkResult{}}},
1278+
},
1279+
{
1280+
Query: "/* client b */ show create procedure p;",
1281+
Expected: []sql.Row{{"p", "", "/* client a */ create procedure p() begin select 1; end", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}},
1282+
},
1283+
},
1284+
},
1285+
{
1286+
Name: "create procedure queries are implicitly committed",
1287+
Assertions: []ScriptTestAssertion{
1288+
{
1289+
Query: "/* client a */ set @@autocommit = 0;",
1290+
Expected: []sql.Row{{}},
1291+
},
1292+
{
1293+
Query: "/* client a */ start transaction;",
1294+
Expected: []sql.Row{},
1295+
},
1296+
{
1297+
// This implicitly commits the transaction
1298+
Query: "/* client a */ create event e on schedule every 1 second starts '2025-01-01' do begin select 1; end;",
1299+
Expected: []sql.Row{{types.OkResult{}}},
1300+
},
1301+
{
1302+
Query: "/* client b */ show create event e;",
1303+
Expected: []sql.Row{{"e", "NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES", "SYSTEM", "CREATE DEFINER = `root`@`localhost` EVENT `e` ON SCHEDULE EVERY 1 SECOND STARTS '2025-01-01 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO begin select 1; end", "utf8mb4", "utf8mb4_0900_bin", "utf8mb4_0900_bin"}},
1304+
},
1305+
},
1306+
},
1307+
{
1308+
Name: "create database queries are implicitly committed",
1309+
Assertions: []ScriptTestAssertion{
1310+
{
1311+
Query: "/* client a */ set @@autocommit = 0;",
1312+
Expected: []sql.Row{{}},
1313+
},
1314+
{
1315+
Query: "/* client a */ start transaction;",
1316+
Expected: []sql.Row{},
1317+
},
1318+
{
1319+
// This implicitly commits the transaction
1320+
Query: "/* client a */ create database otherdb;",
1321+
Expected: []sql.Row{{types.OkResult{RowsAffected: 1}}},
1322+
},
1323+
{
1324+
Query: "/* client b */ show create database otherdb;",
1325+
Expected: []sql.Row{{"otherdb", "CREATE DATABASE `otherdb` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin */"}},
1326+
},
1327+
},
1328+
},
12041329
}

sql/planbuilder/builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ func (b *Builder) buildSubquery(inScope *scope, stmt ast.Statement, subQuery str
238238
b.qFlags.Set(sql.QFlagAlterTable)
239239
return b.buildAlterTable(inScope, subQuery, n)
240240
case *ast.DBDDL:
241+
b.qFlags.Set(sql.QFlagDBDDL)
241242
return b.buildDBDDL(inScope, n)
242243
case *ast.Explain:
243244
return b.buildExplain(inScope, n)

sql/query_flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const (
2929
QFlagCount
3030
QFlagCountStar
3131
QFlagDDL
32+
QFlagDBDDL
3233
QFlagAlterTable
3334
QFlagCrossJoin
3435
QFlagSort

sql/rowexec/transaction_iters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func AddTransactionCommittingIter(ctx *sql.Context, qFlags *sql.QueryFlags, iter
8787
return nil, err
8888
}
8989

90-
implicitCommit := qFlags != nil && (qFlags.IsSet(sql.QFlagDDL) || qFlags.IsSet(sql.QFlagAlterTable))
90+
implicitCommit := qFlags != nil && (qFlags.IsSet(sql.QFlagDDL) || qFlags.IsSet(sql.QFlagAlterTable) || qFlags.IsSet(sql.QFlagDBDDL))
9191
return &TransactionCommittingIter{
9292
childIter: iter,
9393
autoCommit: autoCommit,

0 commit comments

Comments
 (0)