Skip to content

Commit c631117

Browse files
authored
refactor create procedure and call procedure (#2833)
1 parent 6f3b8ac commit c631117

15 files changed

+486
-431
lines changed

enginetest/queries/procedure_queries.go

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,6 +2441,27 @@ var ProcedureCallTests = []ScriptTest{
24412441
},
24422442
},
24432443
},
2444+
{
2445+
Name: "creating invalid procedure doesn't error until it is called",
2446+
Assertions: []ScriptTestAssertion{
2447+
{
2448+
Query: `CREATE PROCEDURE proc1 (OUT out_count INT) READS SQL DATA SELECT COUNT(*) FROM mytable WHERE i = 1 AND s = 'first row' AND func1(i);`,
2449+
Expected: []sql.Row{{types.NewOkResult(0)}},
2450+
},
2451+
{
2452+
Query: "CALL proc1(@out_count);",
2453+
ExpectedErr: sql.ErrTableNotFound,
2454+
},
2455+
{
2456+
Query: "CREATE TABLE mytable (i int, s varchar(128));",
2457+
Expected: []sql.Row{{types.NewOkResult(0)}},
2458+
},
2459+
{
2460+
Query: "CALL proc1(@out_count);",
2461+
ExpectedErr: sql.ErrFunctionNotFound,
2462+
},
2463+
},
2464+
},
24442465
}
24452466

