Skip to content

Commit

Permalink
MDEV-8909 union parser cleanup
Browse files Browse the repository at this point in the history
This is the final patch removing some old remainders that are
not needed anymore.

(Other clean-ups were done in earlier commits)
  • Loading branch information
Alexander Barkov committed Sep 7, 2016
1 parent 5e20c61 commit dd283db
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 77 deletions.
8 changes: 0 additions & 8 deletions sql/sql_lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,6 @@ bool st_select_lex::mark_as_dependent(THD *thd, st_select_lex *last,
return FALSE;
}

bool st_select_lex_node::set_braces(bool value) { return 1; }
bool st_select_lex_node::inc_in_sum_expr() { return 1; }
uint st_select_lex_node::get_in_sum_expr() { return 0; }
TABLE_LIST* st_select_lex_node::get_table_list() { return 0; }
Expand Down Expand Up @@ -2607,13 +2606,6 @@ st_select_lex* st_select_lex::outer_select()
}


bool st_select_lex::set_braces(bool value)
{
braces= value;
return 0;
}


bool st_select_lex::inc_in_sum_expr()
{
in_sum_expr++;
Expand Down
6 changes: 4 additions & 2 deletions sql/sql_lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ class st_select_lex_node {
virtual st_select_lex* outer_select()= 0;
virtual st_select_lex* return_after_parsing()= 0;

virtual bool set_braces(bool value);
virtual bool inc_in_sum_expr();
virtual uint get_in_sum_expr();
virtual TABLE_LIST* get_table_list();
Expand Down Expand Up @@ -955,7 +954,10 @@ class st_select_lex: public st_select_lex_node

bool mark_as_dependent(THD *thd, st_select_lex *last, Item *dependency);

bool set_braces(bool value);
void set_braces(bool value)
{
braces= value;
}
bool inc_in_sum_expr();
uint get_in_sum_expr();

Expand Down
26 changes: 10 additions & 16 deletions sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7468,22 +7468,16 @@ mysql_new_select(LEX *lex, bool move_down)
my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
DBUG_RETURN(TRUE);
}
if (lex->proc_list.elements!=0)
{
my_error(ER_WRONG_USAGE, MYF(0), "UNION",
"SELECT ... PROCEDURE ANALYSE()");
DBUG_RETURN(TRUE);
}
if (lex->current_select->order_list.first && !lex->current_select->braces)
{
my_error(ER_WRONG_USAGE, MYF(0), "UNION", "ORDER BY");
DBUG_RETURN(1);
}
if (lex->current_select->explicit_limit && !lex->current_select->braces)
{
my_error(ER_WRONG_USAGE, MYF(0), "UNION", "LIMIT");
DBUG_RETURN(1);
}

// SELECT 1 FROM t1 PROCEDURE ANALYSE() UNION ... -- not possible
DBUG_ASSERT(lex->proc_list.elements == 0);
// SELECT 1 FROM t1 ORDER BY 1 UNION SELECT 1 FROM t1 -- not possible
DBUG_ASSERT(!lex->current_select->order_list.first ||
lex->current_select->braces);
// SELECT 1 FROM t1 LIMIT 1 UNION SELECT 1 FROM t1; -- not possible
DBUG_ASSERT(!lex->current_select->explicit_limit ||
lex->current_select->braces);

select_lex->include_neighbour(lex->current_select);
SELECT_LEX_UNIT *unit= select_lex->master_unit();
if (!unit->fake_select_lex && unit->add_fake_select_lex(lex->thd))
Expand Down
57 changes: 6 additions & 51 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -714,34 +714,6 @@ bool add_select_to_union_list(LEX *lex, bool is_union_distinct,
return FALSE;
}

/**
@brief Initializes a SELECT_LEX for a query within parentheses (aka
braces).

@return false if successful, true if an error was reported. In the latter
case parsing should stop.
*/
bool setup_select_in_parentheses(LEX *lex)
{
SELECT_LEX * sel= lex->current_select;
/*
if (sel->set_braces(1))
{
my_parse_error(lex->thd, ER_SYNTAX_ERROR);
return TRUE;
}
*/
DBUG_ASSERT(sel->braces);
if (sel->linkage == UNION_TYPE &&
!sel->master_unit()->first_select()->braces &&
sel->master_unit()->first_select()->linkage ==
UNION_TYPE)
{
my_parse_error(lex->thd, ER_SYNTAX_ERROR);
return TRUE;
}
return FALSE;
}

static bool add_create_index_prepare(LEX *lex, Table_ident *table)
{
Expand Down Expand Up @@ -8398,8 +8370,7 @@ select_paren:
SELECT_SYM select_options_and_item_list select_part3
opt_select_lock_type
{
if (setup_select_in_parentheses(Lex))
MYSQL_YYABORT;
DBUG_ASSERT(Lex->current_select->braces);
}
| '(' select_paren ')'
;
Expand All @@ -8415,8 +8386,7 @@ select_paren_union_query_term:
SELECT_SYM select_options_and_item_list select_part3_union_query_term
opt_select_lock_type
{
if (setup_select_in_parentheses(Lex))
MYSQL_YYABORT;
DBUG_ASSERT(Lex->current_select->braces);
}
| '(' select_paren_union_query_term ')'
;
Expand All @@ -8432,8 +8402,7 @@ select_paren_view:
SELECT_SYM select_options_and_item_list select_part3_view
opt_select_lock_type
{
if (setup_select_in_parentheses(Lex))
MYSQL_YYABORT;
DBUG_ASSERT(Lex->current_select->braces);
}
| '(' select_paren_view ')'
;
Expand All @@ -8449,8 +8418,7 @@ select_paren_derived:
opt_limit_clause
opt_select_lock_type
{
if (setup_select_in_parentheses(Lex))
MYSQL_YYABORT;
DBUG_ASSERT(Lex->current_select->braces);
$$= Lex->current_select->master_unit()->first_select();
}
| '(' select_paren_derived ')' { $$= $2; }
Expand Down Expand Up @@ -11076,12 +11044,7 @@ union_list_derived:
select_init2_derived:
select_part2_derived
{
LEX *lex= Lex;
if (lex->current_select->set_braces(0))
{
my_parse_error(thd, ER_SYNTAX_ERROR);
MYSQL_YYABORT;
}
Select->set_braces(0);
}
;

Expand Down Expand Up @@ -11126,16 +11089,8 @@ select_derived:
derived_query_specification:
SELECT_SYM select_derived_init select_derived2
{
LEX *lex= Lex;
SELECT_LEX *sel= lex->current_select;
if ($2)
{
if (sel->set_braces(1))
{
my_parse_error(thd, ER_SYNTAX_ERROR);
MYSQL_YYABORT;
}
}
Select->set_braces(1);
$$= NULL;
}
;
Expand Down

0 comments on commit dd283db

Please sign in to comment.