matrixorigin / matrixorigin/matrixone

[Bug]: MySQL-style CREATE PROCEDURE/FUNCTION BEGIN...END syntax is not supported

Open
#25,409 0 comments 0 reactions 1 assignee Claimed by @daviszhen View on GitHub
deferred kind/bug
Dominant language
Go
Stars
1.9k
Forks
311
Avg merge
1d 3h
Merged PRs (30d)
768

Description

### Environment

- Branch: latest `main`
- MO git version: `51656deb6`
- MySQL oracle: `8.0.45`

### Reference behavior

MySQL supports stored routines using `CREATE PROCEDURE` / `CREATE FUNCTION` with `BEGIN ... END` compound statements:
https://dev.mysql.com/doc/en/create-procedure.html

MySQL stored routines also support local variables, OUT parameters, handlers, and cursors:
https://dev.mysql.com/doc/en/cursors.html

### Reproduce

```sql
drop database if exists mysql_compat_model15_routine;
create database mysql_compat_model15_routine;
use mysql_compat_model15_routine;

create table t_routine (
id int primary key,
grp int,
v varchar(20),
key idx_grp_v(grp, v)
);
insert into t_routine values
(1,10,'a'),
(2,10,'b'),
(3,20,'c'),
(4,null,null);

delimiter $$

create procedure p_basic(in p_min int, out p_cnt int)
begin
select count(*) into p_cnt from t_routine where id >= p_min;
select id, v from t_routine where id >= p_min order by id;
end$$

create function f_add(x int, y int)
returns int
deterministic
no sql
begin
return x + y;
end$$

delimiter ;

call p_basic(2, @cnt);
select @cnt as out_count;
select f_add(2,3) as f_add_result;
```

### MySQL result

```text
id v
2 b
3 c
4 NULL

out_count
3

f_add_result
5
```

### MO result

```text
ERROR 1064 (HY000): SQL parser error ... near "
begin
select count(*) into p_cnt from t_routine where id >= p_min;
select id, v from t_routine where id >= p_min order by id;
end";

ERROR 1064 (HY000): SQL parser error ... near "
deterministic
no sql
begin
return x + y;
end";

ERROR 1122 (HY000): function p_basic doesn't exist
ERROR 20101 (HY000): internal error: the user variable cnt does not exist
ERROR 20105 (HY000): not supported: function or operator 'f_add'
```

### Expected

MO should accept MySQL-compatible stored routine syntax for `CREATE PROCEDURE` and `CREATE FUNCTION`, including `BEGIN ... END` routine bodies and standard routine characteristics such as `DETERMINISTIC` / `NO SQL`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.