MDEV-34316 sql_mode=ORACLE: Ignore the NOCOPY keyword in stored routine parameters

During sql_mode=ORACLE, ignore the NOCOPY keyword in stored routine
parameters. The optimization (pass-by-reference instead of
pass-by-value) helping to avoid value copying will be done in a separate
task when needed.
This commit is contained in:
sts-kokseng.wong 2024-09-09 17:52:52 +08:00 committed by Nikita Malyavin
parent f493e46494
commit 43825af101
4 changed files with 232 additions and 1 deletions

View file

@ -0,0 +1,103 @@
#
# MDEV-34316 sql_mode=ORACLE: Ignore the NOCOPY keyword in stored routine parameters
#
#
# sql_mode=DEFAULT. Test with function, IN NOCOPY
#
CREATE OR REPLACE FUNCTION example_func(IN NOCOPY p_in INT) RETURNS INT
BEGIN
RETURN 0;
END;
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOCOPY p_in INT) RETURNS INT
BEGIN
RETURN 0;
END' at line 1
#
# sql_mode=DEFAULT. Test with function, OUT NOCOPY
#
CREATE OR REPLACE FUNCTION example_func(OUT NOCOPY p_out INT) RETURNS INT
BEGIN
RETURN 0;
END;
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOCOPY p_out INT) RETURNS INT
BEGIN
RETURN 0;
END' at line 1
#
# sql_mode=DEFAULT. Test with function, INOUT NOCOPY
#
CREATE OR REPLACE FUNCTION example_func(INOUT NOCOPY p_inout INT) RETURNS INT
BEGIN
RETURN 0;
END;
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOCOPY p_inout INT) RETURNS INT
BEGIN
RETURN 0;
END' at line 1
#
# sql_mode=DEFAULT. Test with procedure, IN NOCOPY
#
CREATE OR REPLACE PROCEDURE example_proc(IN NOCOPY p_in INT)
BEGIN
END;
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOCOPY p_in INT)
BEGIN
END' at line 1
#
# sql_mode=DEFAULT. Test with procedure, OUT NOCOPY
#
CREATE OR REPLACE PROCEDURE example_proc(OUT NOCOPY p_out INT)
BEGIN
END;
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOCOPY p_out INT)
BEGIN
END' at line 1
#
# sql_mode=DEFAULT. Test with procedure, INOUT NOCOPY
#
CREATE OR REPLACE PROCEDURE example_proc(INOUT NOCOPY p_inout INT)
BEGIN
END;
$$
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NOCOPY p_inout INT)
BEGIN
END' at line 1
SET sql_mode=ORACLE;
#
# sql_mode=ORACLE. Test with function
#
CREATE OR REPLACE FUNCTION example_func(
p_in1 IN VARCHAR(255),
p_in2 IN NOCOPY VARCHAR(255),
p_out1 OUT INT,
p_out2 OUT NOCOPY INT,
p_in_out1 IN OUT VARCHAR(255),
p_in_out2 IN OUT NOCOPY VARCHAR(255),
p_in_out3 INOUT NUMBER,
p_in_out4 INOUT NOCOPY NUMBER) RETURN NUMBER AS
BEGIN
RETURN 0;
END;
$$
DROP FUNCTION example_func;
#
# sql_mode=ORACLE. Test with procedure
#
CREATE OR REPLACE PROCEDURE example_proc(
p_in1 IN VARCHAR(255),
p_in2 IN NOCOPY VARCHAR(255),
p_out1 OUT INT,
p_out2 OUT NOCOPY INT,
p_in_out1 IN OUT VARCHAR(255),
p_in_out2 IN OUT NOCOPY VARCHAR(255),
p_in_out3 INOUT NUMBER,
p_in_out4 INOUT NOCOPY NUMBER) AS
BEGIN
END;
$$
DROP PROCEDURE example_proc;

View file

