cleanup: don't pass wild_num to setup_wild()

because internally setup_wild() adjusts select_lex->with_wild directly
anyway, so there is no reason to pretend that the number of '*' may be
anything else but select_lex->with_wild

And don't update select_lex->item_list, because fields can come
from anywhere and don't necessarily have to be copied into select_lex.
This commit is contained in:
Sergei Golubchik 2019-09-22 23:23:28 +02:00
parent c7320830a6
commit a4a025f5d1
10 changed files with 39 additions and 82 deletions

View File

@ -3720,7 +3720,6 @@ int subselect_single_select_engine::prepare(THD *thd)
SELECT_LEX *save_select= thd->lex->current_select; SELECT_LEX *save_select= thd->lex->current_select;
thd->lex->current_select= select_lex; thd->lex->current_select= select_lex;
if (join->prepare(select_lex->table_list.first, if (join->prepare(select_lex->table_list.first,
select_lex->with_wild,
select_lex->where, select_lex->where,
select_lex->order_list.elements + select_lex->order_list.elements +
select_lex->group_list.elements, select_lex->group_list.elements,

View File

@ -7459,17 +7459,16 @@ static bool setup_natural_join_row_types(THD *thd,
****************************************************************************/ ****************************************************************************/
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields, int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
List<Item> *sum_func_list, List<Item> *sum_func_list, SELECT_LEX *select_lex)
uint wild_num, uint *hidden_bit_fields)
{ {
if (!wild_num)
return(0);
Item *item; Item *item;
List_iterator<Item> it(fields); List_iterator<Item> it(fields);
Query_arena *arena, backup; Query_arena *arena, backup;
DBUG_ENTER("setup_wild"); DBUG_ENTER("setup_wild");
if (!select_lex->with_wild)
DBUG_RETURN(0);
/* /*
Don't use arena if we are not in prepared statements or stored procedures Don't use arena if we are not in prepared statements or stored procedures
For PS/SP we have to use arena to remember the changes For PS/SP we have to use arena to remember the changes
@ -7477,7 +7476,7 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
arena= thd->activate_stmt_arena_if_needed(&backup); arena= thd->activate_stmt_arena_if_needed(&backup);
thd->lex->current_select->cur_pos_in_select_list= 0; thd->lex->current_select->cur_pos_in_select_list= 0;
while (wild_num && (item= it++)) while (select_lex->with_wild && (item= it++))
{ {
if (item->type() == Item::FIELD_ITEM && if (item->type() == Item::FIELD_ITEM &&
((Item_field*) item)->field_name.str == star_clex_str.str && ((Item_field*) item)->field_name.str == star_clex_str.str &&
@ -7500,7 +7499,7 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
else if (insert_fields(thd, ((Item_field*) item)->context, else if (insert_fields(thd, ((Item_field*) item)->context,
((Item_field*) item)->db_name.str, ((Item_field*) item)->db_name.str,
((Item_field*) item)->table_name.str, &it, ((Item_field*) item)->table_name.str, &it,
any_privileges, hidden_bit_fields)) any_privileges, &select_lex->hidden_bit_fields))
{ {
if (arena) if (arena)
thd->restore_active_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
@ -7515,30 +7514,15 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
*/ */
sum_func_list->elements+= fields.elements - elem; sum_func_list->elements+= fields.elements - elem;
} }
wild_num--; select_lex->with_wild--;
} }
else else
thd->lex->current_select->cur_pos_in_select_list++; thd->lex->current_select->cur_pos_in_select_list++;
} }
DBUG_ASSERT(!select_lex->with_wild);
thd->lex->current_select->cur_pos_in_select_list= UNDEF_POS; thd->lex->current_select->cur_pos_in_select_list= UNDEF_POS;
if (arena) if (arena)
{
/* make * substituting permanent */
SELECT_LEX *select_lex= thd->lex->current_select;
select_lex->with_wild= 0;
#ifdef HAVE_valgrind
if (&select_lex->item_list != &fields) // Avoid warning
#endif
/*
The assignment below is translated to memcpy() call (at least on some
platforms). memcpy() expects that source and destination areas do not
overlap. That problem was detected by valgrind.
*/
if (&select_lex->item_list != &fields)
select_lex->item_list= fields;
thd->restore_active_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
}
DBUG_RETURN(0); DBUG_RETURN(0);
} }

View File

