Skip to content

Commit 6d525e6

Browse files
committed
Merge branch 'main' into zachmu/literals-alt
2 parents e626185 + b9931b0 commit 6d525e6

24 files changed

+364
-44
lines changed

enginetest/join_op_tests.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,56 @@ SELECT SUM(x) FROM xy WHERE x IN (
19841984
},
19851985
},
19861986
},
1987+
{
1988+
name: "string key test",
1989+
setup: [][]string{
1990+
{
1991+
`
1992+
CREATE TABLE testA (
1993+
id int PRIMARY KEY,
1994+
supplierkey VARCHAR(100),
1995+
name VARCHAR(100),
1996+
product VARCHAR(100),
1997+
UNIQUE KEY unique_product_supplier_key (product, supplierKey)
1998+
);`,
1999+
`
2000+
CREATE TABLE testB (
2001+
id int PRIMARY KEY,
2002+
vendorkey VARCHAR(100),
2003+
name VARCHAR(100),
2004+
supplierkey VARCHAR(100),
2005+
product VARCHAR(100),
2006+
UNIQUE KEY unique_product_vendor_key (product,vendorKey)
2007+
);`,
2008+
"INSERT INTO testA VALUES (1, 'texwin-post-frame', 'Texwin (Post Frame)', 'carports');",
2009+
"INSERT INTO testA VALUES (2, 'texwin', 'Texwin', 'carports');",
2010+
"INSERT INTO testB VALUES (1, 'advancebldg', 'Test', 'texwin', 'carports');",
2011+
},
2012+
},
2013+
tests: []JoinOpTests{
2014+
{
2015+
Query: `
2016+
SELECT
2017+
v.vendorkey AS vendor,
2018+
v.product,
2019+
v.supplierkey,
2020+
s.name AS supplierName
2021+
FROM
2022+
testB AS v
2023+
INNER JOIN
2024+
testA AS s
2025+
ON
2026+
s.supplierkey = v.supplierkey AND
2027+
s.product = v.product
2028+
WHERE
2029+
v.vendorkey = 'advancebldg';
2030+
`,
2031+
Expected: []sql.Row{
2032+
{"advancebldg", "carports", "texwin", "Texwin"},
2033+
},
2034+
},
2035+
},
2036+
},
19872037
}
19882038

