Skip to content

Commit 4c44894

Browse files
author
James Cor
committed
tests
1 parent 34c9c2e commit 4c44894

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

enginetest/queries/transaction_queries.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,4 +1064,56 @@ var TransactionTests = []TransactionTest{
10641064
},
10651065
},
10661066
},
1067+
{
1068+
Name: "ddl queries are implicitly committed",
1069+
Assertions: []ScriptTestAssertion{
1070+
{
1071+
Query: "/* client a */ set @@autocommit = 0;",
1072+
Expected: []sql.Row{{}},
1073+
},
1074+
{
1075+
Query: "/* client a */ start transaction;",
1076+
Expected: []sql.Row{},
1077+
},
1078+
{
1079+
// This implicitly commits the transaction
1080+
Query: "/* client a */ create table t (pk int primary key);",
1081+
Expected: []sql.Row{{types.OkResult{}}},
1082+
},
1083+
{
1084+
Query: "/* client a */ commit;",
1085+
Expected: []sql.Row{},
1086+
},
1087+
{
1088+
Query: "/* client b */ select * from t;",
1089+
Expected: []sql.Row{},
1090+
},
1091+
1092+
{
1093+
Query: "/* client a */ start transaction;",
1094+
Expected: []sql.Row{},
1095+
},
1096+
{
1097+
Query: "/* client a */ insert into t values (1), (2), (3);",
1098+
Expected: []sql.Row{{types.OkResult{RowsAffected: 3}}},
1099+
},
1100+
{
1101+
Query: "/* client b */ select * from t;",
1102+
Expected: []sql.Row{},
1103+
},
1104+
{
1105+
// This implicitly commits the transaction
1106+
Query: "/* client a */ create table t2 (pk int primary key);",
1107+
Expected: []sql.Row{{types.OkResult{}}},
1108+
},
1109+
{
1110+
Query: "/* client b */ select * from t;",
1111+
Expected: []sql.Row{
1112+
{1},
1113+
{2},
1114+
{3},
1115+
},
1116+
},
1117+
},
1118+
},
10671119
}

sql/rowexec/transaction_iters.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@ func AddTransactionCommittingIter(ctx *sql.Context, qFlags *sql.QueryFlags, iter
8484
// TODO: In the future we should ensure that analyzer supports implicit commits instead of directly
8585
// accessing autocommit here.
8686
// cc. https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html
87-
autocommit, err := plan.IsSessionAutocommit(ctx)
87+
shouldCommit, err := plan.IsSessionAutocommit(ctx)
8888
if err != nil {
8989
return nil, err
9090
}
9191

92-
shouldCommit := autocommit || (qFlags != nil && qFlags.IsSet(sql.QFlagDDL))
92+
if qFlags != nil && qFlags.IsSet(sql.QFlagDDL) {
93+
shouldCommit = true
94+
ctx.SetIgnoreAutoCommit(false)
95+
}
9396
return &TransactionCommittingIter{childIter: iter, shouldCommit: shouldCommit}, nil
9497
}
9598

0 commit comments

Comments
 (0)