Skip to content

Commit cf93209

Browse files
montywivuvova
authored andcommitted
MDEV-20021 sql_mode="oracle" does not support MINUS set operator
MINUS is mapped to EXCEPT One consequence of the patch is that MINUS becomes a reserved word in Oracle mode. Author: woqutech
1 parent b8c3159 commit cf93209

File tree

6 files changed

+103
-2
lines changed

6 files changed

+103
-2
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
CREATE TABLE tx1 (c1 int, c2 varchar(30));
2+
CREATE TABLE tx2 (c1 int, c2 varchar(30));
3+
CREATE TABLE tx3 (c1 int, c2 varchar(30));
4+
INSERT INTO tx1 VALUES (1, 'jim');
5+
INSERT INTO tx1 VALUES (2, 'menny');
6+
INSERT INTO tx1 VALUES (3, 'linda');
7+
INSERT INTO tx2 VALUES (1, 'jim');
8+
INSERT INTO tx2 VALUES (2, 'kris');
9+
INSERT INTO tx2 VALUES (3, 'shory');
10+
INSERT INTO tx3 VALUES (1, 'jim');
11+
INSERT INTO tx3 VALUES (2, 'kris');
12+
INSERT INTO tx3 VALUES (3, 'linda');
13+
#
14+
# test when sql_mode is not oracle
15+
#
16+
SELECT c2 FROM tx1 EXCEPT SELECT c2 from tx2;
17+
c2
18+
menny
19+
linda
20+
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2;
21+
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 'SELECT c2 from tx2' at line 1
22+
create table MINUS (a int);
23+
drop table MINUS;
24+
#
25+
# test when sql_mode is oracle
26+
#
27+
SET sql_mode=ORACLE;
28+
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2;
29+
c2
30+
menny
31+
linda
32+
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 MINUS SELECT c2 from tx3;
33+
c2
34+
menny
35+
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 EXCEPT SELECT c2 from tx3;
36+
c2
37+
menny
38+
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 UNION SELECT c2 from tx3;
39+
c2
40+
jim
41+
menny
42+
linda
43+
kris
44+
create table MINUS (a int);
45+
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 'MINUS (a int)' at line 1
46+
DROP TABLE tx1;
47+
DROP TABLE tx2;
48+
DROP TABLE tx3;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
CREATE TABLE tx1 (c1 int, c2 varchar(30));
2+
CREATE TABLE tx2 (c1 int, c2 varchar(30));
3+
CREATE TABLE tx3 (c1 int, c2 varchar(30));
4+
INSERT INTO tx1 VALUES (1, 'jim');
5+
INSERT INTO tx1 VALUES (2, 'menny');
6+
INSERT INTO tx1 VALUES (3, 'linda');
7+
8+
INSERT INTO tx2 VALUES (1, 'jim');
9+
INSERT INTO tx2 VALUES (2, 'kris');
10+
INSERT INTO tx2 VALUES (3, 'shory');
11+
12+
INSERT INTO tx3 VALUES (1, 'jim');
13+
INSERT INTO tx3 VALUES (2, 'kris');
14+
INSERT INTO tx3 VALUES (3, 'linda');
15+
16+
--echo #
17+
--echo # test when sql_mode is not oracle
18+
--echo #
19+
20+
SELECT c2 FROM tx1 EXCEPT SELECT c2 from tx2;
21+
--error 1064
22+
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2;
23+
24+
# MINUS should not be a reserved word
25+
create table MINUS (a int);
26+
drop table MINUS;
27+
28+
--echo #
29+
--echo # test when sql_mode is oracle
30+
--echo #
31+
32+
SET sql_mode=ORACLE;
33+
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2;
34+
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 MINUS SELECT c2 from tx3;
35+
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 EXCEPT SELECT c2 from tx3;
36+
SELECT c2 FROM tx1 MINUS SELECT c2 from tx2 UNION SELECT c2 from tx3;
37+
38+
# MINUS should be a reserved word
39+
--error ER_PARSE_ERROR
40+
create table MINUS (a int);
41+
42+
DROP TABLE tx1;
43+
DROP TABLE tx2;
44+
DROP TABLE tx3;

