Skip to content

Commit 43825af

Browse files
wong-github1FooBarrior
authored andcommitted
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.
1 parent f493e46 commit 43825af

File tree

4 files changed

+232
-1
lines changed

4 files changed

+232
-1
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#
2+
# MDEV-34316 sql_mode=ORACLE: Ignore the NOCOPY keyword in stored routine parameters
3+
#
4+
#
5+
# sql_mode=DEFAULT. Test with function, IN NOCOPY
6+
#
7+
CREATE OR REPLACE FUNCTION example_func(IN NOCOPY p_in INT) RETURNS INT
8+
BEGIN
9+
RETURN 0;
10+
END;
11+
$$
12+
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
13+
BEGIN
14+
RETURN 0;
15+
END' at line 1
16+
#
17+
# sql_mode=DEFAULT. Test with function, OUT NOCOPY
18+
#
19+
CREATE OR REPLACE FUNCTION example_func(OUT NOCOPY p_out INT) RETURNS INT
20+
BEGIN
21+
RETURN 0;
22+
END;
23+
$$
24+
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
25+
BEGIN
26+
RETURN 0;
27+
END' at line 1
28+
#
29+
# sql_mode=DEFAULT. Test with function, INOUT NOCOPY
30+
#
31+
CREATE OR REPLACE FUNCTION example_func(INOUT NOCOPY p_inout INT) RETURNS INT
32+
BEGIN
33+
RETURN 0;
34+
END;
35+
$$
36+
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
37+
BEGIN
38+
RETURN 0;
39+
END' at line 1
40+
#
41+
# sql_mode=DEFAULT. Test with procedure, IN NOCOPY
42+
#
43+
CREATE OR REPLACE PROCEDURE example_proc(IN NOCOPY p_in INT)
44+
BEGIN
45+
END;
46+
$$
47+
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)
48+
BEGIN
49+
END' at line 1
50+
#
51+
# sql_mode=DEFAULT. Test with procedure, OUT NOCOPY
52+
#
53+
CREATE OR REPLACE PROCEDURE example_proc(OUT NOCOPY p_out INT)
54+
BEGIN
55+
END;
56+
$$
57+
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)
58+
BEGIN
59+
END' at line 1
60+
#
61+
# sql_mode=DEFAULT. Test with procedure, INOUT NOCOPY
62+
#
63+
CREATE OR REPLACE PROCEDURE example_proc(INOUT NOCOPY p_inout INT)
64+
BEGIN
65+
END;
66+
$$
67+
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)
68+
BEGIN
69+
END' at line 1
70+
SET sql_mode=ORACLE;
71+
#
72+
# sql_mode=ORACLE. Test with function
73+
#
74+
CREATE OR REPLACE FUNCTION example_func(
75+
p_in1 IN VARCHAR(255),
76+
p_in2 IN NOCOPY VARCHAR(255),
77+
p_out1 OUT INT,
78+
p_out2 OUT NOCOPY INT,
79+
p_in_out1 IN OUT VARCHAR(255),
80+
p_in_out2 IN OUT NOCOPY VARCHAR(255),
81+
p_in_out3 INOUT NUMBER,
82+
p_in_out4 INOUT NOCOPY NUMBER) RETURN NUMBER AS
83+
BEGIN
84+
RETURN 0;
85+
END;
86+
$$
87+
DROP FUNCTION example_func;
88+
#
89+
# sql_mode=ORACLE. Test with procedure
90+
#
91+
CREATE OR REPLACE PROCEDURE example_proc(
92+
p_in1 IN VARCHAR(255),
93+
p_in2 IN NOCOPY VARCHAR(255),
94+
p_out1 OUT INT,
95+
p_out2 OUT NOCOPY INT,
96+
p_in_out1 IN OUT VARCHAR(255),
97+
p_in_out2 IN OUT NOCOPY VARCHAR(255),
98+
p_in_out3 INOUT NUMBER,
99+
p_in_out4 INOUT NOCOPY NUMBER) AS
100+
BEGIN
101+
END;
102+
$$
103+
DROP PROCEDURE example_proc;

