diff options
author | Alexander Barkov <bar@mariadb.org> | 2016-05-21 16:52:12 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.org> | 2016-05-21 16:52:12 +0400 |
commit | a999acf26ecbe815f9b10780153384bea7840a03 (patch) | |
tree | aa3a866129d7373454c4054d31f394edd36d87c4 | |
parent | 349da1d643e6d56ba1e3e6edd3f5fcb3fddc5dee (diff) | |
download | mariadb-git-a999acf26ecbe815f9b10780153384bea7840a03.tar.gz |
MDEV-10095 Fix derived tables to return a syntax error instead of "Illegal usage of UNION and LIMIT"
-rw-r--r-- | mysql-test/r/join.result | 2 | ||||
-rw-r--r-- | mysql-test/r/parser.result | 14 | ||||
-rw-r--r-- | mysql-test/r/subselect.result | 4 | ||||
-rw-r--r-- | mysql-test/r/subselect_no_exists_to_in.result | 4 | ||||
-rw-r--r-- | mysql-test/r/subselect_no_mat.result | 4 | ||||
-rw-r--r-- | mysql-test/r/subselect_no_opts.result | 4 | ||||
-rw-r--r-- | mysql-test/r/subselect_no_scache.result | 4 | ||||
-rw-r--r-- | mysql-test/r/subselect_no_semijoin.result | 4 | ||||
-rw-r--r-- | mysql-test/t/parser.test | 14 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 55 |
10 files changed, 61 insertions, 48 deletions
diff --git a/mysql-test/r/join.result b/mysql-test/r/join.result index e7292e8ddce..536fd4ab97f 100644 --- a/mysql-test/r/join.result +++ b/mysql-test/r/join.result @@ -1476,7 +1476,7 @@ DROP TABLE t1,t2,t3,t4,t5; # MDEV-4752: Segfault during parsing of illegal query # SELECT * FROM t5 JOIN (t1 JOIN t2 UNION SELECT * FROM t3 JOIN t4); -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 ')' at line 1 +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 * FROM t3 JOIN t4)' at line 1 # # MDEV-4959: join of const table with NULL fields # diff --git a/mysql-test/r/parser.result b/mysql-test/r/parser.result index 5d1e89e6116..f42346608d5 100644 --- a/mysql-test/r/parser.result +++ b/mysql-test/r/parser.result @@ -822,19 +822,19 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp SELECT (SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1); ERROR HY000: Incorrect usage of UNION and ORDER BY SELECT 1 FROM (SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1) a; -ERROR HY000: Incorrect usage of UNION and ORDER BY +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 'UNION SELECT 1 FROM t1) a' at line 1 SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1; 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 'UNION SELECT 1 FROM t1' at line 1 SELECT (SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1); ERROR HY000: Incorrect usage of UNION and LIMIT SELECT 1 FROM (SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1) a; -ERROR HY000: Incorrect usage of UNION and LIMIT +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 'UNION SELECT 1 FROM t1) a' at line 1 SELECT 1 FROM t1 ORDER BY 1 LIMIT 1 UNION SELECT 1 FROM t1; 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 'UNION SELECT 1 FROM t1' at line 1 SELECT (SELECT 1 FROM t1 ORDER BY 1 LIMIT 1 UNION SELECT 1 FROM t1); ERROR HY000: Incorrect usage of UNION and ORDER BY SELECT 1 FROM (SELECT 1 FROM t1 ORDER BY 1 LIMIT 1 UNION SELECT 1 FROM t1) a; -ERROR HY000: Incorrect usage of UNION and ORDER BY +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 'UNION SELECT 1 FROM t1) a' at line 1 SELECT 1 FROM t1 LIMIT 1 ORDER BY 1 UNION SELECT 1 FROM t1; 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 'ORDER BY 1 UNION SELECT 1 FROM t1' at line 1 SELECT (SELECT 1 FROM t1 LIMIT 1 ORDER BY 1 UNION SELECT 1 FROM t1); @@ -846,25 +846,25 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp SELECT (SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 ORDER BY 1); ERROR HY000: Incorrect usage of UNION and ORDER BY SELECT 1 FROM (SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 ORDER BY 1) a; -ERROR HY000: Incorrect usage of UNION and ORDER BY +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 'UNION SELECT 1 FROM t1 ORDER BY 1) a' at line 1 SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 LIMIT 1; 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 'UNION SELECT 1 FROM t1 LIMIT 1' at line 1 SELECT (SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 LIMIT 1); ERROR HY000: Incorrect usage of UNION and LIMIT SELECT 1 FROM (SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 LIMIT 1) a; -ERROR HY000: Incorrect usage of UNION and LIMIT +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 'UNION SELECT 1 FROM t1 LIMIT 1) a' at line 1 SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 ORDER BY 1; 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 'UNION SELECT 1 FROM t1 ORDER BY 1' at line 1 SELECT (SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 ORDER BY 1); ERROR HY000: Incorrect usage of UNION and LIMIT SELECT 1 FROM (SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 ORDER BY 1) a; -ERROR HY000: Incorrect usage of UNION and LIMIT +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 'UNION SELECT 1 FROM t1 ORDER BY 1) a' at line 1 SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 LIMIT 1; 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 'UNION SELECT 1 FROM t1 LIMIT 1' at line 1 SELECT (SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 LIMIT 1); ERROR HY000: Incorrect usage of UNION and ORDER BY SELECT 1 FROM (SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 LIMIT 1) a; -ERROR HY000: Incorrect usage of UNION and ORDER BY +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 'UNION SELECT 1 FROM t1 LIMIT 1) a' at line 1 DROP TABLE t1; # # MDEV-8380: Subquery parse error diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 1b1198958b8..974c60d381d 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -5188,9 +5188,9 @@ a 1 SELECT * FROM t1 JOIN ((SELECT 1 UNION SELECT 1)) ON 1; ERROR 42000: Every derived table must have its own alias SELECT * FROM t1 JOIN (t1 t1a UNION SELECT 1) ON 1; -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 ') ON 1' at line 1 +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 1) ON 1' at line 1 SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1; -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 ')) ON 1' at line 1 +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 1)) ON 1' at line 1 SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1; 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 't1a ON 1' at line 1 SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1; diff --git a/mysql-test/r/subselect_no_exists_to_in.result b/mysql-test/r/subselect_no_exists_to_in.result index 39d1f64410e..6183a3bc2e4 100644 --- a/mysql-test/r/subselect_no_exists_to_in.result +++ b/mysql-test/r/subselect_no_exists_to_in.result @@ -5190,9 +5190,9 @@ a 1 SELECT * FROM t1 JOIN ((SELECT 1 UNION SELECT 1)) ON 1; ERROR 42000: Every derived table must have its own alias SELECT * FROM t1 JOIN (t1 t1a UNION SELECT 1) ON 1; -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 ') ON 1' at line 1 +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 1) ON 1' at line 1 SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1; -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 ')) ON 1' at line 1 +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 1)) ON 1' at line 1 SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1; 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 't1a ON 1' at line 1 SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1; diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result index 211d3206a7f..c9c86acf63c 100644 --- a/mysql-test/r/subselect_no_mat.result +++ b/mysql-test/r/subselect_no_mat.result @@ -5188,9 +5188,9 @@ a 1 SELECT * FROM t1 JOIN ((SELECT 1 UNION SELECT 1)) ON 1; ERROR 42000: Every derived table must have its own alias SELECT * FROM t1 JOIN (t1 t1a UNION SELECT 1) ON 1; -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 ') ON 1' at line 1 +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 1) ON 1' at line 1 SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1; -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 ')) ON 1' at line 1 +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 1)) ON 1' at line 1 SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1; 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 't1a ON 1' at line 1 SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1; diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result index 6ae9f8aa066..ce1136057bc 100644 --- a/mysql-test/r/subselect_no_opts.result +++ b/mysql-test/r/subselect_no_opts.result @@ -5184,9 +5184,9 @@ a 1 SELECT * FROM t1 JOIN ((SELECT 1 UNION SELECT 1)) ON 1; ERROR 42000: Every derived table must have its own alias SELECT * FROM t1 JOIN (t1 t1a UNION SELECT 1) ON 1; -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 ') ON 1' at line 1 +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 1) ON 1' at line 1 SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1; -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 ')) ON 1' at line 1 +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 1)) ON 1' at line 1 SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1; 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 't1a ON 1' at line 1 SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1; diff --git a/mysql-test/r/subselect_no_scache.result b/mysql-test/r/subselect_no_scache.result index 9a3fcd1de3b..e18468b9975 100644 --- a/mysql-test/r/subselect_no_scache.result +++ b/mysql-test/r/subselect_no_scache.result @@ -5194,9 +5194,9 @@ a 1 SELECT * FROM t1 JOIN ((SELECT 1 UNION SELECT 1)) ON 1; ERROR 42000: Every derived table must have its own alias SELECT * FROM t1 JOIN (t1 t1a UNION SELECT 1) ON 1; -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 ') ON 1' at line 1 +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 1) ON 1' at line 1 SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1; -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 ')) ON 1' at line 1 +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 1)) ON 1' at line 1 SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1; 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 't1a ON 1' at line 1 SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1; diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result index 10cf05649e7..a28cc7cb0d6 100644 --- a/mysql-test/r/subselect_no_semijoin.result +++ b/mysql-test/r/subselect_no_semijoin.result @@ -5184,9 +5184,9 @@ a 1 SELECT * FROM t1 JOIN ((SELECT 1 UNION SELECT 1)) ON 1; ERROR 42000: Every derived table must have its own alias SELECT * FROM t1 JOIN (t1 t1a UNION SELECT 1) ON 1; -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 ') ON 1' at line 1 +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 1) ON 1' at line 1 SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1; -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 ')) ON 1' at line 1 +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 1)) ON 1' at line 1 SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1; 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 't1a ON 1' at line 1 SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1; diff --git a/mysql-test/t/parser.test b/mysql-test/t/parser.test index ae456574c39..7d1582c397c 100644 --- a/mysql-test/t/parser.test +++ b/mysql-test/t/parser.test @@ -951,7 +951,7 @@ let $q=SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1; eval $q; --error ER_WRONG_USAGE eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1; @@ -959,7 +959,7 @@ let $q=SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1; eval $q; --error ER_WRONG_USAGE eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 ORDER BY 1 LIMIT 1 UNION SELECT 1 FROM t1; @@ -967,7 +967,7 @@ let $q=SELECT 1 FROM t1 ORDER BY 1 LIMIT 1 UNION SELECT 1 FROM t1; eval $q; --error ER_WRONG_USAGE eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 LIMIT 1 ORDER BY 1 UNION SELECT 1 FROM t1; @@ -983,7 +983,7 @@ let $q=SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 ORDER BY 1; eval $q; --error ER_WRONG_USAGE eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 LIMIT 1; @@ -991,7 +991,7 @@ let $q=SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 LIMIT 1; eval $q; --error ER_WRONG_USAGE eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 ORDER BY 1; @@ -999,7 +999,7 @@ let $q=SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 ORDER BY 1; eval $q; --error ER_WRONG_USAGE eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; let $q=SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 LIMIT 1; @@ -1007,7 +1007,7 @@ let $q=SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 LIMIT 1; eval $q; --error ER_WRONG_USAGE eval SELECT ($q); ---error ER_WRONG_USAGE +--error ER_PARSE_ERROR eval SELECT 1 FROM ($q) a; DROP TABLE t1; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 904354c54fe..89f1430a1c1 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1882,6 +1882,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); table_primary_ident table_primary_derived select_derived derived_table_list select_derived_union + derived_query_specification %type <date_time_type> date_time_type; %type <interval> interval @@ -11113,34 +11114,39 @@ table_primary_derived: subqueries have their own union rules. */ select_derived_union: - select_derived opt_union_order_or_limit + select_derived + | select_derived union_order_or_limit { - if ($1 && $2) + if ($1) { my_parse_error(thd, ER_SYNTAX_ERROR); MYSQL_YYABORT; } } - | derived_query_specification - opt_order_clause - opt_limit_clause - opt_select_lock_type - { $$= NULL; } - | select_derived_union union_head_non_top query_term + | select_derived union_head_non_top { - /* - Remove from the name resolution context stack the context of the - last select in the union. - */ - Lex->pop_context(); - - if ($1 != NULL) + if ($1) { my_parse_error(thd, ER_SYNTAX_ERROR); MYSQL_YYABORT; } } - ; + union_list_derived_part2 + | derived_query_specification opt_select_lock_type + | derived_query_specification order_or_limit opt_select_lock_type + | derived_query_specification opt_select_lock_type union_list_derived + ; + +union_list_derived_part2: + query_term_union_not_ready { Lex->pop_context(); } + | query_term_union_ready { Lex->pop_context(); } + | query_term_union_ready { Lex->pop_context(); } union_list_derived + ; + +union_list_derived: + union_head_non_top union_list_derived_part2 + ; + /* The equivalent of select_init2 for nested queries. */ select_init2_derived: @@ -11206,6 +11212,7 @@ derived_query_specification: MYSQL_YYABORT; } } + $$= NULL; } ; @@ -16398,12 +16405,18 @@ query_specification: ; query_term: - query_specification - opt_order_clause - opt_limit_clause - opt_select_lock_type + query_term_union_ready + | query_term_union_not_ready + ; + +query_term_union_not_ready: + query_specification order_or_limit opt_select_lock_type + | '(' select_paren_derived ')' union_order_or_limit + ; + +query_term_union_ready: + query_specification opt_select_lock_type | '(' select_paren_derived ')' - opt_union_order_or_limit ; query_expression_body: |