Bug#30333 (Performance, expressions lists in the parser)

Before this patch, the parser would execute:
- Select->expr_list.push_front()
- Select->expr_list.pop()
when parsing expressions lists, in the following rules:
- udf_expr_list
- expr_list
- ident_list

This is unnecessary, and introduces overhead due to the memory allocations
performed with Select->expr_list

With this patch, this code has been removed.
The list being parsed is maintained in the parser stack instead.

Also, 'udf_expr_list' has been renamed 'opt_udf_expr_list', since this
production can be empty.
parent b1e0dcc0
......@@ -323,7 +323,6 @@ void lex_start(THD *thd)
lex->length=0;
lex->part_info= 0;
lex->select_lex.in_sum_expr=0;
lex->select_lex.expr_list.empty();
lex->select_lex.ftfunc_list_alloc.empty();
lex->select_lex.ftfunc_list= &lex->select_lex.ftfunc_list_alloc;
lex->select_lex.group_list.empty();
......@@ -1555,7 +1554,6 @@ void st_select_lex::init_select()
options= 0;
sql_cache= SQL_CACHE_UNSPECIFIED;
braces= 0;
expr_list.empty();
interval_list.empty();
ftfunc_list_alloc.empty();
inner_sum_func_list= 0;
......
......@@ -596,7 +596,6 @@ class st_select_lex: public st_select_lex_node
const char *type; /* type of select for EXPLAIN */
SQL_LIST order_list; /* ORDER clause */
List<List_item> expr_list;
SQL_LIST *gorder_list;
Item *select_limit, *offset_limit; /* LIMIT clause parameters */
// Arrays of pointers to top elements of all_fields list
......
......@@ -1171,7 +1171,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
NUM_literal
%type <item_list>
expr_list udf_expr_list udf_expr_list2 when_list
expr_list opt_udf_expr_list udf_expr_list when_list
ident_list ident_list_arg opt_expr_list
%type <var_type>
......@@ -1245,7 +1245,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
select_item_list select_item values_list no_braces
opt_limit_clause delete_limit_clause fields opt_values values
procedure_list procedure_list2 procedure_item
expr_list2 udf_expr_list3 handler
handler
opt_precision opt_ignore opt_column opt_restrict
grant revoke set lock unlock string_list field_options field_option
field_opt_list opt_binary table_lock_list table_lock
......@@ -7253,7 +7253,7 @@ function_call_generic:
$<udf>$= udf;
#endif
}
udf_expr_list ')'
opt_udf_expr_list ')'
{
THD *thd= YYTHD;
Create_func *builder;
......@@ -7350,25 +7350,21 @@ opt_query_expansion:
| WITH QUERY_SYM EXPANSION_SYM { $$= FT_EXPAND; }
;
udf_expr_list:
opt_udf_expr_list:
/* empty */ { $$= NULL; }
| udf_expr_list2 { $$= $1;}
;
udf_expr_list2:
{ Select->expr_list.push_front(new List<Item>); }
udf_expr_list3
{ $$= Select->expr_list.pop(); }
| udf_expr_list { $$= $1; }
;
udf_expr_list3:
udf_expr_list:
udf_expr
{
Select->expr_list.head()->push_back($1);
$$= new (YYTHD->mem_root) List<Item>;
$$->push_back($1);
}
| udf_expr_list3 ',' udf_expr
| udf_expr_list ',' udf_expr
{
Select->expr_list.head()->push_back($3);
$1->push_back($3);
$$= $1;
}
;
......@@ -7568,13 +7564,17 @@ opt_expr_list:
;
expr_list:
{ Select->expr_list.push_front(new List<Item>); }
expr_list2
{ $$= Select->expr_list.pop(); };
expr_list2:
expr { Select->expr_list.head()->push_back($1); }
| expr_list2 ',' expr { Select->expr_list.head()->push_back($3); };
expr
{
$$= new (YYTHD->mem_root) List<Item>;
$$->push_back($1);
}
| expr_list ',' expr
{
$1->push_back($3);
$$= $1;
}
;
ident_list_arg:
ident_list { $$= $1; }
......@@ -7582,13 +7582,17 @@ ident_list_arg:
;
ident_list:
{ Select->expr_list.push_front(new List<Item>); }
ident_list2
{ $$= Select->expr_list.pop(); };
ident_list2:
simple_ident { Select->expr_list.head()->push_back($1); }
| ident_list2 ',' simple_ident { Select->expr_list.head()->push_back($3); };
simple_ident
{
$$= new (YYTHD->mem_root) List<Item>;
$$->push_back($1);
}
| ident_list ',' simple_ident
{
$1->push_back($3);
$$= $1;
}
;
opt_expr:
/* empty */ { $$= NULL; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment