Skip to content

Commit 4823d27

Browse files
author
James Cor
committed
merge with main
2 parents 74a0a8e + 5b1a12f commit 4823d27

File tree

9 files changed

+147
-12
lines changed

9 files changed

+147
-12
lines changed

enginetest/queries/queries.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5429,7 +5429,7 @@ SELECT * FROM cte WHERE d = 2;`,
54295429
{
54305430
Query: "SELECT version()",
54315431
Expected: []sql.Row{
5432-
{"8.0.23"},
5432+
{"8.0.31"},
54335433
},
54345434
},
54355435
{
@@ -5825,7 +5825,7 @@ SELECT * FROM cte WHERE d = 2;`,
58255825
{
58265826
Query: `SHOW VARIABLES WHERE Variable_name = 'version' || variable_name = 'autocommit'`,
58275827
Expected: []sql.Row{
5828-
{"autocommit", 1}, {"version", "8.0.23"},
5828+
{"autocommit", 1}, {"version", "8.0.31"},
58295829
},
58305830
},
58315831
{
@@ -5865,7 +5865,7 @@ SELECT * FROM cte WHERE d = 2;`,
58655865
{
58665866
Query: "SHOW VARIABLES LIKE 'VERSION'",
58675867
Expected: []sql.Row{
5868-
{"version", "8.0.23"},
5868+
{"version", "8.0.31"},
58695869
},
58705870
},
58715871
{

enginetest/queries/transaction_queries.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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{

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad
77
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71
88
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81
9-
github.com/dolthub/vitess v0.0.0-20250418221234-8d272f40a217
9+
github.com/dolthub/vitess v0.0.0-20250423221552-f731ee5c5379
1010
github.com/go-kit/kit v0.10.0
1111
github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d
1212
github.com/gocraft/dbr/v2 v2.7.2

go.sum

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 h1:bMGS25NWAGTE
5858
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71/go.mod h1:2/2zjLQ/JOOSbbSboojeg+cAwcRV0fDLzIiWch/lhqI=
5959
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE=
6060
github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY=
61-
github.com/dolthub/vitess v0.0.0-20250418221234-8d272f40a217 h1:QcVH/2VQrEv+azfhqUU1wkkP6fsbJfzx5JO1dqx/DwY=
62-
github.com/dolthub/vitess v0.0.0-20250418221234-8d272f40a217/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
61+
github.com/dolthub/vitess v0.0.0-20250410233614-8d8c7a5b3d6b h1:2wE+qJwJ5SRIzz+dJQT8XbkpK+g8/pFt34AU/iJ5K+Y=
62+
github.com/dolthub/vitess v0.0.0-20250410233614-8d8c7a5b3d6b/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
63+
github.com/dolthub/vitess v0.0.0-20250414165810-f0031a6472b7 h1:4Y043kZgAH1WhOER0nk+02KPKxJX8Ir6yK7cGzY04c4=
64+
github.com/dolthub/vitess v0.0.0-20250414165810-f0031a6472b7/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
65+
github.com/dolthub/vitess v0.0.0-20250417230335-b8d80bc39341 h1:qebIGlJEgi/mSXVZ39P77cklPuuIl8gApyTVMnKm79s=
66+
github.com/dolthub/vitess v0.0.0-20250417230335-b8d80bc39341/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
67+
github.com/dolthub/vitess v0.0.0-20250423221552-f731ee5c5379 h1:3nPFx23Ol0djIPf9rDw/y38yEn1BXqTXOUkYrWfxrEI=
68+
github.com/dolthub/vitess v0.0.0-20250423221552-f731ee5c5379/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
6369
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
6470
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
6571
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=

server/handler.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,14 @@ func (h *Handler) resultForDefaultIter(ctx *sql.Context, c *mysql.Conn, schema s
673673
timer := time.NewTimer(waitTime)
674674
defer timer.Stop()
675675

676-
// Wrap the callback to include a BytesBuffer.Reset() to clean out rows that have already been spooled
676+
// Wrap the callback to include a BytesBuffer.Reset() for non-cursor requests, to
677+
// clean out rows that have already been spooled.
677678
resetCallback := func(r *sqltypes.Result, more bool) error {
678-
defer buf.Reset()
679+
// A server-side cursor allows the caller to fetch results cached on the server-side,
680+
// so if a cursor exists, we can't release the buffer memory yet.
681+
if c.StatusFlags&uint16(mysql.ServerCursorExists) != 0 {
682+
defer buf.Reset()
683+
}
679684
return callback(r, more)
680685
}
681686

sql/expression/function/version_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ func TestNewVersion(t *testing.T) {
3232

3333
val, err := f.Eval(ctx, nil)
3434
require.NoError(err)
35-
require.Equal("8.0.23-"+versionPostfix, val)
35+
require.Equal("8.0.31-"+versionPostfix, val)
3636

3737
f, err = NewVersion("")()
3838
require.NoError(err)
3939

4040
val, err = f.Eval(ctx, nil)
4141
require.NoError(err)
42-
require.Equal("8.0.23", val)
42+
require.Equal("8.0.31", val)
4343
}

sql/planbuilder/builder.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ func (b *Builder) buildSubquery(inScope *scope, stmt ast.Statement, subQuery str
233233
case *ast.Show:
234234
return b.buildShow(inScope, n)
235235
case *ast.DDL:
236-
b.qFlags.Set(sql.QFlagDDL)
237236
return b.buildDDL(inScope, subQuery, fullQuery, n)
238237
case *ast.AlterTable:
239238
b.qFlags.Set(sql.QFlagAlterTable)

sql/planbuilder/ddl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ func (b *Builder) buildDDL(inScope *scope, subQuery string, fullQuery string, c
122122
if err := b.cat.AuthorizationHandler().HandleAuth(b.ctx, b.authQueryState, c.Auth); err != nil && b.authEnabled {
123123
b.handleErr(err)
124124
}
125+
if !c.Temporary {
126+
b.qFlags.Set(sql.QFlagDDL)
127+
}
125128

126129
outScope = inScope.push()
127130
switch strings.ToLower(c.Action) {
@@ -231,6 +234,7 @@ func (b *Builder) buildDropTable(inScope *scope, c *ast.DDL) (outScope *scope) {
231234
if dbName == "" {
232235
dbName = b.currentDb().Name()
233236
}
237+
234238
for _, t := range c.FromTables {
235239
if t.DbQualifier.String() != "" && t.DbQualifier.String() != dbName {
236240
err := sql.ErrUnsupportedFeature.New("dropping tables on multiple databases in the same statement")

sql/variables/system_variables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2951,7 +2951,7 @@ var systemVars = map[string]sql.SystemVariable{
29512951
Dynamic: false,
29522952
SetVarHintApplies: false,
29532953
Type: types.NewSystemStringType("version"),
2954-
Default: "8.0.23",
2954+
Default: "8.0.31",
29552955
},
29562956
"version_comment": &sql.MysqlSystemVariable{
29572957
Name: "version_comment",

0 commit comments

Comments
 (0)