@ -175,7 +175,7 @@ bool insert_fields(THD *thd, Name_resolution_context *context,
void make_leaves_list(THD *thd, List<TABLE_LIST> &list, TABLE_LIST *tables, void make_leaves_list(THD *thd, List<TABLE_LIST> &list, TABLE_LIST *tables,
bool full_table_list, TABLE_LIST *boundary); bool full_table_list, TABLE_LIST *boundary);
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields, int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
List<Item> *sum_func_list, uint wild_num, uint * hidden_bit_fields); List<Item> *sum_func_list, SELECT_LEX *sl);
bool setup_fields(THD *thd, Ref_ptr_array ref_pointer_array, bool setup_fields(THD *thd, Ref_ptr_array ref_pointer_array,
List<Item> &item, enum_column_usage column_usage, List<Item> &item, enum_column_usage column_usage,
List<Item> *sum_func_list, List<Item> *pre_fix, List<Item> *sum_func_list, List<Item> *pre_fix,

View File

@ -1061,8 +1061,7 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list,
DBUG_RETURN(true); DBUG_RETURN(true);
} }
if ((wild_num && setup_wild(thd, table_list, field_list, NULL, wild_num, if ((wild_num && setup_wild(thd, table_list, field_list, NULL, select_lex)) ||
&select_lex->hidden_bit_fields)) ||
setup_fields(thd, Ref_ptr_array(), setup_fields(thd, Ref_ptr_array(),
field_list, MARK_COLUMNS_READ, NULL, NULL, 0) || field_list, MARK_COLUMNS_READ, NULL, NULL, 0) ||
setup_conds(thd, table_list, select_lex->leaf_tables, conds) || setup_conds(thd, table_list, select_lex->leaf_tables, conds) ||

View File

@ -1224,7 +1224,6 @@ bool mysql_derived_fill(THD *thd, LEX *lex, TABLE_LIST *derived)
lex->current_select= first_select; lex->current_select= first_select;
res= mysql_select(thd, res= mysql_select(thd,
first_select->table_list.first, first_select->table_list.first,
first_select->with_wild,
first_select->item_list, first_select->where, first_select->item_list, first_select->where,
(first_select->order_list.elements+ (first_select->order_list.elements+
first_select->group_list.elements), first_select->group_list.elements),

View File

@ -4727,7 +4727,6 @@ mysql_execute_command(THD *thd)
{ {
res= mysql_select(thd, res= mysql_select(thd,
select_lex->get_table_list(), select_lex->get_table_list(),
select_lex->with_wild,
select_lex->item_list, select_lex->item_list,
select_lex->where, select_lex->where,
0, (ORDER *)NULL, (ORDER *)NULL, (Item *)NULL, 0, (ORDER *)NULL, (ORDER *)NULL, (Item *)NULL,

View File

@ -415,7 +415,7 @@ bool handle_select(THD *thd, LEX *lex, select_result *result,
*/ */
res= mysql_select(thd, res= mysql_select(thd,
select_lex->table_list.first, select_lex->table_list.first,
select_lex->with_wild, select_lex->item_list, select_lex->item_list,
select_lex->where, select_lex->where,
select_lex->order_list.elements + select_lex->order_list.elements +
select_lex->group_list.elements, select_lex->group_list.elements,
@ -1064,8 +1064,7 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
0 on success 0 on success
*/ */
int int
JOIN::prepare(TABLE_LIST *tables_init, JOIN::prepare(TABLE_LIST *tables_init, COND *conds_init, uint og_num,
uint wild_num, COND *conds_init, uint og_num,
ORDER *order_init, bool skip_order_by, ORDER *order_init, bool skip_order_by,
ORDER *group_init, Item *having_init, ORDER *group_init, Item *having_init,
ORDER *proc_param_init, SELECT_LEX *select_lex_arg, ORDER *proc_param_init, SELECT_LEX *select_lex_arg,
@ -1187,8 +1186,7 @@ JOIN::prepare(TABLE_LIST *tables_init,
real_og_num+= select_lex->order_list.elements; real_og_num+= select_lex->order_list.elements;
DBUG_ASSERT(select_lex->hidden_bit_fields == 0); DBUG_ASSERT(select_lex->hidden_bit_fields == 0);
if (setup_wild(thd, tables_list, fields_list, &all_fields, wild_num, if (setup_wild(thd, tables_list, fields_list, &all_fields, select_lex))
&select_lex->hidden_bit_fields))
DBUG_RETURN(-1); DBUG_RETURN(-1);
if (select_lex->setup_ref_array(thd, real_og_num)) if (select_lex->setup_ref_array(thd, real_og_num))
DBUG_RETURN(-1); DBUG_RETURN(-1);
@ -4472,11 +4470,6 @@ void JOIN::cleanup_item_list(List<Item> &items) const
the top-level select_lex for this query the top-level select_lex for this query
@param tables list of all tables used in this query. @param tables list of all tables used in this query.
The tables have been pre-opened. The tables have been pre-opened.
@param wild_num number of wildcards used in the top level
select of this query.
For example statement
SELECT *, t1.*, catalog.t2.* FROM t0, t1, t2;
has 3 wildcards.
@param fields list of items in SELECT list of the top-level @param fields list of items in SELECT list of the top-level
select select
e.g. SELECT a, b, c FROM t1 will have Item_field e.g. SELECT a, b, c FROM t1 will have Item_field
@ -4509,12 +4502,10 @@ void JOIN::cleanup_item_list(List<Item> &items) const
*/ */
bool bool
mysql_select(THD *thd, mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds,
TABLE_LIST *tables, uint wild_num, List<Item> &fields, uint og_num, ORDER *order, ORDER *group, Item *having,
COND *conds, uint og_num, ORDER *order, ORDER *group, ORDER *proc_param, ulonglong select_options, select_result *result,
Item *having, ORDER *proc_param, ulonglong select_options, SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex)
select_result *result, SELECT_LEX_UNIT *unit,
SELECT_LEX *select_lex)
{ {
int err= 0; int err= 0;
bool free_join= 1; bool free_join= 1;
@ -4544,9 +4535,8 @@ mysql_select(THD *thd,
} }
else else
{ {
if ((err= join->prepare( tables, wild_num, if ((err= join->prepare(tables, conds, og_num, order, false, group,
conds, og_num, order, false, group, having, having, proc_param, select_lex, unit)))
proc_param, select_lex, unit)))
{ {
goto err; goto err;
} }
@ -4568,9 +4558,8 @@ mysql_select(THD *thd,
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
THD_STAGE_INFO(thd, stage_init); THD_STAGE_INFO(thd, stage_init);
thd->lex->used_tables=0; thd->lex->used_tables=0;
if ((err= join->prepare(tables, wild_num, if ((err= join->prepare(tables, conds, og_num, order, false, group, having,
conds, og_num, order, false, group, having, proc_param, proc_param, select_lex, unit)))
select_lex, unit)))
{ {
goto err; goto err;
} }
@ -26876,15 +26865,11 @@ bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
{ {
thd->lex->current_select= first; thd->lex->current_select= first;
unit->set_limit(unit->global_parameters()); unit->set_limit(unit->global_parameters());
res= mysql_select(thd, res= mysql_select(thd, first->table_list.first, first->item_list,
first->table_list.first,
first->with_wild, first->item_list,
first->where, first->where,
first->order_list.elements + first->group_list.elements, first->order_list.elements + first->group_list.elements,
first->order_list.first, first->order_list.first, first->group_list.first,
first->group_list.first, first->having, thd->lex->proc_list.first,
first->having,
thd->lex->proc_list.first,
first->options | thd->variables.option_bits | SELECT_DESCRIBE, first->options | thd->variables.option_bits | SELECT_DESCRIBE,
result, unit, first); result, unit, first);
} }

View File

@ -1619,10 +1619,9 @@ public:
return exec_join_tab_cnt() + aggr_tables - 1; return exec_join_tab_cnt() + aggr_tables - 1;
} }
int prepare(TABLE_LIST *tables, uint wind_num, int prepare(TABLE_LIST *tables, COND *conds, uint og_num, ORDER *order,
COND *conds, uint og_num, ORDER *order, bool skip_order_by, bool skip_order_by, ORDER *group, Item *having,
ORDER *group, Item *having, ORDER *proc_param, SELECT_LEX *select, ORDER *proc_param, SELECT_LEX *select, SELECT_LEX_UNIT *unit);
SELECT_LEX_UNIT *unit);
bool prepare_stage2(); bool prepare_stage2();
int optimize(); int optimize();
int optimize_inner(); int optimize_inner();
@ -2096,8 +2095,7 @@ int join_read_key2(THD *thd, struct st_join_table *tab, TABLE *table,
bool handle_select(THD *thd, LEX *lex, select_result *result, bool handle_select(THD *thd, LEX *lex, select_result *result,
ulong setup_tables_done_option); ulong setup_tables_done_option);
bool mysql_select(THD *thd, bool mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &list,
TABLE_LIST *tables, uint wild_num, List<Item> &list,
COND *conds, uint og_num, ORDER *order, ORDER *group, COND *conds, uint og_num, ORDER *order, ORDER *group,
Item *having, ORDER *proc_param, ulonglong select_type, Item *having, ORDER *proc_param, ulonglong select_type,
select_result *result, SELECT_LEX_UNIT *unit, select_result *result, SELECT_LEX_UNIT *unit,

View File

@ -1089,7 +1089,6 @@ bool st_select_lex_unit::prepare_join(THD *thd_arg, SELECT_LEX *sl,
can_skip_order_by= is_union_select && !(sl->braces && sl->explicit_limit); can_skip_order_by= is_union_select && !(sl->braces && sl->explicit_limit);
saved_error= join->prepare(sl->table_list.first, saved_error= join->prepare(sl->table_list.first,
sl->with_wild,
(derived && derived->merged ? NULL : sl->where), (derived && derived->merged ? NULL : sl->where),
(can_skip_order_by ? 0 : (can_skip_order_by ? 0 :
sl->order_list.elements) + sl->order_list.elements) +
@ -1103,8 +1102,6 @@ bool st_select_lex_unit::prepare_join(THD *thd_arg, SELECT_LEX *sl,
thd_arg->lex->proc_list.first), thd_arg->lex->proc_list.first),
sl, this); sl, this);
/* There are no * in the statement anymore (for PS) */
sl->with_wild= 0;
last_procedure= join->procedure; last_procedure= join->procedure;
if (unlikely(saved_error || (saved_error= thd_arg->is_fatal_error))) if (unlikely(saved_error || (saved_error= thd_arg->is_fatal_error)))
@ -1803,7 +1800,7 @@ cont:
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
saved_error= fake_select_lex->join-> saved_error= fake_select_lex->join->
prepare(fake_select_lex->table_list.first, 0, 0, prepare(fake_select_lex->table_list.first, 0,
global_parameters()->order_list.elements, // og_num global_parameters()->order_list.elements, // og_num
global_parameters()->order_list.first, // order global_parameters()->order_list.first, // order
false, NULL, NULL, NULL, fake_select_lex, this); false, NULL, NULL, NULL, fake_select_lex, this);
@ -2307,14 +2304,13 @@ bool st_select_lex_unit::exec()
if (!was_executed) if (!was_executed)
save_union_explain_part2(thd->lex->explain); save_union_explain_part2(thd->lex->explain);
saved_error= mysql_select(thd, saved_error= mysql_select(thd, &result_table_list,
&result_table_list, item_list, NULL,
0, item_list, NULL,
global_parameters()->order_list.elements, global_parameters()->order_list.elements,
global_parameters()->order_list.first, global_parameters()->order_list.first,
NULL, NULL, NULL, NULL, NULL, NULL,
fake_select_lex->options | SELECT_NO_UNLOCK, fake_select_lex->options | SELECT_NO_UNLOCK,
result, this, fake_select_lex); result, this, fake_select_lex);
} }
else else
{ {
@ -2330,14 +2326,12 @@ bool st_select_lex_unit::exec()
to reset them back, we re-do all of the actions (yes it is ugly): to reset them back, we re-do all of the actions (yes it is ugly):
*/ // psergey-todo: is the above really necessary anymore?? */ // psergey-todo: is the above really necessary anymore??
join->init(thd, item_list, fake_select_lex->options, result); join->init(thd, item_list, fake_select_lex->options, result);
saved_error= mysql_select(thd, saved_error= mysql_select(thd, &result_table_list, item_list, NULL,
&result_table_list,
0, item_list, NULL,
global_parameters()->order_list.elements, global_parameters()->order_list.elements,
global_parameters()->order_list.first, global_parameters()->order_list.first,
NULL, NULL, NULL, NULL, NULL, NULL,
fake_select_lex->options | SELECT_NO_UNLOCK, fake_select_lex->options | SELECT_NO_UNLOCK,
result, this, fake_select_lex); result, this, fake_select_lex);
} }
else else
{ {

View File

@ -1901,7 +1901,7 @@ bool mysql_multi_update(THD *thd, TABLE_LIST *table_list, List<Item> *fields,
List<Item> total_list; List<Item> total_list;
res= mysql_select(thd, res= mysql_select(thd,
table_list, select_lex->with_wild, total_list, conds, table_list, total_list, conds,
select_lex->order_list.elements, select_lex->order_list.elements,
select_lex->order_list.first, NULL, NULL, NULL, select_lex->order_list.first, NULL, NULL, NULL,
options | SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK | options | SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK |