Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor create procedure and call procedure #2833

Merged
merged 37 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
93bc19e
refactor create procedure and call procedure
Jan 28, 2025
cf09af9
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Jan 28, 2025
e406070
debugging
Jan 29, 2025
2ce0641
pass at fixing external procedures
Jan 29, 2025
1bf75ae
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Jan 29, 2025
ba620f8
another pass at external
Jan 29, 2025
65a75e2
fixed external stored procedures, moving onto other procedure errors
Jan 29, 2025
b387d21
fixing subqueries in stored procs
Jan 29, 2025
f755beb
start sorting through bugs
Jan 30, 2025
57ebce9
lots of fixing towards validation
Jan 31, 2025
7de8dde
Merge branch 'james/proc' of https://github.com/dolthub/go-mysql-serv…
Jan 31, 2025
c0ea80d
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Jan 31, 2025
1b7eabe
some progress
Jan 31, 2025
4cdfba3
debugging
Jan 31, 2025
206cf48
Merge branch 'james/proc' of https://github.com/dolthub/go-mysql-serv…
Jan 31, 2025
ff83c1d
catch panics
Jan 31, 2025
fd6da22
fixed bad procs
Jan 31, 2025
baf9b1b
ddl and stored routine tests
Jan 31, 2025
971bd81
fixing validation errors
Jan 31, 2025
9f03809
progress towards analyzer
Feb 3, 2025
6bd4174
debugging
Feb 3, 2025
bfb0776
Merge branch 'main' into james/proc
Feb 4, 2025
bc78d97
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Feb 4, 2025
9abaefc
delete
Feb 5, 2025
6b884de
skip
Feb 5, 2025
be8201a
Merge branch 'main' into james/proc
Feb 5, 2025
373ed67
Merge branch 'main' into james/proc
Feb 5, 2025
0cb0dfe
debug
Feb 6, 2025
e72746c
more debugging
Feb 6, 2025
738f6e9
tidy and revert
Feb 6, 2025
e87a92b
[ga-format-pr] Run ./format_repo.sh to fix formatting
jycor Feb 6, 2025
fc07e1f
missed some tests
Feb 6, 2025
b066a15
Merge branch 'james/proc' of https://github.com/dolthub/go-mysql-serv…
Feb 6, 2025
8db0c9f
revert
Feb 6, 2025
a7ebd3f
hacky, but whatever
Feb 7, 2025
724c51d
error changes
Feb 7, 2025
0fe4ce1
feedback
Feb 7, 2025
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
52 changes: 30 additions & 22 deletions enginetest/queries/procedure_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -2441,6 +2441,27 @@ var ProcedureCallTests = []ScriptTest{
},
},
},
{
Name: "creating invalid procedure doesn't error until it is called",
Assertions: []ScriptTestAssertion{
{
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);`,
Expected: []sql.Row{{types.NewOkResult(0)}},
},
{
Query: "CALL proc1(@out_count);",
ExpectedErr: sql.ErrTableNotFound,
},
{
Query: "CREATE TABLE mytable (i int, s varchar(128));",
Expected: []sql.Row{{types.NewOkResult(0)}},
},
{
Query: "CALL proc1(@out_count);",
ExpectedErr: sql.ErrFunctionNotFound,
},
},
},
}

var ProcedureDropTests = []ScriptTest{
Expand Down Expand Up @@ -2787,25 +2808,12 @@ var ProcedureShowCreate = []ScriptTest{
}

var ProcedureCreateInSubroutineTests = []ScriptTest{
//TODO: Match MySQL behavior (https://github.com/dolthub/dolt/issues/8053)
{
Name: "procedure must not contain CREATE PROCEDURE",
Assertions: []ScriptTestAssertion{
{
Query: "CREATE PROCEDURE foo() CREATE PROCEDURE bar() SELECT 0;",
// MySQL output: "Can't create a PROCEDURE from within another stored routine",
ExpectedErrStr: "creating procedures in stored procedures is currently unsupported and will be added in a future release",
},
},
},
{
Name: "event must not contain CREATE PROCEDURE",
Assertions: []ScriptTestAssertion{
{
// Skipped because MySQL errors here but we don't.
Query: "CREATE EVENT foo ON SCHEDULE EVERY 1 YEAR DO CREATE PROCEDURE bar() SELECT 1;",
ExpectedErrStr: "Can't create a PROCEDURE from within another stored routine",
Skip: true,
ExpectedErrStr: "can't create a PROCEDURE from within another stored routine",
},
},
},
Expand All @@ -2828,11 +2836,11 @@ var ProcedureCreateInSubroutineTests = []ScriptTest{
Assertions: []ScriptTestAssertion{
{
Query: "create procedure p() create table t (pk int);",
ExpectedErrStr: "creating tables in stored procedures is currently unsupported and will be added in a future release",
ExpectedErrStr: "CREATE statements in CREATE PROCEDURE not yet supported",
},
{
Query: "create procedure p() begin create table t (pk int); end;",
ExpectedErrStr: "creating tables in stored procedures is currently unsupported and will be added in a future release",
ExpectedErrStr: "CREATE statements in CREATE PROCEDURE not yet supported",
},
},
},
Expand All @@ -2844,11 +2852,11 @@ var ProcedureCreateInSubroutineTests = []ScriptTest{
Assertions: []ScriptTestAssertion{
{
Query: "create procedure p() create trigger trig before insert on t for each row begin select 1; end;",
ExpectedErrStr: "creating triggers in stored procedures is currently unsupported and will be added in a future release",
ExpectedErrStr: "can't create a TRIGGER from within another stored routine",
},
{
Query: "create procedure p() begin create trigger trig before insert on t for each row begin select 1; end; end;",
ExpectedErrStr: "creating triggers in stored procedures is currently unsupported and will be added in a future release",
ExpectedErrStr: "can't create a TRIGGER from within another stored routine",
},
},
},
Expand All @@ -2858,11 +2866,11 @@ var ProcedureCreateInSubroutineTests = []ScriptTest{
Assertions: []ScriptTestAssertion{
{
Query: "create procedure p() create database procdb;",
ExpectedErrStr: "creating databases in stored procedures is currently unsupported and will be added in a future release",
ExpectedErrStr: "DBDDL in CREATE PROCEDURE not yet supported",
},
{
Query: "create procedure p() begin create database procdb; end;",
ExpectedErrStr: "creating databases in stored procedures is currently unsupported and will be added in a future release",
ExpectedErrStr: "DBDDL in CREATE PROCEDURE not yet supported",
},
},
},
Expand All @@ -2872,11 +2880,11 @@ var ProcedureCreateInSubroutineTests = []ScriptTest{
Assertions: []ScriptTestAssertion{
{
Query: "create procedure p() create view v as select 1;",
ExpectedErrStr: "creating views in stored procedures is currently unsupported and will be added in a future release",
ExpectedErrStr: "CREATE statements in CREATE PROCEDURE not yet supported",
},
{
Query: "create procedure p() begin create view v as select 1; end;",
ExpectedErrStr: "creating views in stored procedures is currently unsupported and will be added in a future release",
ExpectedErrStr: "CREATE statements in CREATE PROCEDURE not yet supported",
},
},
},
Expand Down
5 changes: 0 additions & 5 deletions enginetest/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -10971,11 +10971,6 @@ var ErrorQueries = []QueryErrorTest{
Query: `SELECT * FROM datetime_table where datetime_col >= 'not a valid datetime'`,
ExpectedErr: types.ErrConvertingToTime,
},
// this query was panicing, but should be allowed and should return error when this query is called
{
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);`,
ExpectedErr: sql.ErrFunctionNotFound,
},
{
Query: "CREATE TABLE table_test (id int PRIMARY KEY, c float DEFAULT rand())",
ExpectedErr: sql.ErrSyntaxError,
Expand Down
36 changes: 10 additions & 26 deletions enginetest/queries/trigger_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -3230,39 +3230,23 @@ for each row
}

var TriggerCreateInSubroutineTests = []ScriptTest{
//TODO: Match MySQL behavior (https://github.com/dolthub/dolt/issues/8053)
{
Name: "procedure must not contain CREATE TRIGGER",
Assertions: []ScriptTestAssertion{
{
Query: "CREATE PROCEDURE foo() CREATE PROCEDURE bar() SELECT 0;",
// MySQL's error message: "Can't create a PROCEDURE from within another stored routine",
ExpectedErrStr: "creating procedures in stored procedures is currently unsupported and will be added in a future release",
},
},
},
{
Name: "event must not contain CREATE TRIGGER",
Assertions: []ScriptTestAssertion{
{
// Skipped because MySQL errors here but we don't.
Query: "CREATE EVENT foo ON SCHEDULE EVERY 1 YEAR DO CREATE PROCEDURE bar() SELECT 1;",
ExpectedErrStr: "Can't create a PROCEDURE from within another stored routine",
Skip: true,
},
},
},
{
Name: "trigger must not contain CREATE TRIGGER",
Name: "triggers cannot contain or be contained in other stored routines",
SetUpScript: []string{
"CREATE TABLE t (pk INT PRIMARY KEY);",
},
Assertions: []ScriptTestAssertion{
{
// Skipped because MySQL errors here but we don't.
Query: "CREATE PROCEDURE bar() CREATE TRIGGER foo AFTER UPDATE ON t FOR EACH ROW BEGIN SELECT 1; END;",
ExpectedErrStr: "can't create a TRIGGER from within another stored routine",
},
{
Query: "CREATE TRIGGER foo AFTER UPDATE ON t FOR EACH ROW BEGIN CREATE PROCEDURE bar() SELECT 1; END",
ExpectedErrStr: "Can't create a PROCEDURE from within another stored routine",
Skip: true,
ExpectedErrStr: "can't create a PROCEDURE from within another stored routine",
},
{
Query: "CREATE EVENT foo ON SCHEDULE EVERY 1 YEAR DO CREATE TRIGGER foo AFTER UPDATE ON t FOR EACH ROW BEGIN SELECT 1; END;",
ExpectedErrStr: "can't create a TRIGGER from within another stored routine",
},
},
},
Expand Down
3 changes: 1 addition & 2 deletions sql/analyzer/replace_count_star.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ func replaceCountStar(ctx *sql.Context, a *Analyzer, n sql.Node, _ *plan.Scope,

return transform.Node(n, func(n sql.Node) (sql.Node, transform.TreeIdentity, error) {
if agg, ok := n.(*plan.GroupBy); ok {

if len(agg.GroupByExprs) == 0 && !qFlags.JoinIsSet() && !qFlags.SubqueryIsSet() && !qFlags.IsSet(sql.QFlagAnyAgg) {
if len(agg.GroupByExprs) == 0 && !qFlags.JoinIsSet() && !qFlags.SubqueryIsSet() && !qFlags.IsSet(sql.QFlagAnyAgg) && !qFlags.IsSet(sql.QFlagAnalyzeProcedure) {
// top-level aggregation with a single group and no "any_value" functions can only return one row
qFlags.Set(sql.QFlagMax1Row)
}
Expand Down
Loading