mysql-test/suite/perfschema/r/start_server_low_digest_sql_length.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ SELECT 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
88
####################################
99
SELECT event_name, digest, digest_text, sql_text FROM events_statements_history_long;
1010
event_name digest digest_text sql_text
11-
statement/sql/select 62764f94ca18cf720c44d84579e05e60 SELECT ? + ? + SELECT ...
12-
statement/sql/truncate 5947880b8ba439f0ed3ff0bfbb04eebf TRUNCATE TABLE truncat...
11+
statement/sql/select bb82f2829bcdfd9ac1e53f7b27829d36 SELECT ? + ? + SELECT ...
12+
statement/sql/truncate fd6a2d48e5fda6a3f990cb8810136546 TRUNCATE TABLE truncat...

sql/lex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ static SYMBOL symbols[] = {
404404
{ "MICROSECOND", SYM(MICROSECOND_SYM)},
405405
{ "MIDDLEINT", SYM(MEDIUMINT)}, /* For powerbuilder */
406406
{ "MIGRATE", SYM(MIGRATE_SYM)},
407+
{ "MINUS", SYM(MINUS_ORACLE_SYM)},
407408
{ "MINUTE", SYM(MINUTE_SYM)},
408409
{ "MINUTE_MICROSECOND", SYM(MINUTE_MICROSECOND_SYM)},
409410
{ "MINUTE_SECOND", SYM(MINUTE_SECOND_SYM)},

sql/sql_lex.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,7 @@ int Lex_input_stream::find_keyword(Lex_ident_cli_st *kwd,
14041404
case EXCEPTION_MARIADB_SYM: return EXCEPTION_ORACLE_SYM;
14051405
case EXIT_MARIADB_SYM: return EXIT_ORACLE_SYM;
14061406
case GOTO_MARIADB_SYM: return GOTO_ORACLE_SYM;
1407+
case MINUS_ORACLE_SYM: return EXCEPT_SYM;
14071408
case NUMBER_MARIADB_SYM: return NUMBER_ORACLE_SYM;
14081409
case OTHERS_MARIADB_SYM: return OTHERS_ORACLE_SYM;
14091410
case PACKAGE_MARIADB_SYM: return PACKAGE_ORACLE_SYM;

sql/sql_yacc.yy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ End SQL_MODE_ORACLE_SPECIFIC */
592592
%token <kwd> MEDIUMINT
593593
%token <kwd> MEDIUMTEXT
594594
%token <kwd> MIN_SYM /* SQL-2003-N */
595+
%token <kwd> MINUS_ORACLE_SYM /* Oracle-R */
595596
%token <kwd> MINUTE_MICROSECOND_SYM
596597
%token <kwd> MINUTE_SECOND_SYM
597598
%token <kwd> MODIFIES_SYM /* SQL-2003-R */
@@ -16037,6 +16038,9 @@ keyword_sp_var_and_label:
1603716038
| MICROSECOND_SYM
1603816039
| MIGRATE_SYM
1603916040
| MINUTE_SYM
16041+
/* Start SQL_MODE_DEFAULT_SPECIFIC */
16042+
| MINUS_ORACLE_SYM
16043+
/* End SQL_MODE_DEFAULT_SPECIFIC */
1604016044
| MINVALUE_SYM
1604116045
| MIN_ROWS
1604216046
| MODIFY_SYM
@@ -16329,6 +16333,9 @@ reserved_keyword_udt_not_param_type:
1632916333
| MINUTE_MICROSECOND_SYM
1633016334
| MINUTE_SECOND_SYM
1633116335
| MIN_SYM
16336+
/* Start SQL_MODE_ORACLE_SPECIFIC
16337+
| MINUS_ORACLE_SYM
16338+
End SQL_MODE_ORACLE_SPECIFIC */
1633216339
| MODIFIES_SYM
1633316340
| MOD_SYM
1633416341
| NATURAL

0 commit comments

Comments
 (0)