diff options
author | Alexander Barkov <bar@mariadb.com> | 2019-09-20 10:36:20 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2019-09-20 10:36:20 +0400 |
commit | 2f88bd2da26abd30b027308aedc30989c039d518 (patch) | |
tree | 46154ab8b7b906727cf9c0832aa05b5017eb02fd /sql | |
parent | b9dea911bf8e3d4d8fc57ce3ef15ab0e2ab4d076 (diff) | |
download | mariadb-git-2f88bd2da26abd30b027308aedc30989c039d518.tar.gz |
MDEV-20634 Report disallowed subquery errors as such (instead of parse error)
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_lex.cc | 15 | ||||
-rw-r--r-- | sql/sql_lex.h | 12 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 57 | ||||
-rw-r--r-- | sql/sql_yacc_ora.yy | 57 |
4 files changed, 69 insertions, 72 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 91e55127cd1..7952b2a267e 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -733,7 +733,7 @@ void LEX::start(THD *thd_arg) default_used= FALSE; query_tables= 0; reset_query_tables_list(FALSE); - expr_allows_subselect= TRUE; + clause_that_disallows_subselect= NULL; selects_allow_into= FALSE; selects_allow_procedure= FALSE; use_only_table_context= FALSE; @@ -9049,12 +9049,12 @@ bool LEX::insert_select_hack(SELECT_LEX *sel) Create an Item_singlerow_subselect for a query expression. */ Item *LEX::create_item_query_expression(THD *thd, - const char *tok_start, st_select_lex_unit *unit) { - if (!expr_allows_subselect) + if (clause_that_disallows_subselect) { - thd->parse_error(ER_SYNTAX_ERROR, tok_start); + my_error(ER_SUBQUERIES_NOT_SUPPORTED, MYF(0), + clause_that_disallows_subselect); return NULL; } @@ -9323,11 +9323,12 @@ SELECT_LEX_UNIT *LEX::parsed_body_unit_tail(SELECT_LEX_UNIT *unit, Process subselect parsing */ -SELECT_LEX *LEX::parsed_subselect(SELECT_LEX_UNIT *unit, char *place) +SELECT_LEX *LEX::parsed_subselect(SELECT_LEX_UNIT *unit) { - if (!expr_allows_subselect) + if (clause_that_disallows_subselect) { - thd->parse_error(ER_SYNTAX_ERROR, place); + my_error(ER_SUBQUERIES_NOT_SUPPORTED, MYF(0), + clause_that_disallows_subselect); return NULL; } diff --git a/sql/sql_lex.h b/sql/sql_lex.h index d351378a9a6..8296f9e2dec 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -3267,10 +3267,10 @@ public: /* Usually `expr` rule of yacc is quite reused but some commands better not support subqueries which comes standard with this rule, like - KILL, HA_READ, CREATE/ALTER EVENT etc. Set this to `false` to get - syntax error back. + KILL, HA_READ, CREATE/ALTER EVENT etc. Set this to a non-NULL + clause name to get an error. */ - bool expr_allows_subselect; + const char *clause_that_disallows_subselect; bool selects_allow_into; bool selects_allow_procedure; /* @@ -3988,9 +3988,7 @@ public: const Lex_ident_cli_st *var_name, const Lex_ident_cli_st *field_name); - Item *create_item_query_expression(THD *thd, - const char *tok_start, - st_select_lex_unit *unit); + Item *create_item_query_expression(THD *thd, st_select_lex_unit *unit); Item *make_item_func_replace(THD *thd, Item *org, Item *find, Item *replace); Item *make_item_func_substr(THD *thd, Item *a, Item *b, Item *c); @@ -4460,7 +4458,7 @@ public: bool parsed_body_unit(SELECT_LEX_UNIT *unit); SELECT_LEX_UNIT *parsed_body_unit_tail(SELECT_LEX_UNIT *unit, Lex_order_limit_lock * l); - SELECT_LEX *parsed_subselect(SELECT_LEX_UNIT *unit, char *place); + SELECT_LEX *parsed_subselect(SELECT_LEX_UNIT *unit); bool parsed_insert_select(SELECT_LEX *firs_select); bool parsed_TVC_start(); SELECT_LEX *parsed_TVC_end(); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 3756982b384..a9da6f9836d 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1873,7 +1873,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type <item> literal insert_ident order_ident temporal_literal - simple_ident expr expr_no_subselect sum_expr in_sum_expr + simple_ident expr sum_expr in_sum_expr variable variable_aux bool_pri predicate bit_expr parenthesized_expr table_wild simple_expr column_default_non_parenthesized_expr udf_expr @@ -2340,19 +2340,13 @@ deallocate_or_drop: ; prepare: - PREPARE_SYM ident FROM expr_no_subselect - { - if (Lex->stmt_prepare($2, $4)) - MYSQL_YYABORT; - } - ; - -expr_no_subselect: - { Lex->expr_allows_subselect= false; } + PREPARE_SYM ident FROM + { Lex->clause_that_disallows_subselect= "PREPARE..FROM"; } expr { - Lex->expr_allows_subselect= true; - $$= $2; + Lex->clause_that_disallows_subselect= NULL; + if (Lex->stmt_prepare($2, $5)) + MYSQL_YYABORT; } ; @@ -2362,20 +2356,25 @@ execute: if (Lex->stmt_execute($2, $3)) MYSQL_YYABORT; } - | EXECUTE_SYM IMMEDIATE_SYM expr_no_subselect execute_using + | EXECUTE_SYM IMMEDIATE_SYM + { Lex->clause_that_disallows_subselect= "EXECUTE IMMEDIATE"; } + expr + { Lex->clause_that_disallows_subselect= NULL; } + execute_using { - if (Lex->stmt_execute_immediate($3, $4)) + if (Lex->stmt_execute_immediate($4, $6)) MYSQL_YYABORT; } ; execute_using: /* nothing */ { $$= NULL; } - | USING { Lex->expr_allows_subselect= false; } + | USING + { Lex->clause_that_disallows_subselect= "EXECUTE..USING"; } execute_params { $$= $3; - Lex->expr_allows_subselect= true; + Lex->clause_that_disallows_subselect= NULL; } ; @@ -6776,10 +6775,9 @@ parse_vcol_expr: ; parenthesized_expr: - remember_tok_start query_expression { - if (!($$= Lex->create_item_query_expression(thd, $1, $2))) + if (!($$= Lex->create_item_query_expression(thd, $1))) MYSQL_YYABORT; } | expr @@ -9358,10 +9356,9 @@ query_expression: ; subselect: - remember_tok_start query_expression { - if (!($$= Lex->parsed_subselect($2, $1))) + if (!($$= Lex->parsed_subselect($1))) YYABORT; } ; @@ -12944,17 +12941,16 @@ procedure_clause: /* PROCEDURE CLAUSE cannot handle subquery as one of its parameter, - so set expr_allows_subselect as false to disallow any subqueries - further. Reset expr_allows_subselect back to true once the - parameters are reduced. + so disallow any subqueries further. + Alow subqueries back once the parameters are reduced. */ - Lex->expr_allows_subselect= false; + Lex->clause_that_disallows_subselect= "PROCEDURE"; Select->options|= OPTION_PROCEDURE_CLAUSE; } '(' procedure_list ')' { /* Subqueries are allowed from now.*/ - Lex->expr_allows_subselect= true; + Lex->clause_that_disallows_subselect= NULL; } ; @@ -14701,9 +14697,12 @@ purge: { Lex->stmt_purge_to($5); } - | PURGE master_or_binary LOGS_SYM BEFORE_SYM expr_no_subselect + | PURGE master_or_binary LOGS_SYM BEFORE_SYM + { Lex->clause_that_disallows_subselect= "PURGE..BEFORE"; } + expr { - if (Lex->stmt_purge_before($5)) + Lex->clause_that_disallows_subselect= NULL; + if (Lex->stmt_purge_before($6)) MYSQL_YYABORT; } ; @@ -16797,7 +16796,7 @@ handler_tail: LEX *lex=Lex; if (unlikely(lex->sphead)) my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "HANDLER")); - lex->expr_allows_subselect= FALSE; + lex->clause_that_disallows_subselect= "HANDLER..READ"; lex->sql_command = SQLCOM_HA_READ; lex->ha_rkey_mode= HA_READ_KEY_EXACT; /* Avoid purify warnings */ Item *one= new (thd->mem_root) Item_int(thd, (int32) 1); @@ -16812,7 +16811,7 @@ handler_tail: handler_read_or_scan opt_where_clause opt_global_limit_clause { LEX *lex=Lex; - lex->expr_allows_subselect= TRUE; + lex->clause_that_disallows_subselect= NULL; if (!lex->current_select->explicit_limit) { Item *one= new (thd->mem_root) Item_int(thd, (int32) 1); diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index eda8834ff6a..67bcfbaa616 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -1358,7 +1358,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize); %type <item> literal insert_ident order_ident temporal_literal - simple_ident expr expr_no_subselect sum_expr in_sum_expr + simple_ident expr sum_expr in_sum_expr variable variable_aux bool_pri predicate bit_expr parenthesized_expr table_wild simple_expr column_default_non_parenthesized_expr udf_expr @@ -1844,19 +1844,13 @@ deallocate_or_drop: ; prepare: - PREPARE_SYM ident FROM expr_no_subselect - { - if (Lex->stmt_prepare($2, $4)) - MYSQL_YYABORT; - } - ; - -expr_no_subselect: - { Lex->expr_allows_subselect= false; } + PREPARE_SYM ident FROM + { Lex->clause_that_disallows_subselect= "PREPARE..FROM"; } expr { - Lex->expr_allows_subselect= true; - $$= $2; + Lex->clause_that_disallows_subselect= NULL; + if (Lex->stmt_prepare($2, $5)) + MYSQL_YYABORT; } ; @@ -1866,20 +1860,25 @@ execute: if (Lex->stmt_execute($2, $3)) MYSQL_YYABORT; } - | EXECUTE_SYM IMMEDIATE_SYM expr_no_subselect execute_using + | EXECUTE_SYM IMMEDIATE_SYM + { Lex->clause_that_disallows_subselect= "EXECUTE IMMEDIATE"; } + expr + { Lex->clause_that_disallows_subselect= NULL; } + execute_using { - if (Lex->stmt_execute_immediate($3, $4)) + if (Lex->stmt_execute_immediate($4, $6)) MYSQL_YYABORT; } ; execute_using: /* nothing */ { $$= NULL; } - | USING { Lex->expr_allows_subselect= false; } + | USING + { Lex->clause_that_disallows_subselect= "EXECUTE..USING"; } execute_params { $$= $3; - Lex->expr_allows_subselect= true; + Lex->clause_that_disallows_subselect= NULL; } ; @@ -6785,10 +6784,9 @@ parse_vcol_expr: ; parenthesized_expr: - remember_tok_start query_expression { - if (!($$= Lex->create_item_query_expression(thd, $1, $2))) + if (!($$= Lex->create_item_query_expression(thd, $1))) MYSQL_YYABORT; } | expr @@ -9459,10 +9457,9 @@ query_expression: ; subselect: - remember_tok_start query_expression { - if (!($$= Lex->parsed_subselect($2, $1))) + if (!($$= Lex->parsed_subselect($1))) YYABORT; } ; @@ -13054,17 +13051,16 @@ procedure_clause: /* PROCEDURE CLAUSE cannot handle subquery as one of its parameter, - so set expr_allows_subselect as false to disallow any subqueries - further. Reset expr_allows_subselect back to true once the - parameters are reduced. + so disallow any subqueries further. + Alow subqueries back once the parameters are reduced. */ - Lex->expr_allows_subselect= false; + Lex->clause_that_disallows_subselect= "PROCEDURE"; Select->options|= OPTION_PROCEDURE_CLAUSE; } '(' procedure_list ')' { /* Subqueries are allowed from now.*/ - Lex->expr_allows_subselect= true; + Lex->clause_that_disallows_subselect= NULL; } ; @@ -14834,9 +14830,12 @@ purge: { Lex->stmt_purge_to($5); } - | PURGE master_or_binary LOGS_SYM BEFORE_SYM expr_no_subselect + | PURGE master_or_binary LOGS_SYM BEFORE_SYM + { Lex->clause_that_disallows_subselect= "PURGE..BEFORE"; } + expr { - if (Lex->stmt_purge_before($5)) + Lex->clause_that_disallows_subselect= NULL; + if (Lex->stmt_purge_before($6)) MYSQL_YYABORT; } ; @@ -17016,7 +17015,7 @@ handler_tail: LEX *lex=Lex; if (unlikely(lex->sphead)) my_yyabort_error((ER_SP_BADSTATEMENT, MYF(0), "HANDLER")); - lex->expr_allows_subselect= FALSE; + lex->clause_that_disallows_subselect= "HANDLER..READ"; lex->sql_command = SQLCOM_HA_READ; lex->ha_rkey_mode= HA_READ_KEY_EXACT; /* Avoid purify warnings */ Item *one= new (thd->mem_root) Item_int(thd, (int32) 1); @@ -17031,7 +17030,7 @@ handler_tail: handler_read_or_scan opt_where_clause opt_global_limit_clause { LEX *lex=Lex; - lex->expr_allows_subselect= TRUE; + lex->clause_that_disallows_subselect= NULL; if (!lex->current_select->explicit_limit) { Item *one= new (thd->mem_root) Item_int(thd, (int32) 1); |