Skip to content

Commit

Permalink
MDEV-10051 Fix subselect to return a syntax error instead of "Incorre…
Browse files Browse the repository at this point in the history
…ct usage of UNION and LIMIT"
  • Loading branch information
Alexander Barkov committed May 23, 2016
1 parent a999acf commit 4c0e296
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 41 deletions.
14 changes: 7 additions & 7 deletions mysql-test/r/parser.result
Original file line number Diff line number Diff line change
Expand Up @@ -820,19 +820,19 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT 1 FROM t1 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 'UNION SELECT 1 FROM t1' at line 1
SELECT (SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1);
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)' at line 1
SELECT 1 FROM (SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1) a;
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
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 1 FROM (SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1) a;
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
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 1 FROM (SELECT 1 FROM t1 ORDER BY 1 LIMIT 1 UNION SELECT 1 FROM t1) a;
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;
Expand All @@ -844,25 +844,25 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
SELECT 1 FROM t1 ORDER BY 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 ORDER BY 1 UNION SELECT 1 FROM t1 ORDER BY 1);
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)' at line 1
SELECT 1 FROM (SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 ORDER BY 1) a;
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
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 1 FROM (SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 LIMIT 1) a;
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
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 1 FROM (SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1 ORDER BY 1) a;
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
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 1 FROM (SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 LIMIT 1) a;
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;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/r/subselect.result
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ create table t1 (a float);
select 10.5 IN (SELECT * from t1 LIMIT 1);
ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
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.5)' at line 1
select 10.5 IN (SELECT * from t1 UNION SELECT 1.5 LIMIT 1);
ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
drop table t1;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/r/subselect_no_exists_to_in.result
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ create table t1 (a float);
select 10.5 IN (SELECT * from t1 LIMIT 1);
ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
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.5)' at line 1
select 10.5 IN (SELECT * from t1 UNION SELECT 1.5 LIMIT 1);
ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
drop table t1;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/r/subselect_no_mat.result
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ create table t1 (a float);
select 10.5 IN (SELECT * from t1 LIMIT 1);
ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
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.5)' at line 1
select 10.5 IN (SELECT * from t1 UNION SELECT 1.5 LIMIT 1);
ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
drop table t1;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/r/subselect_no_opts.result
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ create table t1 (a float);
select 10.5 IN (SELECT * from t1 LIMIT 1);
ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
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.5)' at line 1
select 10.5 IN (SELECT * from t1 UNION SELECT 1.5 LIMIT 1);
ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
drop table t1;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/r/subselect_no_scache.result
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ create table t1 (a float);
select 10.5 IN (SELECT * from t1 LIMIT 1);
ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
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.5)' at line 1
select 10.5 IN (SELECT * from t1 UNION SELECT 1.5 LIMIT 1);
ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
drop table t1;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/r/subselect_no_semijoin.result
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ create table t1 (a float);
select 10.5 IN (SELECT * from t1 LIMIT 1);
ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
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.5)' at line 1
select 10.5 IN (SELECT * from t1 UNION SELECT 1.5 LIMIT 1);
ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
drop table t1;
Expand Down
14 changes: 7 additions & 7 deletions mysql-test/t/parser.test
Original file line number Diff line number Diff line change
Expand Up @@ -949,23 +949,23 @@ eval SELECT 1 FROM ($q) a;
let $q=SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1;
--error ER_PARSE_ERROR
eval $q;
--error ER_WRONG_USAGE
--error ER_PARSE_ERROR
eval SELECT ($q);
--error ER_PARSE_ERROR
eval SELECT 1 FROM ($q) a;

let $q=SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1;
--error ER_PARSE_ERROR
eval $q;
--error ER_WRONG_USAGE
--error ER_PARSE_ERROR
eval SELECT ($q);
--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;
--error ER_PARSE_ERROR
eval $q;
--error ER_WRONG_USAGE
--error ER_PARSE_ERROR
eval SELECT ($q);
--error ER_PARSE_ERROR
eval SELECT 1 FROM ($q) a;
Expand All @@ -981,31 +981,31 @@ eval SELECT 1 FROM ($q) a;
let $q=SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 ORDER BY 1;
--error ER_PARSE_ERROR
eval $q;
--error ER_WRONG_USAGE
--error ER_PARSE_ERROR
eval SELECT ($q);
--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;
--error ER_PARSE_ERROR
eval $q;
--error ER_WRONG_USAGE
--error ER_PARSE_ERROR
eval SELECT ($q);
--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;
--error ER_PARSE_ERROR
eval $q;
--error ER_WRONG_USAGE
--error ER_PARSE_ERROR
eval SELECT ($q);
--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;
--error ER_PARSE_ERROR
eval $q;
--error ER_WRONG_USAGE
--error ER_PARSE_ERROR
eval SELECT ($q);
--error ER_PARSE_ERROR
eval SELECT 1 FROM ($q) a;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/t/subselect.test
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ drop table t1, t2;
create table t1 (a float);
-- error ER_NOT_SUPPORTED_YET
select 10.5 IN (SELECT * from t1 LIMIT 1);
-- error ER_WRONG_USAGE
-- error ER_PARSE_ERROR
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
-- error ER_NOT_SUPPORTED_YET
select 10.5 IN (SELECT * from t1 UNION SELECT 1.5 LIMIT 1);
Expand Down
36 changes: 16 additions & 20 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
select_derived derived_table_list
select_derived_union
derived_query_specification

%type <date_time_type> date_time_type;
%type <interval> interval

Expand Down Expand Up @@ -1922,7 +1921,11 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);

%type <select_lex> subselect
get_select_lex get_select_lex_derived
query_specification
query_term_union_not_ready
query_term_union_ready
query_expression_body
select_paren_derived

%type <boolfunc2creator> comp_op

Expand Down Expand Up @@ -8555,8 +8558,9 @@ select_paren_derived:
{
if (setup_select_in_parentheses(Lex))
MYSQL_YYABORT;
$$= Lex->current_select->master_unit()->first_select();
}
| '(' select_paren_derived ')'
| '(' select_paren_derived ')' { $$= $2; }
;

select_init3:
Expand Down Expand Up @@ -16402,33 +16406,25 @@ union_option:
*/
query_specification:
SELECT_SYM select_init2_derived opt_table_expression
;

query_term:
query_term_union_ready
| query_term_union_not_ready
{
$$= Lex->current_select->master_unit()->first_select();
}
;

query_term_union_not_ready:
query_specification order_or_limit opt_select_lock_type
| '(' select_paren_derived ')' union_order_or_limit
query_specification order_or_limit opt_select_lock_type { $$= $1; }
| '(' select_paren_derived ')' union_order_or_limit { $$= $2; }
;

query_term_union_ready:
query_specification opt_select_lock_type
| '(' select_paren_derived ')'
query_specification opt_select_lock_type { $$= $1; }
| '(' select_paren_derived ')' { $$= $2; }
;

query_expression_body:
query_term
{
$$= Lex->current_select->master_unit()->first_select();
}
| query_expression_body union_head_non_top query_term
{
Lex->pop_context();
$$= $1;
}
query_term_union_not_ready { $$= $1; }
| query_term_union_ready { $$= $1; }
| query_term_union_ready union_list_derived { $$= $1; }
;

/* Corresponds to <query expression> in the SQL:2003 standard. */
Expand Down

0 comments on commit 4c0e296

Please sign in to comment.