summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2019-09-22 23:23:28 +0200
committerSergei Golubchik <serg@mariadb.org>2019-10-14 10:29:30 +0200
commita4a025f5d1aa123e31d86be82b79daa15a523b19 (patch)
treecc018f627daa711bb2fd87a61c41b6d52aab886f
parentc7320830a62b0ed3245c476f074c534d3cd20027 (diff)
downloadmariadb-git-a4a025f5d1aa123e31d86be82b79daa15a523b19.tar.gz
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.
-rw-r--r--sql/item_subselect.cc1
-rw-r--r--sql/sql_base.cc32
-rw-r--r--sql/sql_base.h2
-rw-r--r--sql/sql_delete.cc3
-rw-r--r--sql/sql_derived.cc1
-rw-r--r--sql/sql_parse.cc1
-rw-r--r--sql/sql_select.cc43
-rw-r--r--sql/sql_select.h10
-rw-r--r--sql/sql_union.cc26
-rw-r--r--sql/sql_update.cc2
10 files changed, 39 insertions, 82 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index c9675b227a1..ea6a9910e1f 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -3720,7 +3720,6 @@ int subselect_single_select_engine::prepare(THD *thd)
SELECT_LEX *save_select= thd->lex->current_select;
thd->lex->current_select= select_lex;
if (join->prepare(select_lex->table_list.first,
- select_lex->with_wild,
select_lex->where,
select_lex->order_list.elements +
select_lex->group_list.elements,
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 57038c1a64a..feb79990796 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -7459,17 +7459,16 @@ static bool setup_natural_join_row_types(THD *thd,
****************************************************************************/
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 *select_lex)
{
- if (!wild_num)
- return(0);
-
Item *item;
List_iterator<Item> it(fields);
Query_arena *arena, backup;
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
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);
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 &&
((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,
((Item_field*) item)->db_name.str,
((Item_field*) item)->table_name.str, &it,
- any_privileges, hidden_bit_fields))
+ any_privileges, &select_lex->hidden_bit_fields))
{
if (arena)
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;
}
- wild_num--;
+ select_lex->with_wild--;
}
else
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;
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);
- }
DBUG_RETURN(0);
}
diff --git a/sql/sql_base.h b/sql/sql_base.h
index 28a787c56dd..40dd3ed0907 100644
--- a/sql/sql_base.h
+++ b/sql/sql_base.h
@@ -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,
bool full_table_list, TABLE_LIST *boundary);
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,
List<Item> &item, enum_column_usage column_usage,
List<Item> *sum_func_list, List<Item> *pre_fix,
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 4488b4a92dd..d39bcaea299 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -1061,8 +1061,7 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list,
DBUG_RETURN(true);
}
- if ((wild_num && setup_wild(thd, table_list, field_list, NULL, wild_num,
- &select_lex->hidden_bit_fields)) ||
+ if ((wild_num && setup_wild(thd, table_list, field_list, NULL, select_lex)) ||
setup_fields(thd, Ref_ptr_array(),
field_list, MARK_COLUMNS_READ, NULL, NULL, 0) ||
setup_conds(thd, table_list, select_lex->leaf_tables, conds) ||
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc
index 78e87fe737f..f4eaa43e8ab 100644
--- a/sql/sql_derived.cc
+++ b/sql/sql_derived.cc
@@ -1224,7 +1224,6 @@ bool mysql_derived_fill(THD *thd, LEX *lex, TABLE_LIST *derived)
lex->current_select= first_select;
res= mysql_select(thd,
first_select->table_list.first,
- first_select->with_wild,
first_select->item_list, first_select->where,
(first_select->order_list.elements+
first_select->group_list.elements),
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index c921e2137e6..0adba6f64e0 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -4727,7 +4727,6 @@ mysql_execute_command(THD *thd)
{
res= mysql_select(thd,
select_lex->get_table_list(),
- select_lex->with_wild,
select_lex->item_list,
select_lex->where,
0, (ORDER *)NULL, (ORDER *)NULL, (Item *)NULL,
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 824d9b4e5bb..ee9c84e44fd 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -415,7 +415,7 @@ bool handle_select(THD *thd, LEX *lex, select_result *result,
*/
res= mysql_select(thd,
select_lex->table_list.first,
- select_lex->with_wild, select_lex->item_list,
+ select_lex->item_list,
select_lex->where,
select_lex->order_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
*/
int
-JOIN::prepare(TABLE_LIST *tables_init,
- uint wild_num, COND *conds_init, uint og_num,
+JOIN::prepare(TABLE_LIST *tables_init, COND *conds_init, uint og_num,
ORDER *order_init, bool skip_order_by,
ORDER *group_init, Item *having_init,
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;
DBUG_ASSERT(select_lex->hidden_bit_fields == 0);
- if (setup_wild(thd, tables_list, fields_list, &all_fields, wild_num,
- &select_lex->hidden_bit_fields))
+ if (setup_wild(thd, tables_list, fields_list, &all_fields, select_lex))
DBUG_RETURN(-1);
if (select_lex->setup_ref_array(thd, real_og_num))
DBUG_RETURN(-1);
@@ -4472,11 +4470,6 @@ void JOIN::cleanup_item_list(List<Item> &items) const
the top-level select_lex for this query
@param tables list of all tables used in this query.
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
select
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
-mysql_select(THD *thd,
- TABLE_LIST *tables, uint wild_num, List<Item> &fields,
- COND *conds, uint og_num, ORDER *order, ORDER *group,
- Item *having, ORDER *proc_param, ulonglong select_options,
- select_result *result, SELECT_LEX_UNIT *unit,
- SELECT_LEX *select_lex)
+mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &fields, COND *conds,
+ uint og_num, ORDER *order, ORDER *group, Item *having,
+ ORDER *proc_param, ulonglong select_options, select_result *result,
+ SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex)
{
int err= 0;
bool free_join= 1;
@@ -4544,9 +4535,8 @@ mysql_select(THD *thd,
}
else
{
- if ((err= join->prepare( tables, wild_num,
- conds, og_num, order, false, group, having,
- proc_param, select_lex, unit)))
+ if ((err= join->prepare(tables, conds, og_num, order, false, group,
+ having, proc_param, select_lex, unit)))
{
goto err;
}
@@ -4568,9 +4558,8 @@ mysql_select(THD *thd,
DBUG_RETURN(TRUE);
THD_STAGE_INFO(thd, stage_init);
thd->lex->used_tables=0;
- if ((err= join->prepare(tables, wild_num,
- conds, og_num, order, false, group, having, proc_param,
- select_lex, unit)))
+ if ((err= join->prepare(tables, conds, og_num, order, false, group, having,
+ proc_param, select_lex, unit)))
{
goto err;
}
@@ -26876,15 +26865,11 @@ bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
{
thd->lex->current_select= first;
unit->set_limit(unit->global_parameters());
- res= mysql_select(thd,
- first->table_list.first,
- first->with_wild, first->item_list,
+ res= mysql_select(thd, first->table_list.first, first->item_list,
first->where,
first->order_list.elements + first->group_list.elements,
- first->order_list.first,
- first->group_list.first,
- first->having,
- thd->lex->proc_list.first,
+ first->order_list.first, first->group_list.first,
+ first->having, thd->lex->proc_list.first,
first->options | thd->variables.option_bits | SELECT_DESCRIBE,
result, unit, first);
}
diff --git a/sql/sql_select.h b/sql/sql_select.h
index 4f7bf49f635..d440d79fbf5 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -1619,10 +1619,9 @@ public:
return exec_join_tab_cnt() + aggr_tables - 1;
}
- int prepare(TABLE_LIST *tables, uint wind_num,
- COND *conds, uint og_num, ORDER *order, bool skip_order_by,
- ORDER *group, Item *having, ORDER *proc_param, SELECT_LEX *select,
- SELECT_LEX_UNIT *unit);
+ int prepare(TABLE_LIST *tables, COND *conds, uint og_num, ORDER *order,
+ bool skip_order_by, ORDER *group, Item *having,
+ ORDER *proc_param, SELECT_LEX *select, SELECT_LEX_UNIT *unit);
bool prepare_stage2();
int optimize();
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,
ulong setup_tables_done_option);
-bool mysql_select(THD *thd,
- TABLE_LIST *tables, uint wild_num, List<Item> &list,
+bool mysql_select(THD *thd, TABLE_LIST *tables, List<Item> &list,
COND *conds, uint og_num, ORDER *order, ORDER *group,
Item *having, ORDER *proc_param, ulonglong select_type,
select_result *result, SELECT_LEX_UNIT *unit,
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index aba1107b6e8..ece5a84b1c3 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -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);
saved_error= join->prepare(sl->table_list.first,
- sl->with_wild,
(derived && derived->merged ? NULL : sl->where),
(can_skip_order_by ? 0 :
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),
sl, this);
- /* There are no * in the statement anymore (for PS) */
- sl->with_wild= 0;
last_procedure= join->procedure;
if (unlikely(saved_error || (saved_error= thd_arg->is_fatal_error)))
@@ -1803,7 +1800,7 @@ cont:
DBUG_RETURN(TRUE);
}
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.first, // order
false, NULL, NULL, NULL, fake_select_lex, this);
@@ -2307,14 +2304,13 @@ bool st_select_lex_unit::exec()
if (!was_executed)
save_union_explain_part2(thd->lex->explain);
- saved_error= mysql_select(thd,
- &result_table_list,
- 0, item_list, NULL,
+ saved_error= mysql_select(thd, &result_table_list,
+ item_list, NULL,
global_parameters()->order_list.elements,
global_parameters()->order_list.first,
- NULL, NULL, NULL,
- fake_select_lex->options | SELECT_NO_UNLOCK,
- result, this, fake_select_lex);
+ NULL, NULL, NULL,
+ fake_select_lex->options | SELECT_NO_UNLOCK,
+ result, this, fake_select_lex);
}
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):
*/ // psergey-todo: is the above really necessary anymore??
join->init(thd, item_list, fake_select_lex->options, result);
- saved_error= mysql_select(thd,
- &result_table_list,
- 0, item_list, NULL,
+ saved_error= mysql_select(thd, &result_table_list, item_list, NULL,
global_parameters()->order_list.elements,
global_parameters()->order_list.first,
- NULL, NULL, NULL,
- fake_select_lex->options | SELECT_NO_UNLOCK,
- result, this, fake_select_lex);
+ NULL, NULL, NULL,
+ fake_select_lex->options | SELECT_NO_UNLOCK,
+ result, this, fake_select_lex);
}
else
{
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 6e2fec83d26..296197524eb 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -1901,7 +1901,7 @@ bool mysql_multi_update(THD *thd, TABLE_LIST *table_list, List<Item> *fields,
List<Item> total_list;
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.first, NULL, NULL, NULL,
options | SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK |