Skip to content

Commit

Permalink
MDEV-6152: Remove calls to current_thd while creating Item
Browse files Browse the repository at this point in the history
- Part 3: Adding mem_root to push_back() and push_front()

Other things:
- Added THD as an argument to some partition functions.
- Added memory overflow checking for XML tag's in read_xml()
  • Loading branch information
montywi committed Aug 27, 2015
1 parent ba340d8 commit 3cb578c
Show file tree
Hide file tree
Showing 50 changed files with 1,103 additions and 753 deletions.
2 changes: 1 addition & 1 deletion plugin/feedback/feedback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static COND* make_cond(THD *thd, TABLE_LIST *tables, LEX_STRING *filter)
if (!like)
return OOM;

res->add(like);
res->add(like, thd->mem_root);
}

if (res->fix_fields(thd, (Item**)&res))
Expand Down
16 changes: 9 additions & 7 deletions sql/events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -640,35 +640,37 @@ send_show_create_event(THD *thd, Event_timed *et, Protocol *protocol)
DBUG_RETURN(TRUE);

field_list.push_back(new (mem_root)
Item_empty_string(thd, "Event", NAME_CHAR_LEN));
Item_empty_string(thd, "Event", NAME_CHAR_LEN),
mem_root);

if (sql_mode_string_representation(thd, et->sql_mode, &sql_mode))
DBUG_RETURN(TRUE);

field_list.push_back(new (mem_root)
Item_empty_string(thd, "sql_mode",
(uint) sql_mode.length));
(uint) sql_mode.length), mem_root);

tz_name= et->time_zone->get_name();

field_list.push_back(new (mem_root)
Item_empty_string(thd, "time_zone", tz_name->length()));
Item_empty_string(thd, "time_zone", tz_name->length()),
mem_root);

field_list.push_back(new (mem_root)
Item_empty_string(thd, "Create Event",
show_str.length()));
show_str.length()), mem_root);

field_list.push_back(new (mem_root)
Item_empty_string(thd, "character_set_client",
MY_CS_NAME_SIZE));
MY_CS_NAME_SIZE), mem_root);

field_list.push_back(new (mem_root)
Item_empty_string(thd, "collation_connection",
MY_CS_NAME_SIZE));
MY_CS_NAME_SIZE), mem_root);

field_list.push_back(new (mem_root)
Item_empty_string(thd, "Database Collation",
MY_CS_NAME_SIZE));
MY_CS_NAME_SIZE), mem_root);

if (protocol->send_result_set_metadata(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
Expand Down
2 changes: 1 addition & 1 deletion sql/ha_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ int ha_partition::change_partitions(HA_CREATE_INFO *create_info,
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
if (p_share_refs->init(num_subparts))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
if (m_new_partitions_share_refs.push_back(p_share_refs))
if (m_new_partitions_share_refs.push_back(p_share_refs, thd->mem_root))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
do
{
Expand Down
18 changes: 11 additions & 7 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1986,16 +1986,16 @@ bool mysql_xa_recover(THD *thd)

field_list.push_back(new (mem_root)
Item_int(thd, "formatID", 0,
MY_INT32_NUM_DECIMAL_DIGITS));
MY_INT32_NUM_DECIMAL_DIGITS), mem_root);
field_list.push_back(new (mem_root)
Item_int(thd, "gtrid_length", 0,
MY_INT32_NUM_DECIMAL_DIGITS));
MY_INT32_NUM_DECIMAL_DIGITS), mem_root);
field_list.push_back(new (mem_root)
Item_int(thd, "bqual_length", 0,
MY_INT32_NUM_DECIMAL_DIGITS));
MY_INT32_NUM_DECIMAL_DIGITS), mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "data",
XIDDATASIZE));
XIDDATASIZE), mem_root);

