[Commits] 561c366a9e4: cleanup
revision-id: 561c366a9e440797cc7eb0c1c5fad5d10c498a73 (mariadb-10.3.6-8-g561c366a9e4) parent(s): 24c07973c89244765dc964684c91ce30fc32ac2d author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2018-05-24 12:35:45 +0200 message: cleanup --- sql/sql_lex.cc | 116 -------------------------------------------------------- sql/sql_lex.h | 4 -- sql/sql_yacc.yy | 89 ------------------------------------------- 3 files changed, 209 deletions(-) diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 55e76c7effd..539161f4eaf 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -5396,122 +5396,6 @@ SELECT_LEX *LEX::link_selects_chain_down(SELECT_LEX *sel) DBUG_RETURN(NULL); } -/** - Put given (new) SELECT_LEX level below after currect (last) SELECT - - LAST SELECT -> DUMMY SELECT - | - V - NEW UNIT - | - V - NEW SELECT - - SELECT (*LAST*) ... FROM (SELECT (*NEW*) ... ) - - @param nselect Select to put one level below - - @retval TRUE Error - @retval FALSE OK -*/ - -bool LEX::add_unit_in_brackets(SELECT_LEX *nselect) -{ - DBUG_ENTER("LEX::add_unit_in_brackets"); - SELECT_LEX_UNIT *unit= nselect->master_unit(); - int old_nest_level= nselect->nest_level; - bool distinct= unit->union_distinct == nselect; - if (add_select_to_union_list(distinct, nselect->linkage, 0)) - DBUG_RETURN(TRUE); - - SELECT_LEX *dummy= current_select; - dummy->next= NULL; - if (make_select_in_brackets(current_select, nselect, FALSE)) - DBUG_RETURN(TRUE); - - if (!distinct && nselect->master_unit()->union_distinct) - { - // move distinct pointer - if (unit->union_distinct->master_unit() != unit) - { - unit->union_distinct->master_unit()->union_distinct= unit->union_distinct; - unit->union_distinct= NULL; - } - } - else if (distinct) - unit->union_distinct= NULL;// distinct was moved by add_select_to_union_list - - dummy->set_nest_level(old_nest_level); - DBUG_RETURN(FALSE); -} - - -bool LEX::make_select_in_brackets(SELECT_LEX* dummy_select, - SELECT_LEX *nselect, bool automatic) -{ - DBUG_ENTER("LEX::make_select_in_brackets"); - - int old_nest_level= nselect->nest_level; - dummy_select->automatic_brackets= automatic; - dummy_select->set_linkage(nselect->linkage); - current_select= dummy_select; // for mysql_new_select & Items - - /* stuff dummy SELECT * FROM (...) */ - Name_resolution_context *context= &dummy_select->context; - context->init(); - - /* add SELECT list*/ - Item *item= new (thd->mem_root) - Item_field(thd, context, NULL, NULL, &star_clex_str); - if (item == NULL) - DBUG_RETURN(TRUE); - if (add_item_to_list(thd, item)) - DBUG_RETURN(TRUE); - (dummy_select->with_wild)++; - - nselect->set_linkage(DERIVED_TABLE_TYPE); - SELECT_LEX *sl= nselect; - bool down= TRUE; - do{ - SELECT_LEX *next= sl->next_select(); - if (mysql_new_select(this, down, sl)) - DBUG_RETURN(TRUE); - down= FALSE; - DBUG_ASSERT(sl->outer_select() == dummy_select); - sl= next; - } while (sl); - - current_select= dummy_select; - - SELECT_LEX_UNIT *unit= nselect->master_unit(); - Table_ident *ti= new (thd->mem_root) Table_ident(unit); - if (ti == NULL) - DBUG_RETURN(TRUE); - char buff[10]; - LEX_CSTRING alias; - alias.length= my_snprintf(buff, sizeof(buff), - "__%u", dummy_select->select_number); - alias.str= thd->strmake(buff, alias.length); - if (!alias.str) - DBUG_RETURN(TRUE); - - TABLE_LIST *table_list; - if (!(table_list= dummy_select->add_table_to_list(thd, ti, &alias, - 0, TL_READ, - MDL_SHARED_READ))) - DBUG_RETURN(TRUE); - context->resolve_in_table_list_only(table_list); - dummy_select->add_joined_table(table_list); - - derived_tables|= DERIVED_SUBQUERY; - - if (dummy_select->set_nest_level(old_nest_level)) - DBUG_RETURN(TRUE); - - current_select= nselect; - DBUG_RETURN(FALSE); -} - bool LEX::push_context(Name_resolution_context *context) { DBUG_ENTER("LEX::push_context"); diff --git a/sql/sql_lex.h b/sql/sql_lex.h index f715fddc5f0..053444190a9 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -3402,9 +3402,6 @@ struct LEX: public Query_tables_list int case_stmt_action_expr(Item* expr); int case_stmt_action_when(Item *when, bool simple); int case_stmt_action_then(); - bool add_select_to_union_list(bool is_union_distinct, - enum sub_select_type type, - bool is_top_level); bool setup_select_in_parentheses(); bool set_trigger_new_row(const LEX_CSTRING *name, Item *val); bool set_trigger_field(const LEX_CSTRING *name1, const LEX_CSTRING *name2, @@ -3958,7 +3955,6 @@ struct LEX: public Query_tables_list SELECT_LEX *exclude_last_select(); SELECT_LEX *exclude_not_first_select(SELECT_LEX *exclude); - bool add_unit_in_brackets(SELECT_LEX *nselect); void check_automatic_up(enum sub_select_type type); bool create_or_alter_view_finalize(THD *thd, Table_ident *table_ident); bool add_alter_view(THD *thd, uint16 algorithm, enum_view_suid suid, diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index d856570c3de..5f4e615280b 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -487,95 +487,6 @@ Item* handle_sql2003_note184_exception(THD *thd, Item* left, bool equal, DBUG_RETURN(result); } -/** - @brief Creates a new SELECT_LEX for a UNION branch. - - Sets up and initializes a SELECT_LEX structure for a query once the parser - discovers a UNION token. The current SELECT_LEX is pushed on the stack and - the new SELECT_LEX becomes the current one. - - @param lex The parser state. - - @param is_union_distinct True if the union preceding the new select - statement uses UNION DISTINCT. - - @param is_top_level This should be @c TRUE if the newly created SELECT_LEX - is a non-nested statement. - - @return <code>false</code> if successful, <code>true</code> if an error was - reported. In the latter case parsing should stop. - */ -bool LEX::add_select_to_union_list(bool is_union_distinct, - enum sub_select_type type, - bool is_top_level) -{ - const char *type_name= (type == INTERSECT_TYPE ? "INTERSECT" : - (type == EXCEPT_TYPE ? "EXCEPT" : "UNION")); - DBUG_ENTER("LEX::add_select_to_union_list"); - /* - Only the last SELECT can have INTO. Since the grammar won't allow INTO in - a nested SELECT, we make this check only when creating a top-level SELECT. - */ - if (is_top_level && result) - { - my_error(ER_WRONG_USAGE, MYF(0), type_name, "INTO"); - DBUG_RETURN(TRUE); - } - if (current_select->order_list.first && !current_select->braces) - { - my_error(ER_WRONG_USAGE, MYF(0), type_name, "ORDER BY"); - DBUG_RETURN(TRUE); - } - - if (current_select->explicit_limit && !current_select->braces) - { - my_error(ER_WRONG_USAGE, MYF(0), type_name, "LIMIT"); - DBUG_RETURN(TRUE); - } - if (current_select->linkage == GLOBAL_OPTIONS_TYPE) - { - thd->parse_error(); - DBUG_RETURN(TRUE); - } - if (!is_union_distinct && (type == INTERSECT_TYPE || type == EXCEPT_TYPE)) - { - my_error(ER_WRONG_USAGE, MYF(0), type_name, "ALL"); - DBUG_RETURN(TRUE); - } - /* - Priority implementation, but also trying to keep things as flat - as possible */ - if (type == INTERSECT_TYPE && - (current_select->linkage != INTERSECT_TYPE && - current_select != current_select->master_unit()->first_select())) - { - /* - This and previous SELECTs should go one level down because of - priority - */ - SELECT_LEX *prev= exclude_last_select(); - if (add_unit_in_brackets(prev)) - DBUG_RETURN(TRUE); - bool res= add_select_to_union_list(is_union_distinct, type, 0); - DBUG_RETURN(res); - } - else - { - check_automatic_up(type); - } - if (mysql_new_select(this, 0, NULL)) - DBUG_RETURN(TRUE); - mysql_init_select(this); - current_select->set_linkage(type); - if (is_union_distinct) /* UNION DISTINCT - remember position */ - { - current_select->master_unit()->union_distinct= - current_select; - } - DBUG_RETURN(FALSE); -} - - /** Create a separate LEX for each assignment if in SP.
participants (1)
-
Oleksandr Byelkin