mysql-test/main/sp-ignore_nocopy.test

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
--echo #
2+
--echo # MDEV-34316 sql_mode=ORACLE: Ignore the NOCOPY keyword in stored routine parameters
3+
--echo #
4+
5+
DELIMITER $$;
6+
7+
--echo #
8+
--echo # sql_mode=DEFAULT. Test with function, IN NOCOPY
9+
--echo #
10+
11+
--error ER_PARSE_ERROR
12+
CREATE OR REPLACE FUNCTION example_func(IN NOCOPY p_in INT) RETURNS INT
13+
BEGIN
14+
RETURN 0;
15+
END;
16+
$$
17+
18+
--echo #
19+
--echo # sql_mode=DEFAULT. Test with function, OUT NOCOPY
20+
--echo #
21+
22+
--error ER_PARSE_ERROR
23+
CREATE OR REPLACE FUNCTION example_func(OUT NOCOPY p_out INT) RETURNS INT
24+
BEGIN
25+
RETURN 0;
26+
END;
27+
$$
28+
29+
--echo #
30+
--echo # sql_mode=DEFAULT. Test with function, INOUT NOCOPY
31+
--echo #
32+
33+
--error ER_PARSE_ERROR
34+
CREATE OR REPLACE FUNCTION example_func(INOUT NOCOPY p_inout INT) RETURNS INT
35+
BEGIN
36+
RETURN 0;
37+
END;
38+
$$
39+
40+
--echo #
41+
--echo # sql_mode=DEFAULT. Test with procedure, IN NOCOPY
42+
--echo #
43+
44+
--error ER_PARSE_ERROR
45+
CREATE OR REPLACE PROCEDURE example_proc(IN NOCOPY p_in INT)
46+
BEGIN
47+
END;
48+
$$
49+
50+
--echo #
51+
--echo # sql_mode=DEFAULT. Test with procedure, OUT NOCOPY
52+
--echo #
53+
54+
--error ER_PARSE_ERROR
55+
CREATE OR REPLACE PROCEDURE example_proc(OUT NOCOPY p_out INT)
56+
BEGIN
57+
END;
58+
$$
59+
60+
--echo #
61+
--echo # sql_mode=DEFAULT. Test with procedure, INOUT NOCOPY
62+
--echo #
63+
64+
--error ER_PARSE_ERROR
65+
CREATE OR REPLACE PROCEDURE example_proc(INOUT NOCOPY p_inout INT)
66+
BEGIN
67+
END;
68+
$$
69+
70+
DELIMITER ;$$
71+
72+
SET sql_mode=ORACLE;
73+
74+
--echo #
75+
--echo # sql_mode=ORACLE. Test with function
76+
--echo #
77+
78+
DELIMITER $$;
79+
80+
CREATE OR REPLACE FUNCTION example_func(
81+
p_in1 IN VARCHAR(255),
82+
p_in2 IN NOCOPY VARCHAR(255),
83+
p_out1 OUT INT,
84+
p_out2 OUT NOCOPY INT,
85+
p_in_out1 IN OUT VARCHAR(255),
86+
p_in_out2 IN OUT NOCOPY VARCHAR(255),
87+
p_in_out3 INOUT NUMBER,
88+
p_in_out4 INOUT NOCOPY NUMBER) RETURN NUMBER AS
89+
BEGIN
90+
RETURN 0;
91+
END;
92+
93+
$$
94+
95+
DELIMITER ;$$
96+
97+
DROP FUNCTION example_func;
98+
99+
--echo #
100+
--echo # sql_mode=ORACLE. Test with procedure
101+
--echo #
102+
103+
DELIMITER $$;
104+
105+
CREATE OR REPLACE PROCEDURE example_proc(
106+
p_in1 IN VARCHAR(255),
107+
p_in2 IN NOCOPY VARCHAR(255),
108+
p_out1 OUT INT,
109+
p_out2 OUT NOCOPY INT,
110+
p_in_out1 IN OUT VARCHAR(255),
111+
p_in_out2 IN OUT NOCOPY VARCHAR(255),
112+
p_in_out3 INOUT NUMBER,
113+
p_in_out4 INOUT NOCOPY NUMBER) AS
114+
BEGIN
115+
END;
116+
117+
$$
118+
119+
DELIMITER ;$$
120+
121+
DROP PROCEDURE example_proc;

sql/lex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ SYMBOL symbols[] = {
432432
{ "NEXT", SYM(NEXT_SYM)},
433433
{ "NEXTVAL", SYM(NEXTVAL_SYM)},
434434
{ "NO", SYM(NO_SYM)},
435+
{ "NOCOPY", SYM(NOCOPY_SYM)},
435436
{ "NOMAXVALUE", SYM(NOMAXVALUE_SYM)},
436437
{ "NOMINVALUE", SYM(NOMINVALUE_SYM)},
437438
{ "NOCACHE", SYM(NOCACHE_SYM)},

sql/sql_yacc.yy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
727727
%token <kwd> ELSIF_MARIADB_SYM // PLSQL-R
728728
%token <kwd> EXCEPTION_ORACLE_SYM // SQL-2003-N, PLSQL-R
729729
%token <kwd> GOTO_MARIADB_SYM // Oracle-R
730+
%token <kwd> NOCOPY_SYM
730731
%token <kwd> OTHERS_MARIADB_SYM // SQL-2011-N, PLSQL-R
731732
%token <kwd> PACKAGE_MARIADB_SYM // Oracle-R
732733
%token <kwd> RAISE_MARIADB_SYM // PLSQL-R
@@ -19048,6 +19049,11 @@ sp_opt_default:
1904819049
}
1904919050
;
1905019051

19052+
sp_opt_nocopy:
19053+
_empty
19054+
| NOCOPY_SYM
19055+
;
19056+
1905119057
sp_opt_inout:
1905219058
_empty { $$= sp_variable::MODE_IN; }
1905319059
| sp_parameter_type
@@ -19461,7 +19467,7 @@ sp_decl_variable_list_anchored:
1946119467
;
1946219468

1946319469
sp_param_name_and_mode:
19464-
sp_param_name sp_opt_inout
19470+
sp_param_name sp_opt_inout sp_opt_nocopy
1946519471
{
1946619472
$1->mode= $2;
1946719473
$$= $1;

0 commit comments

Comments
 (0)