if (protocol->send_result_set_metadata(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
Expand Down Expand Up @@ -5533,9 +5533,13 @@ bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat)
MEM_ROOT *mem_root= thd->mem_root;
bool result;

field_list.push_back(new (mem_root) Item_empty_string(thd, "Type", 10));
field_list.push_back(new (mem_root) Item_empty_string(thd, "Name", FN_REFLEN));
field_list.push_back(new (mem_root) Item_empty_string(thd, "Status", 10));
field_list.push_back(new (mem_root) Item_empty_string(thd, "Type", 10),
mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Name", FN_REFLEN), mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Status", 10),
mem_root);

if (protocol->send_result_set_metadata(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
Expand Down
20 changes: 11 additions & 9 deletions sql/item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4785,7 +4785,7 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
non aggregated fields of the outer select.
*/
marker= select->cur_pos_in_select_list;
select->non_agg_fields.push_back(this);
select->non_agg_fields.push_back(this, thd->mem_root);
}
if (*from_field != view_ref_found)
{
Expand All @@ -4810,7 +4810,7 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
if (!(rf= new (thd->mem_root) Item_outer_ref(thd, context, this)))
return -1;
thd->change_item_tree(reference, rf);
select->inner_refs_list.push_back(rf);
select->inner_refs_list.push_back(rf, thd->mem_root);
rf->in_sum_func= thd->lex->in_sum_func;
}
/*
Expand Down Expand Up @@ -4930,7 +4930,8 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)

if (place != IN_HAVING && select->group_list.elements)
{
outer_context->select_lex->inner_refs_list.push_back((Item_outer_ref*)rf);
outer_context->select_lex->inner_refs_list.push_back((Item_outer_ref*)rf,
thd->mem_root);
((Item_outer_ref*)rf)->in_sum_func= thd->lex->in_sum_func;
}
thd->change_item_tree(reference, rf);
Expand Down Expand Up @@ -5205,7 +5206,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
!outer_fixed && !thd->lex->in_sum_func &&
thd->lex->current_select->cur_pos_in_select_list != UNDEF_POS)
{
thd->lex->current_select->non_agg_fields.push_back(this);
thd->lex->current_select->non_agg_fields.push_back(this, thd->mem_root);
marker= thd->lex->current_select->cur_pos_in_select_list;
}
mark_non_agg_field:
Expand Down Expand Up @@ -5241,7 +5242,7 @@ bool Item_field::fix_fields(THD *thd, Item **reference)
else
{
if (outer_fixed)
thd->lex->in_sum_func->outer_fields.push_back(this);
thd->lex->in_sum_func->outer_fields.push_back(this, thd->mem_root);
else if (thd->lex->in_sum_func->nest_level !=
thd->lex->current_select->nest_level)
select_lex->set_non_agg_field_used(true);
Expand Down Expand Up @@ -6731,9 +6732,10 @@ Item *Item_field::update_value_transformer(THD *thd, uchar *select_arg)
Item_ref *ref;

ref_pointer_array[el]= (Item*)this;
all_fields->push_front((Item*)this);
ref= new (thd->mem_root) Item_ref(thd, &select->context, ref_pointer_array + el,
table_name, field_name);
all_fields->push_front((Item*)this, thd->mem_root);
ref= new (thd->mem_root)
Item_ref(thd, &select->context, ref_pointer_array + el,
table_name, field_name);
return ref;
}
return this;
Expand Down Expand Up @@ -7165,7 +7167,7 @@ void Item_ref::cleanup()

Item* Item_ref::transform(THD *thd, Item_transformer transformer, uchar *arg)
{
DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
DBUG_ASSERT(!thd->stmt_arena->is_stmt_prepare());
DBUG_ASSERT((*ref) != NULL);

/* Transform the object we are referencing. */
Expand Down
38 changes: 33 additions & 5 deletions sql/item_cmpfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2774,6 +2774,26 @@ Item_func_nullif::is_null()
}