24462467
var ProcedureDropTests = []ScriptTest{
@@ -2787,25 +2808,12 @@ var ProcedureShowCreate = []ScriptTest{
27872808
}
27882809

27892810
var ProcedureCreateInSubroutineTests = []ScriptTest{
2790-
//TODO: Match MySQL behavior (https://github.com/dolthub/dolt/issues/8053)
2791-
{
2792-
Name: "procedure must not contain CREATE PROCEDURE",
2793-
Assertions: []ScriptTestAssertion{
2794-
{
2795-
Query: "CREATE PROCEDURE foo() CREATE PROCEDURE bar() SELECT 0;",
2796-
// MySQL output: "Can't create a PROCEDURE from within another stored routine",
2797-
ExpectedErrStr: "creating procedures in stored procedures is currently unsupported and will be added in a future release",
2798-
},
2799-
},
2800-
},
28012811
{
28022812
Name: "event must not contain CREATE PROCEDURE",
28032813
Assertions: []ScriptTestAssertion{
28042814
{
2805-
// Skipped because MySQL errors here but we don't.
28062815
Query: "CREATE EVENT foo ON SCHEDULE EVERY 1 YEAR DO CREATE PROCEDURE bar() SELECT 1;",
2807-
ExpectedErrStr: "Can't create a PROCEDURE from within another stored routine",
2808-
Skip: true,
2816+
ExpectedErrStr: "can't create a PROCEDURE from within another stored routine",
28092817
},
28102818
},
28112819
},
@@ -2828,11 +2836,11 @@ var ProcedureCreateInSubroutineTests = []ScriptTest{
28282836
Assertions: []ScriptTestAssertion{
28292837
{
28302838
Query: "create procedure p() create table t (pk int);",
2831-
ExpectedErrStr: "creating tables in stored procedures is currently unsupported and will be added in a future release",
2839+
ExpectedErrStr: "CREATE statements in CREATE PROCEDURE not yet supported",
28322840
},
28332841
{
28342842
Query: "create procedure p() begin create table t (pk int); end;",
2835-
ExpectedErrStr: "creating tables in stored procedures is currently unsupported and will be added in a future release",
2843+
ExpectedErrStr: "CREATE statements in CREATE PROCEDURE not yet supported",
28362844
},
28372845
},
28382846
},
@@ -2844,11 +2852,11 @@ var ProcedureCreateInSubroutineTests = []ScriptTest{
28442852
Assertions: []ScriptTestAssertion{
28452853
{
28462854
Query: "create procedure p() create trigger trig before insert on t for each row begin select 1; end;",
2847-
ExpectedErrStr: "creating triggers in stored procedures is currently unsupported and will be added in a future release",
2855+
ExpectedErrStr: "can't create a TRIGGER from within another stored routine",
28482856
},
28492857
{
28502858
Query: "create procedure p() begin create trigger trig before insert on t for each row begin select 1; end; end;",
2851-
ExpectedErrStr: "creating triggers in stored procedures is currently unsupported and will be added in a future release",
2859+
ExpectedErrStr: "can't create a TRIGGER from within another stored routine",
28522860
},
28532861
},
28542862
},
@@ -2858,11 +2866,11 @@ var ProcedureCreateInSubroutineTests = []ScriptTest{
28582866
Assertions: []ScriptTestAssertion{
28592867
{
28602868
Query: "create procedure p() create database procdb;",
2861-
ExpectedErrStr: "creating databases in stored procedures is currently unsupported and will be added in a future release",
2869+
ExpectedErrStr: "DBDDL in CREATE PROCEDURE not yet supported",
28622870
},
28632871
{
28642872
Query: "create procedure p() begin create database procdb; end;",
2865-
ExpectedErrStr: "creating databases in stored procedures is currently unsupported and will be added in a future release",
2873+
ExpectedErrStr: "DBDDL in CREATE PROCEDURE not yet supported",
28662874
},
28672875
},
28682876
},
@@ -2872,11 +2880,11 @@ var ProcedureCreateInSubroutineTests = []ScriptTest{
28722880
Assertions: []ScriptTestAssertion{
28732881
{
28742882
Query: "create procedure p() create view v as select 1;",
2875-
ExpectedErrStr: "creating views in stored procedures is currently unsupported and will be added in a future release",
2883+
ExpectedErrStr: "CREATE statements in CREATE PROCEDURE not yet supported",
28762884
},
28772885
{
28782886
Query: "create procedure p() begin create view v as select 1; end;",
2879-
ExpectedErrStr: "creating views in stored procedures is currently unsupported and will be added in a future release",
2887+
ExpectedErrStr: "CREATE statements in CREATE PROCEDURE not yet supported",
28802888
},
28812889
},
28822890
},

enginetest/queries/queries.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10971,11 +10971,6 @@ var ErrorQueries = []QueryErrorTest{
1097110971
Query: `SELECT * FROM datetime_table where datetime_col >= 'not a valid datetime'`,
1097210972
ExpectedErr: types.ErrConvertingToTime,
1097310973
},
10974-
// this query was panicing, but should be allowed and should return error when this query is called
10975-
{
10976-
Query: `CREATE PROCEDURE proc1 (OUT out_count INT) READS SQL DATA SELECT COUNT(*) FROM mytable WHERE i = 1 AND s = 'first row' AND func1(i);`,
10977-
ExpectedErr: sql.ErrFunctionNotFound,
10978-
},
1097910974
{
1098010975
Query: "CREATE TABLE table_test (id int PRIMARY KEY, c float DEFAULT rand())",
1098110976
ExpectedErr: sql.ErrSyntaxError,

enginetest/queries/trigger_queries.go

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,39 +3230,23 @@ for each row
32303230
}
32313231

32323232
var TriggerCreateInSubroutineTests = []ScriptTest{
3233-
//TODO: Match MySQL behavior (https://github.com/dolthub/dolt/issues/8053)
32343233
{
3235-
Name: "procedure must not contain CREATE TRIGGER",
3236-
Assertions: []ScriptTestAssertion{
3237-
{
3238-
Query: "CREATE PROCEDURE foo() CREATE PROCEDURE bar() SELECT 0;",
3239-
// MySQL's error message: "Can't create a PROCEDURE from within another stored routine",
3240-
ExpectedErrStr: "creating procedures in stored procedures is currently unsupported and will be added in a future release",
3241-
},
3242-
},
3243-
},
3244-
{
3245-
Name: "event must not contain CREATE TRIGGER",
3246-
Assertions: []ScriptTestAssertion{
3247-
{
3248-
// Skipped because MySQL errors here but we don't.
3249-
Query: "CREATE EVENT foo ON SCHEDULE EVERY 1 YEAR DO CREATE PROCEDURE bar() SELECT 1;",
3250-
ExpectedErrStr: "Can't create a PROCEDURE from within another stored routine",
3251-
Skip: true,
3252-
},
3253-
},
3254-
},
3255-
{
3256-
Name: "trigger must not contain CREATE TRIGGER",
3234+
Name: "triggers cannot contain or be contained in other stored routines",
32573235
SetUpScript: []string{
32583236
"CREATE TABLE t (pk INT PRIMARY KEY);",
32593237
},
32603238
Assertions: []ScriptTestAssertion{
32613239
{
3262-
// Skipped because MySQL errors here but we don't.
3240+
Query: "CREATE PROCEDURE bar() CREATE TRIGGER foo AFTER UPDATE ON t FOR EACH ROW BEGIN SELECT 1; END;",
3241+
ExpectedErrStr: "can't create a TRIGGER from within another stored routine",
3242+
},
3243+
{
32633244
Query: "CREATE TRIGGER foo AFTER UPDATE ON t FOR EACH ROW BEGIN CREATE PROCEDURE bar() SELECT 1; END",
3264-
ExpectedErrStr: "Can't create a PROCEDURE from within another stored routine",
3265-
Skip: true,
3245+
ExpectedErrStr: "can't create a PROCEDURE from within another stored routine",
3246+
},
3247+
{
3248+
Query: "CREATE EVENT foo ON SCHEDULE EVERY 1 YEAR DO CREATE TRIGGER foo AFTER UPDATE ON t FOR EACH ROW BEGIN SELECT 1; END;",
3249+
ExpectedErrStr: "can't create a TRIGGER from within another stored routine",
32663250
},
32673251
},
32683252
},

sql/analyzer/replace_count_star.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ func replaceCountStar(ctx *sql.Context, a *Analyzer, n sql.Node, _ *plan.Scope,
3535

3636
return transform.Node(n, func(n sql.Node) (sql.Node, transform.TreeIdentity, error) {
3737
if agg, ok := n.(*plan.GroupBy); ok {
38-
39-
if len(agg.GroupByExprs) == 0 && !qFlags.JoinIsSet() && !qFlags.SubqueryIsSet() && !qFlags.IsSet(sql.QFlagAnyAgg) {
38+
if len(agg.GroupByExprs) == 0 && !qFlags.JoinIsSet() && !qFlags.SubqueryIsSet() && !qFlags.IsSet(sql.QFlagAnyAgg) && !qFlags.IsSet(sql.QFlagAnalyzeProcedure) {
4039
// top-level aggregation with a single group and no "any_value" functions can only return one row
4140
qFlags.Set(sql.QFlagMax1Row)
4241
}

0 commit comments

Comments
 (0)