Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions enginetest/queries/transaction_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,127 @@ var TransactionTests = []TransactionTest{
},
},
},
{
Name: "certain ddl queries on temporary tables are not implicitly committed",
Assertions: []ScriptTestAssertion{
{
Query: "/* client a */ create table t (pk int primary key);",
Expected: []sql.Row{{types.OkResult{}}},
},
{
Query: "/* client b */ select * from t;",
Expected: []sql.Row{},
},

{
Query: "/* client a */ set @@autocommit = 0;",
Expected: []sql.Row{{}},
},
{
Query: "/* client a */ start transaction;",
Expected: []sql.Row{},
},
{
// This should not appear for client b until a transaction is committed
Query: "/* client a */ insert into t values (1), (2), (3);",
Expected: []sql.Row{{types.OkResult{RowsAffected: 3}}},
},
{
Query: "/* client b */ select * from t;",
Expected: []sql.Row{},
},

{
// This should not implicitly commit the transaction
Query: "/* client a */ create temporary table tmp (pk int primary key);",
Expected: []sql.Row{{types.OkResult{}}},
},
{
Query: "/* client b */ select * from t;",
Expected: []sql.Row{},
},

{
// This should not implicitly commit the transaction
Query: "/* client a */ insert into tmp values (1), (2), (3);",
Expected: []sql.Row{{types.OkResult{RowsAffected: 3}}},
},
{
Query: "/* client b */ select * from t;",
Expected: []sql.Row{},
},

{
// This should not implicitly commit the transaction
Query: "/* client a */ drop temporary table tmp;",
Expected: []sql.Row{{types.OkResult{}}},
},
{
Query: "/* client b */ select * from t;",
Expected: []sql.Row{},
},

{
// This should not implicitly commit the transaction
Query: "/* client a */ create temporary table tmp (pk int primary key);",
Expected: []sql.Row{{types.OkResult{}}},
},
{
// Oddly, this does implicitly commit the transaction
Query: "/* client a */ drop table tmp;",
Expected: []sql.Row{{types.OkResult{}}},
},
{
Query: "/* client b */ select * from t;",
Expected: []sql.Row{
{1},
{2},
{3},
},
},
{
Query: "/* client a */ delete from t where true;",
Expected: []sql.Row{{types.OkResult{RowsAffected: 3}}},
},

{
// This should commit and reset table t
Query: "/* client a */ start transaction;",
Expected: []sql.Row{},
},
{
// This should not implicitly commit the transaction
Query: "/* client a */ insert into t values (1), (2), (3);",
Expected: []sql.Row{{types.OkResult{RowsAffected: 3}}},
},
{
// This should not implicitly commit the transaction
Query: "/* client a */ create temporary table tmp (pk int primary key);",
Expected: []sql.Row{{types.OkResult{}}},
},
{
Query: "/* client b */ select * from t;",
Expected: []sql.Row{},
},
{
// TODO: turns out we can't alter temporary tables; unskip tests when that is fixed
// Oddly, this does implicitly commit the transaction
Skip: true,
Query: "/* client a */ alter table tmp add column j int;",
Expected: []sql.Row{{types.OkResult{}}},
},
{
// TODO: turns out we can't alter temporary tables; unskip tests when that is fixed
Query: "/* client b */ select * from t;",
Skip: true,
Expected: []sql.Row{
{1},
{2},
{3},
},
},
},
},
{
Name: "alter table queries are implicitly committed",
Assertions: []ScriptTestAssertion{
Expand Down
1 change: 0 additions & 1 deletion sql/planbuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ func (b *Builder) buildSubquery(inScope *scope, stmt ast.Statement, subQuery str
case *ast.Show:
return b.buildShow(inScope, n)
case *ast.DDL:
b.qFlags.Set(sql.QFlagDDL)
return b.buildDDL(inScope, subQuery, fullQuery, n)
case *ast.AlterTable:
b.qFlags.Set(sql.QFlagAlterTable)
Expand Down
4 changes: 4 additions & 0 deletions sql/planbuilder/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func (b *Builder) buildDDL(inScope *scope, subQuery string, fullQuery string, c
if err := b.cat.AuthorizationHandler().HandleAuth(b.ctx, b.authQueryState, c.Auth); err != nil && b.authEnabled {
b.handleErr(err)
}
if !c.Temporary {
b.qFlags.Set(sql.QFlagDDL)
}

outScope = inScope.push()
switch strings.ToLower(c.Action) {
Expand Down Expand Up @@ -231,6 +234,7 @@ func (b *Builder) buildDropTable(inScope *scope, c *ast.DDL) (outScope *scope) {
if dbName == "" {
dbName = b.currentDb().Name()
}

for _, t := range c.FromTables {
if t.DbQualifier.String() != "" && t.DbQualifier.String() != dbName {
err := sql.ErrUnsupportedFeature.New("dropping tables on multiple databases in the same statement")
Expand Down