Item_func_case::Item_func_case(THD *thd, List<Item> &list,
Item *first_expr_arg, Item *else_expr_arg):
Item_func_hybrid_field_type(thd), first_expr_num(-1), else_expr_num(-1),
left_result_type(INT_RESULT), case_item(0)
{
ncases= list.elements;
if (first_expr_arg)
{
first_expr_num= list.elements;
list.push_back(first_expr_arg, thd->mem_root);
}
if (else_expr_arg)
{
else_expr_num= list.elements;
list.push_back(else_expr_arg, thd->mem_root);
}
set_arguments(list);
bzero(&cmp_items, sizeof(cmp_items));
}

/**
Find and return matching items for CASE or ELSE item if all compares
are failed or NULL if ELSE item isn't defined.
Expand Down Expand Up @@ -4252,6 +4272,14 @@ Item_cond::Item_cond(THD *thd, Item_cond *item)
}


Item_cond::Item_cond(THD *thd, Item *i1, Item *i2):
Item_bool_func(thd), abort_on_null(0)
{
list.push_back(i1, thd->mem_root);
list.push_back(i2, thd->mem_root);
}


Item *Item_cond_and::copy_andor_structure(THD *thd)
{
Item_cond_and *item;
Expand All @@ -4265,7 +4293,7 @@ void Item_cond::copy_andor_arguments(THD *thd, Item_cond *item)
{
List_iterator_fast<Item> li(item->list);
while (Item *it= li++)
list.push_back(it->copy_andor_structure(thd));
list.push_back(it->copy_andor_structure(thd), thd->mem_root);
}


Expand Down Expand Up @@ -4788,7 +4816,7 @@ Item *and_expressions(THD *thd, Item *a, Item *b, Item **org_item)
}
return res;
}
if (((Item_cond_and*) a)->add((Item*) b))
if (((Item_cond_and*) a)->add((Item*) b, thd->mem_root))
return 0;
((Item_cond_and*) a)->used_tables_cache|= b->used_tables();
((Item_cond_and*) a)->not_null_tables_cache|= b->not_null_tables();
Expand Down Expand Up @@ -5836,7 +5864,7 @@ void Item_equal::add_const(THD *thd, Item *c, Item *f)
with_const= TRUE;
if (f)
compare_as_dates= f->cmp_type() == TIME_RESULT;
equal_items.push_front(c);
equal_items.push_front(c, thd->mem_root);
return;
}
Item *const_item= get_const();
Expand Down Expand Up @@ -5991,7 +6019,7 @@ bool Item_equal::merge_with_check(THD *thd, Item_equal *item, bool save_merged)
while ((item= fi++))
{
if (!contains(fi.get_curr_field()))
add(item);
add(item, thd->mem_root);
}
}
}
Expand Down Expand Up @@ -6041,7 +6069,7 @@ void Item_equal::merge_into_list(THD *thd, List<Item_equal> *list,
}
}
if (!only_intersected && !merge_into)
list->push_back(this);
list->push_back(this, thd->mem_root);
}


Expand Down
36 changes: 7 additions & 29 deletions sql/item_cmpfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1302,24 +1302,7 @@ class Item_func_case :public Item_func_hybrid_field_type
cmp_item *case_item;
public:
Item_func_case(THD *thd, List<Item> &list, Item *first_expr_arg,
Item *else_expr_arg):
Item_func_hybrid_field_type(thd), first_expr_num(-1), else_expr_num(-1),
left_result_type(INT_RESULT), case_item(0)
{
ncases= list.elements;
if (first_expr_arg)
{
first_expr_num= list.elements;
list.push_back(first_expr_arg);
}
if (else_expr_arg)
{
else_expr_num= list.elements;
list.push_back(else_expr_arg);
}
set_arguments(list);
bzero(&cmp_items, sizeof(cmp_items));
}
Item *else_expr_arg);
double real_op();
longlong int_op();
String *str_op(String *);
Expand Down Expand Up @@ -1789,24 +1772,19 @@ class Item_cond :public Item_bool_func
/* Item_cond() is only used to create top level items */
Item_cond(THD *thd): Item_bool_func(thd), abort_on_null(1)
{ const_item_cache=0; }
Item_cond(THD *thd, Item *i1, Item *i2):
Item_bool_func(thd), abort_on_null(0)
{
list.push_back(i1);
list.push_back(i2);
}
Item_cond(THD *thd, Item *i1, Item *i2);
Item_cond(THD *thd, Item_cond *item);
Item_cond(THD *thd, List<Item> &nlist):
Item_bool_func(thd), list(nlist), abort_on_null(0) {}
bool add(Item *item)
bool add(Item *item, MEM_ROOT *root)
{
DBUG_ASSERT(item);
return list.push_back(item);
return list.push_back(item, root);
}
bool add_at_head(Item *item)
bool add_at_head(Item *item, MEM_ROOT *root)
{
DBUG_ASSERT(item);
return list.push_front(item);
return list.push_front(item, root);
}
void add_at_head(List<Item> *nlist)
{
Expand Down Expand Up @@ -2004,7 +1982,7 @@ class Item_equal: public Item_bool_func
inline Item* get_const() { return with_const ? equal_items.head() : NULL; }
void add_const(THD *thd, Item *c, Item *f = NULL);
/** Add a non-constant item to the multiple equality */
void add(Item *f) { equal_items.push_back(f); }
void add(Item *f, MEM_ROOT *root) { equal_items.push_back(f, root); }
bool contains(Field *field);
Item* get_first(struct st_join_table *context, Item *field);
/** Get number of field items / references to field items in this object */
Expand Down
12 changes: 6 additions & 6 deletions sql/item_create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6349,8 +6349,8 @@ static List<Item> *create_func_dyncol_prepare(THD *thd,
for (uint i= 0; (def= li++) ;)
{
dfs[0][i++]= *def;
args->push_back(def->key);
args->push_back(def->value);
args->push_back(def->key, thd->mem_root);
args->push_back(def->value, thd->mem_root);
}
return args;
}
Expand All @@ -6374,7 +6374,7 @@ Item *create_func_dyncol_add(THD *thd, Item *str,
if (!(args= create_func_dyncol_prepare(thd, &dfs, list)))
return NULL;

args->push_back(str);
args->push_back(str, thd->mem_root);

return new (thd->mem_root) Item_func_dyncol_add(thd, *args, dfs);
}
Expand All @@ -6399,11 +6399,11 @@ Item *create_func_dyncol_delete(THD *thd, Item *str, List<Item> &nums)
dfs[i].key= key;
dfs[i].value= new (thd->mem_root) Item_null(thd);
dfs[i].type= DYN_COL_INT;
args->push_back(dfs[i].key);
args->push_back(dfs[i].value);
args->push_back(dfs[i].key, thd->mem_root);
args->push_back(dfs[i].value, thd->mem_root);
}