@ -0,0 +1,121 @@
--echo #
--echo # MDEV-34316 sql_mode=ORACLE: Ignore the NOCOPY keyword in stored routine parameters
--echo #
DELIMITER $$;
--echo #
--echo # sql_mode=DEFAULT. Test with function, IN NOCOPY
--echo #
--error ER_PARSE_ERROR
CREATE OR REPLACE FUNCTION example_func(IN NOCOPY p_in INT) RETURNS INT
BEGIN
RETURN 0;
END;
$$
--echo #
--echo # sql_mode=DEFAULT. Test with function, OUT NOCOPY
--echo #
--error ER_PARSE_ERROR
CREATE OR REPLACE FUNCTION example_func(OUT NOCOPY p_out INT) RETURNS INT
BEGIN
RETURN 0;
END;
$$
--echo #
--echo # sql_mode=DEFAULT. Test with function, INOUT NOCOPY
--echo #
--error ER_PARSE_ERROR
CREATE OR REPLACE FUNCTION example_func(INOUT NOCOPY p_inout INT) RETURNS INT
BEGIN
RETURN 0;
END;
$$
--echo #
--echo # sql_mode=DEFAULT. Test with procedure, IN NOCOPY
--echo #
--error ER_PARSE_ERROR
CREATE OR REPLACE PROCEDURE example_proc(IN NOCOPY p_in INT)
BEGIN
END;
$$
--echo #
--echo # sql_mode=DEFAULT. Test with procedure, OUT NOCOPY
--echo #
--error ER_PARSE_ERROR
CREATE OR REPLACE PROCEDURE example_proc(OUT NOCOPY p_out INT)
BEGIN
END;
$$
--echo #
--echo # sql_mode=DEFAULT. Test with procedure, INOUT NOCOPY
--echo #
--error ER_PARSE_ERROR
CREATE OR REPLACE PROCEDURE example_proc(INOUT NOCOPY p_inout INT)
BEGIN
END;
$$
DELIMITER ;$$
SET sql_mode=ORACLE;
--echo #
--echo # sql_mode=ORACLE. Test with function
--echo #
DELIMITER $$;
CREATE OR REPLACE FUNCTION example_func(
p_in1 IN VARCHAR(255),
p_in2 IN NOCOPY VARCHAR(255),
p_out1 OUT INT,
p_out2 OUT NOCOPY INT,
p_in_out1 IN OUT VARCHAR(255),
p_in_out2 IN OUT NOCOPY VARCHAR(255),
p_in_out3 INOUT NUMBER,
p_in_out4 INOUT NOCOPY NUMBER) RETURN NUMBER AS
BEGIN
RETURN 0;
END;
$$
DELIMITER ;$$
DROP FUNCTION example_func;
--echo #
--echo # sql_mode=ORACLE. Test with procedure
--echo #
DELIMITER $$;
CREATE OR REPLACE PROCEDURE example_proc(
p_in1 IN VARCHAR(255),
p_in2 IN NOCOPY VARCHAR(255),
p_out1 OUT INT,
p_out2 OUT NOCOPY INT,
p_in_out1 IN OUT VARCHAR(255),
p_in_out2 IN OUT NOCOPY VARCHAR(255),
p_in_out3 INOUT NUMBER,
p_in_out4 INOUT NOCOPY NUMBER) AS
BEGIN
END;
$$
DELIMITER ;$$
DROP PROCEDURE example_proc;

View file

@ -432,6 +432,7 @@ SYMBOL symbols[] = {
{ "NEXT", SYM(NEXT_SYM)},
{ "NEXTVAL", SYM(NEXTVAL_SYM)},
{ "NO", SYM(NO_SYM)},
{ "NOCOPY", SYM(NOCOPY_SYM)},
{ "NOMAXVALUE", SYM(NOMAXVALUE_SYM)},
{ "NOMINVALUE", SYM(NOMINVALUE_SYM)},
{ "NOCACHE", SYM(NOCACHE_SYM)},

View file

@ -727,6 +727,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
%token <kwd> ELSIF_MARIADB_SYM // PLSQL-R
%token <kwd> EXCEPTION_ORACLE_SYM // SQL-2003-N, PLSQL-R
%token <kwd> GOTO_MARIADB_SYM // Oracle-R
%token <kwd> NOCOPY_SYM
%token <kwd> OTHERS_MARIADB_SYM // SQL-2011-N, PLSQL-R
%token <kwd> PACKAGE_MARIADB_SYM // Oracle-R
%token <kwd> RAISE_MARIADB_SYM // PLSQL-R
@ -19048,6 +19049,11 @@ sp_opt_default:
}
;
sp_opt_nocopy:
_empty
| NOCOPY_SYM
;
sp_opt_inout:
_empty { $$= sp_variable::MODE_IN; }
| sp_parameter_type
@ -19461,7 +19467,7 @@ sp_decl_variable_list_anchored:
;
sp_param_name_and_mode:
sp_param_name sp_opt_inout
sp_param_name sp_opt_inout sp_opt_nocopy
{
$1->mode= $2;
$$= $1;