19892039
var rangeJoinOpTests = []JoinOpTests{

enginetest/queries/json_scripts.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ var JsonScripts = []ScriptTest{
627627
SetUpScript: []string{
628628
"create table t (pk int primary key, col1 JSON, col2 JSON);",
629629
`insert into t values (1, JSON_OBJECT('key1', 1, 'key2', '"abc"'), JSON_ARRAY(3,10,5,17,"z"));`,
630-
`insert into t values (2, JSON_OBJECT('key1', 100, 'key2', '"ghi"'), JSON_ARRAY(3,10,5,17,JSON_ARRAY(22,"y",66)));`,
630+
`insert into t values (2, JSON_OBJECT('key1', 100, 'key2', 'ghi'), JSON_ARRAY(3,10,5,17,JSON_ARRAY(22,"y",66)));`,
631631
`CREATE TABLE t2 (i INT PRIMARY KEY, j JSON);`,
632632
`INSERT INTO t2 VALUES (0, '{"a": "123", "outer": {"inner": 456}}');`,
633633
},
@@ -636,16 +636,23 @@ var JsonScripts = []ScriptTest{
636636
Query: `select col1->'$.key1' from t;`,
637637
Expected: []sql.Row{{types.MustJSON("1")}, {types.MustJSON("100")}},
638638
},
639+
{
640+
Query: `select col1->'$.key2' from t;`,
641+
Expected: []sql.Row{
642+
{types.JSONDocument{Val: "\"abc\""}},
643+
{types.JSONDocument{Val: "ghi"}},
644+
},
645+
},
639646
{
640647
Query: `select col1->>'$.key2' from t;`,
641-
Expected: []sql.Row{{"abc"}, {"ghi"}},
648+
Expected: []sql.Row{{"\"abc\""}, {"ghi"}},
642649
},
643650
{
644651
Query: `select pk, col1 from t where col1->'$.key1' = 1;`,
645652
Expected: []sql.Row{{1, types.MustJSON(`{"key1":1, "key2":"\"abc\""}`)}},
646653
},
647654
{
648-
Query: `select pk, col1 from t where col1->>'$.key2' = 'abc';`,
655+
Query: `select pk, col1 from t where col1->>'$.key2' = '"abc"';`,
649656
Expected: []sql.Row{{1, types.MustJSON(`{"key1":1, "key2":"\"abc\""}`)}},
650657
},
651658
{

enginetest/queries/queries.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5412,6 +5412,12 @@ SELECT * FROM cte WHERE d = 2;`,
54125412
},
54135413
},
54145414
},
5415+
{
5416+
Query: `SELECT COALESCE(CAST('{"a": "one \\n two"}' as json), '');`,
5417+
Expected: []sql.Row{
5418+
{"{\"a\": \"one \\n two\"}"},
5419+
},
5420+
},
54155421
{
54165422
Query: "SELECT concat(s, i) FROM mytable",
54175423
Expected: []sql.Row{
@@ -5423,7 +5429,7 @@ SELECT * FROM cte WHERE d = 2;`,
54235429
{
54245430
Query: "SELECT version()",
54255431
Expected: []sql.Row{
5426-
{"8.0.23"},
5432+
{"8.0.31"},
54275433
},
54285434
},
54295435
{
@@ -5819,7 +5825,7 @@ SELECT * FROM cte WHERE d = 2;`,
58195825
{
58205826
Query: `SHOW VARIABLES WHERE Variable_name = 'version' || variable_name = 'autocommit'`,
58215827
Expected: []sql.Row{
5822-
{"autocommit", 1}, {"version", "8.0.23"},
5828+
{"autocommit", 1}, {"version", "8.0.31"},
58235829
},
58245830
},
58255831
{
@@ -5859,7 +5865,7 @@ SELECT * FROM cte WHERE d = 2;`,
58595865
{
58605866
Query: "SHOW VARIABLES LIKE 'VERSION'",
58615867
Expected: []sql.Row{
5862-
{"version", "8.0.23"},
5868+
{"version", "8.0.31"},
58635869
},
58645870
},
58655871
{
@@ -9854,6 +9860,18 @@ from typestable`,
98549860
{"NULL"},
98559861
},
98569862
},
9863+
{
9864+
Query: `SELECT json_type(json_extract('{"a": 123}', null));`,
9865+
Expected: []sql.Row{
9866+
{"NULL"},
9867+
},
9868+
},
9869+
{
9870+
Query: `SELECT json_type(json_extract('{"a": 123}', '$.a', null));`,
9871+
Expected: []sql.Row{
9872+
{"NULL"},
9873+
},
9874+
},
98579875
{
98589876
Query: "SELECT json_type(cast(cast('2001-01-01 12:34:56.123456' as datetime) as json));",
98599877
Expected: []sql.Row{

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-20250417230335-b8d80bc39341
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ github.com/dolthub/vitess v0.0.0-20250414165810-f0031a6472b7 h1:4Y043kZgAH1WhOER
6464
github.com/dolthub/vitess v0.0.0-20250414165810-f0031a6472b7/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
6565
github.com/dolthub/vitess v0.0.0-20250417230335-b8d80bc39341 h1:qebIGlJEgi/mSXVZ39P77cklPuuIl8gApyTVMnKm79s=
6666
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=
6769
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
6870
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
6971
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=

processlist.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ func (pl *ProcessList) BeginQuery(
113113
ctx *sql.Context,
114114
query string,
115115
) (*sql.Context, error) {
116+
if ctx.IsInterpreted() {
117+
return ctx, nil
118+
}
116119
pl.mu.Lock()
117120
defer pl.mu.Unlock()
118121

@@ -144,6 +147,9 @@ func (pl *ProcessList) BeginQuery(
144147
}
145148

146149
func (pl *ProcessList) EndQuery(ctx *sql.Context) {
150+
if ctx.IsInterpreted() {
151+
return
152+
}
147153
pl.mu.Lock()
148154
defer pl.mu.Unlock()
149155
id := ctx.Session.ID()
@@ -177,6 +183,9 @@ func (pl *ProcessList) EndQuery(ctx *sql.Context) {
177183
// bracketed with EndOperation(). Should certainly be used for any
178184
// Handler callbacks which may access the database, like Prepare.
179185
func (pl *ProcessList) BeginOperation(ctx *sql.Context) (*sql.Context, error) {
186+
if ctx.IsInterpreted() {
187+
return ctx, nil
188+
}
180189
pl.mu.Lock()
181190
defer pl.mu.Unlock()
182191
id := ctx.Session.ID()
@@ -193,6 +202,9 @@ func (pl *ProcessList) BeginOperation(ctx *sql.Context) (*sql.Context, error) {
193202
}
194203

195204
func (pl *ProcessList) EndOperation(ctx *sql.Context) {
205+
if ctx.IsInterpreted() {
206+
return
207+
}
196208
pl.mu.Lock()
197209
defer pl.mu.Unlock()
198210
id := ctx.Session.ID()

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/analyzer/fix_exec_indexes.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ func (s *idxScope) visitSelf(n sql.Node) error {
514514
newCheck.Expr = newE
515515
s.checks = append(s.checks, &newCheck)
516516
}
517+
for _, r := range n.Returning {
518+
newE := fixExprToScope(r, srcScope)
519+
s.expressions = append(s.expressions, newE)
520+
}
517521
case *plan.LoadData:
518522
scope := &idxScope{}
519523
scope.addSchema(n.DestSch)
@@ -556,6 +560,10 @@ func (s *idxScope) finalizeSelf(n sql.Node) (sql.Node, error) {
556560
nn.Returning = s.expressions[len(n.OnDupExprs):]
557561
return nn.WithChecks(s.checks), nil
558562
default:
563+
if nn, ok := n.(*plan.Update); ok {
564+
nn.Returning = s.expressions
565+
}
566+
559567
s.ids = columnIdsForNode(n)
560568

561569
s.addSchema(n.Schema())

sql/expression/function/coalesce_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ func TestCoalesce(t *testing.T) {
152152
typ: types.Float64,
153153
nullable: false,
154154
},
155+
{
156+
name: "coalesce(json({'a': 'a \n b'}), '')",
157+
input: []sql.Expression{
158+
expression.NewLiteral("{\"a\": \"one \\n two\"}", types.JSON),
159+
expression.NewLiteral("", types.LongText),
160+
},
161+
expected: "{\"a\": \"one \\n two\"}",
162+
typ: types.LongText,
163+
nullable: false,
164+
},
155165
{
156166
name: "coalesce(sysInt, sysInt)",
157167
input: []sql.Expression{

0 commit comments

Comments
 (0)