args->push_back(str);
args->push_back(str, thd->mem_root);

return new (thd->mem_root) Item_func_dyncol_add(thd, *args, dfs);
}
Expand Down
7 changes: 5 additions & 2 deletions sql/item_func.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5552,7 +5552,8 @@ get_var_with_binlog(THD *thd, enum_sql_command sql_command,
tmp_var_list.push_back(new (thd->mem_root)
set_var_user(new (thd->mem_root)
Item_func_set_user_var(thd, name,
new (thd->mem_root) Item_null(thd))));
new (thd->mem_root) Item_null(thd))),
thd->mem_root);
/* Create the variable */
if (sql_set_variables(thd, &tmp_var_list, false))
{
Expand Down Expand Up @@ -6131,7 +6132,9 @@ void Item_func_match::init_search(THD *thd, bool no_order)
if (key == NO_SUCH_KEY)
{
List<Item> fields;
fields.push_back(new (thd->mem_root) Item_string(thd, " ", 1, cmp_collation.collation));
fields.push_back(new (thd->mem_root)
Item_string(thd, " ", 1, cmp_collation.collation),
thd->mem_root);
for (uint i= 1; i < arg_count; i++)
fields.push_back(args[i]);
concat_ws= new (thd->mem_root) Item_func_concat_ws(thd, fields);
Expand Down
Loading

0 comments on commit 3cb578c

Please sign in to comment.