Skip to content

Commit 63df90d

Browse files
author
James Cor
committed
no implicit commit for ddl on temporary tables
1 parent f3df8ac commit 63df90d

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

enginetest/queries/transaction_queries.go

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ var TransactionTests = []TransactionTest{
11181118
},
11191119
},
11201120
{
1121-
Name: "create temporary table queries are not implicitly committed",
1121+
Name: "certain ddl queries on temporary tables are not implicitly committed",
11221122
Assertions: []ScriptTestAssertion{
11231123
{
11241124
Query: "/* client a */ create table t (pk int primary key);",
@@ -1149,13 +1149,18 @@ var TransactionTests = []TransactionTest{
11491149

11501150
{
11511151
// This should not implicitly commit the transaction
1152-
Query: "/* client a */ create temporary table tmp1 (pk int primary key);",
1152+
Query: "/* client a */ create temporary table tmp (pk int primary key);",
11531153
Expected: []sql.Row{{types.OkResult{}}},
11541154
},
1155+
{
1156+
Query: "/* client b */ select * from t;",
1157+
Expected: []sql.Row{},
1158+
},
1159+
11551160
{
11561161
// This should not implicitly commit the transaction
1157-
Query: "/* client a */ create temporary table tmp2 (pk int primary key);",
1158-
Expected: []sql.Row{{types.OkResult{}}},
1162+
Query: "/* client a */ insert into tmp values (1), (2), (3);",
1163+
Expected: []sql.Row{{types.OkResult{RowsAffected: 3}}},
11591164
},
11601165
{
11611166
Query: "/* client b */ select * from t;",
@@ -1164,8 +1169,8 @@ var TransactionTests = []TransactionTest{
11641169

11651170
{
11661171
// This should not implicitly commit the transaction
1167-
Query: "/* client a */ insert into tmp1 values (1), (2), (3);",
1168-
Expected: []sql.Row{{types.OkResult{RowsAffected: 3}}},
1172+
Query: "/* client a */ drop temporary table tmp;",
1173+
Expected: []sql.Row{{types.OkResult{}}},
11691174
},
11701175
{
11711176
Query: "/* client b */ select * from t;",
@@ -1174,21 +1179,57 @@ var TransactionTests = []TransactionTest{
11741179

11751180
{
11761181
// This should not implicitly commit the transaction
1177-
Query: "/* client a */ drop temporary table tmp1;",
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);",
11781216
Expected: []sql.Row{{types.OkResult{}}},
11791217
},
11801218
{
11811219
Query: "/* client b */ select * from t;",
11821220
Expected: []sql.Row{},
11831221
},
1184-
11851222
{
1186-
// Oddly, this does commit the transaction
1187-
Query: "/* client a */ drop table tmp2;",
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;",
11881227
Expected: []sql.Row{{types.OkResult{}}},
11891228
},
11901229
{
1230+
// TODO: turns out we can't alter temporary tables; unskip tests when that is fixed
11911231
Query: "/* client b */ select * from t;",
1232+
Skip: true,
11921233
Expected: []sql.Row{
11931234
{1},
11941235
{2},

sql/planbuilder/ddl.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,6 @@ func (b *Builder) buildCreateTable(inScope *scope, c *ast.DDL) (outScope *scope)
364364
database, c.Table.Name.String(), c.IfNotExists, c.Temporary, tableSpec)
365365
}
366366

367-
// Temporary tables do not cause implicit commits
368-
if c.Temporary {
369-
b.qFlags.Unset(sql.QFlagDDL)
370-
}
371-
372367
return
373368
}
374369

0 commit comments

Comments
 (0)