From 74b4171591692a673572ed80a00b961db6fcc53c Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 30 Oct 2019 16:05:36 +0400 Subject: [PATCH] sql_yacc_ora.yy: syncing grammar for "MDEV-18844 Implement EXCEPT ALL and INTERSECT ALL operations" --- mysql-test/main/set_operation_oracle.result | 70 ++++++++++++++++++--- mysql-test/main/set_operation_oracle.test | 28 +++++---- sql/sql_yacc_ora.yy | 8 +-- 3 files changed, 82 insertions(+), 24 deletions(-) diff --git a/mysql-test/main/set_operation_oracle.result b/mysql-test/main/set_operation_oracle.result index 28f6e315005..947e5e9a11c 100644 --- a/mysql-test/main/set_operation_oracle.result +++ b/mysql-test/main/set_operation_oracle.result @@ -59,17 +59,69 @@ insert into t1 values (5,5),(6,6); insert into t2 values (2,2),(3,3); insert into t3 values (1,1),(3,3); set SQL_MODE=ORACLE; -(select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4); -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 'all (select e,f from t3) union all (select 4,4)' at line 1 -explain extended (select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4); -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 'all (select e,f from t3) union all (select 4,4)' at line 1 -(select e,f from t3) intersect all (select c,d from t2) union all (select a,b from t1) union all (select 4,4); -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 'all (select c,d from t2) union all (select a,b from t1) union all (select 4,4)' at line 1 -explain extended (select e,f from t3) intersect all (select c,d from t2) union all (select a,b from t1) union all (select 4,4); -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 'all (select c,d from t2) union all (select a,b from t1) union all (select 4,4)' at line 1 +select a,b from t1 union all select c,d from t2 intersect select e,f from t3 union all select 4,'4' from dual; +a b +4 4 +3 3 +explain extended +select a,b from t1 union all select c,d from t2 intersect select e,f from t3 union all select 4,'4' from dual; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 +2 UNION t2 ALL NULL NULL NULL NULL 2 100.00 +3 INTERSECT t3 ALL NULL NULL NULL NULL 2 100.00 +4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNIT RESULT ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" union all /* select#2 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2" intersect /* select#3 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3" union all /* select#4 */ select 4 AS "4",'4' AS "4" +select a,b from t1 union all select c,d from t2 intersect all select e,f from t3 union all select 4,'4' from dual; +a b +3 3 +4 4 +explain extended +select a,b from t1 union all select c,d from t2 intersect all select e,f from t3 union all select 4,'4' from dual; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 +2 UNION t2 ALL NULL NULL NULL NULL 2 100.00 +3 INTERSECT t3 ALL NULL NULL NULL NULL 2 100.00 +4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNIT RESULT ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 /* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" union all /* select#2 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2" intersect all /* select#3 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3" union all /* select#4 */ select 4 AS "4",'4' AS "4" +select e,f from t3 intersect select c,d from t2 union all select a,b from t1 union all select 4,'4' from dual; +e f +5 5 +3 3 +6 6 +4 4 +explain extended +select e,f from t3 intersect select c,d from t2 union all select a,b from t1 union all select 4,'4' from dual; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 +2 INTERSECT t2 ALL NULL NULL NULL NULL 2 100.00 +3 UNION t1 ALL NULL NULL NULL NULL 2 100.00 +4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNIT RESULT ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 /* select#1 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3" intersect /* select#2 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2" union all /* select#3 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" union all /* select#4 */ select 4 AS "4",'4' AS "4" +select e,f from t3 intersect all select c,d from t2 union all select a,b from t1 union all select 4,'4' from dual; +e f +3 3 +5 5 +6 6 +4 4 +explain extended +select e,f from t3 intersect all select c,d from t2 union all select a,b from t1 union all select 4,'4' from dual; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 +2 INTERSECT t2 ALL NULL NULL NULL NULL 2 100.00 +3 UNION t1 ALL NULL NULL NULL NULL 2 100.00 +4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNIT RESULT ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 /* select#1 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3" intersect all /* select#2 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2" union all /* select#3 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" union all /* select#4 */ select 4 AS "4",'4' AS "4" set SQL_MODE=default; drop table t1,t2,t3; set SQL_MODE=oracle; select * from t13 union select * from t234 intersect all select * from t12; -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 'all select * from t12' at line 1 +ERROR 42S02: Table 'test.t13' doesn't exist set SQL_MODE=default; diff --git a/mysql-test/main/set_operation_oracle.test b/mysql-test/main/set_operation_oracle.test index bd2a4d5c6e2..60fda4a5cb5 100644 --- a/mysql-test/main/set_operation_oracle.test +++ b/mysql-test/main/set_operation_oracle.test @@ -45,21 +45,27 @@ insert into t3 values (1,1),(3,3); set SQL_MODE=ORACLE; -#(select a,b from t1) union all (select c,d from t2) intersect (select e,f from t3) union all (select 4,4); ---error ER_PARSE_ERROR -(select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4); ---error ER_PARSE_ERROR -explain extended (select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4); +select a,b from t1 union all select c,d from t2 intersect select e,f from t3 union all select 4,'4' from dual; +explain extended +select a,b from t1 union all select c,d from t2 intersect select e,f from t3 union all select 4,'4' from dual; + +select a,b from t1 union all select c,d from t2 intersect all select e,f from t3 union all select 4,'4' from dual; +explain extended +select a,b from t1 union all select c,d from t2 intersect all select e,f from t3 union all select 4,'4' from dual; + +select e,f from t3 intersect select c,d from t2 union all select a,b from t1 union all select 4,'4' from dual; +explain extended +select e,f from t3 intersect select c,d from t2 union all select a,b from t1 union all select 4,'4' from dual; + +select e,f from t3 intersect all select c,d from t2 union all select a,b from t1 union all select 4,'4' from dual; +explain extended +select e,f from t3 intersect all select c,d from t2 union all select a,b from t1 union all select 4,'4' from dual; ---error ER_PARSE_ERROR -(select e,f from t3) intersect all (select c,d from t2) union all (select a,b from t1) union all (select 4,4); ---error ER_PARSE_ERROR -explain extended (select e,f from t3) intersect all (select c,d from t2) union all (select a,b from t1) union all (select 4,4); set SQL_MODE=default; drop table t1,t2,t3; set SQL_MODE=oracle; ---error ER_PARSE_ERROR +--error ER_NO_SUCH_TABLE select * from t13 union select * from t234 intersect all select * from t12; -set SQL_MODE=default; \ No newline at end of file +set SQL_MODE=default; diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index b64dea9ad74..2b54f801548 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -18184,10 +18184,10 @@ release: unit_type_decl: UNION_SYM union_option { $$.unit_type= UNION_TYPE; $$.distinct= $2; } - | INTERSECT_SYM - { $$.unit_type= INTERSECT_TYPE; $$.distinct= 1; } - | EXCEPT_SYM - { $$.unit_type= EXCEPT_TYPE; $$.distinct= 1; } + | INTERSECT_SYM union_option + { $$.unit_type= INTERSECT_TYPE; $$.distinct= $2; } + | EXCEPT_SYM union_option + { $$.unit_type= EXCEPT_TYPE; $$.distinct= $2; } ; /*