mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
A small simplification: perform two actions at once, register a
change, and perform it (the new Item changes registry).
This commit is contained in:
23
sql/item.cc
23
sql/item.cc
@ -1332,13 +1332,11 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
|
||||
return -1;
|
||||
}
|
||||
|
||||
Item_ref *rf;
|
||||
*ref= rf= new Item_ref(last->ref_pointer_array + counter,
|
||||
(char *)table_name,
|
||||
(char *)field_name);
|
||||
thd->register_item_tree_change(ref, this, &thd->mem_root);
|
||||
Item_ref *rf= new Item_ref(last->ref_pointer_array + counter,
|
||||
(char *)table_name, (char *)field_name);
|
||||
if (!rf)
|
||||
return 1;
|
||||
thd->change_item_tree(ref, rf);
|
||||
/*
|
||||
rf is Item_ref => never substitute other items (in this case)
|
||||
during fix_fields() => we can use rf after fix_fields()
|
||||
@ -1355,11 +1353,11 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
|
||||
if (last->having_fix_field)
|
||||
{
|
||||
Item_ref *rf;
|
||||
thd->register_item_tree_change(ref, *ref, &thd->mem_root);
|
||||
*ref= rf= new Item_ref((where->db[0] ? where->db : 0),
|
||||
rf= new Item_ref((where->db[0] ? where->db : 0),
|
||||
(char*) where->alias, (char*) field_name);
|
||||
if (!rf)
|
||||
return 1;
|
||||
thd->change_item_tree(ref, rf);
|
||||
/*
|
||||
rf is Item_ref => never substitute other items (in this case)
|
||||
during fix_fields() => we can use rf after fix_fields()
|
||||
@ -1992,10 +1990,10 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference)
|
||||
else if (tmp != not_found_field)
|
||||
{
|
||||
ref= 0; // To prevent "delete *ref;" on ~Item_ref() of this item
|
||||
Item_field* fld;
|
||||
if (!((*reference)= fld= new Item_field(tmp)))
|
||||
Item_field* fld= new Item_field(tmp);
|
||||
if (!fld)
|
||||
return 1;
|
||||
thd->register_item_tree_change(reference, this, &thd->mem_root);
|
||||
thd->change_item_tree(reference, fld);
|
||||
mark_as_dependent(thd, last, thd->lex->current_select, fld);
|
||||
return 0;
|
||||
}
|
||||
@ -2250,10 +2248,7 @@ void resolve_const_item(THD *thd, Item **ref, Item *comp_item)
|
||||
new Item_real(name, result, decimals, length));
|
||||
}
|
||||
if (new_item)
|
||||
{
|
||||
thd->register_item_tree_change(ref, item, &thd->mem_root);
|
||||
*ref= new_item;
|
||||
}
|
||||
thd->change_item_tree(ref, new_item);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -153,10 +153,7 @@ static bool convert_constant_item(THD *thd, Field *field, Item **item)
|
||||
{
|
||||
Item *tmp=new Item_int_with_ref(field->val_int(), *item);
|
||||
if (tmp)
|
||||
{
|
||||
thd->register_item_tree_change(item, *item, &thd->mem_root);
|
||||
*item=tmp;
|
||||
}
|
||||
thd->change_item_tree(item, tmp);
|
||||
return 1; // Item was replaced
|
||||
}
|
||||
}
|
||||
@ -2033,10 +2030,10 @@ void Item_cond::split_sum_func(THD *thd, Item **ref_pointer_array,
|
||||
{
|
||||
Item **ref= li.ref();
|
||||
uint el= fields.elements;
|
||||
Item *new_item= new Item_ref(ref_pointer_array + el, 0, item->name);
|
||||
fields.push_front(item);
|
||||
ref_pointer_array[el]= item;
|
||||
thd->register_item_tree_change(ref, *ref, &thd->mem_root);
|
||||
li.replace(new Item_ref(ref_pointer_array + el, 0, item->name));
|
||||
thd->change_item_tree(ref, new_item);
|
||||
}
|
||||
item->update_used_tables();
|
||||
used_tables_cache|=item->used_tables();
|
||||
|
@ -269,10 +269,10 @@ void Item_func::split_sum_func(THD *thd, Item **ref_pointer_array,
|
||||
else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
|
||||
{
|
||||
uint el= fields.elements;
|
||||
Item *new_item= new Item_ref(ref_pointer_array + el, 0, item->name);
|
||||
fields.push_front(item);
|
||||
ref_pointer_array[el]= item;
|
||||
thd->register_item_tree_change(arg, *arg, &thd->mem_root);
|
||||
*arg= new Item_ref(ref_pointer_array + el, 0, item->name);
|
||||
thd->change_item_tree(arg, new_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,10 +95,10 @@ void Item_row::split_sum_func(THD *thd, Item **ref_pointer_array,
|
||||
else if ((*arg)->used_tables() || (*arg)->type() == SUM_FUNC_ITEM)
|
||||
{
|
||||
uint el= fields.elements;
|
||||
Item *new_item= new Item_ref(ref_pointer_array + el, 0, (*arg)->name);
|
||||
fields.push_front(*arg);
|
||||
ref_pointer_array[el]= *arg;
|
||||
thd->register_item_tree_change(arg, *arg, &thd->mem_root);
|
||||
*arg= new Item_ref(ref_pointer_array + el, 0, (*arg)->name);
|
||||
thd->change_item_tree(arg, new_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -643,10 +643,10 @@ void Item_func_concat_ws::split_sum_func(THD *thd, Item **ref_pointer_array,
|
||||
else if (separator->used_tables() || separator->type() == SUM_FUNC_ITEM)
|
||||
{
|
||||
uint el= fields.elements;
|
||||
Item *new_item= new Item_ref(ref_pointer_array + el, 0, separator->name);
|
||||
fields.push_front(separator);
|
||||
ref_pointer_array[el]= separator;
|
||||
thd->register_item_tree_change(&separator, separator, &thd->mem_root);
|
||||
separator= new Item_ref(ref_pointer_array + el, 0, separator->name);
|
||||
thd->change_item_tree(&separator, new_item);
|
||||
}
|
||||
Item_str_func::split_sum_func(thd, ref_pointer_array, fields);
|
||||
}
|
||||
@ -1779,10 +1779,10 @@ void Item_func_make_set::split_sum_func(THD *thd, Item **ref_pointer_array,
|
||||
else if (item->used_tables() || item->type() == SUM_FUNC_ITEM)
|
||||
{
|
||||
uint el= fields.elements;
|
||||
Item *new_item= new Item_ref(ref_pointer_array + el, 0, item->name);
|
||||
fields.push_front(item);
|
||||
ref_pointer_array[el]= item;
|
||||
thd->register_item_tree_change(&item, item, &thd->mem_root);
|
||||
item= new Item_ref(ref_pointer_array + el, 0, item->name);
|
||||
thd->change_item_tree(&item, new_item);
|
||||
}
|
||||
Item_str_func::split_sum_func(thd, ref_pointer_array, fields);
|
||||
}
|
||||
|
@ -1054,11 +1054,12 @@ public:
|
||||
inline CHARSET_INFO *charset() { return variables.character_set_client; }
|
||||
void update_charset();
|
||||
|
||||
void register_item_tree_change(Item **place, Item *old_value,
|
||||
MEM_ROOT *runtime_memroot)
|
||||
void change_item_tree(Item **place, Item *new_value)
|
||||
{
|
||||
/* TODO: check for OOM condition here */
|
||||
if (!current_arena->is_conventional_execution())
|
||||
nocheck_register_item_tree_change(place, old_value, runtime_memroot);
|
||||
nocheck_register_item_tree_change(place, *place, &mem_root);
|
||||
*place= new_value;
|
||||
}
|
||||
void nocheck_register_item_tree_change(Item **place, Item *old_value,
|
||||
MEM_ROOT *runtime_memroot);
|
||||
|
@ -4203,8 +4203,7 @@ change_cond_ref_to_const(THD *thd, I_List<COND_CMP> *save_list,
|
||||
Item *tmp=value->new_item();
|
||||
if (tmp)
|
||||
{
|
||||
thd->register_item_tree_change(args + 1, args[1], &thd->mem_root);
|
||||
args[1]= tmp;
|
||||
thd->change_item_tree(args + 1, tmp);
|
||||
func->update_used_tables();
|
||||
if ((functype == Item_func::EQ_FUNC || functype == Item_func::EQUAL_FUNC)
|
||||
&& and_father != cond && !left_item->const_item())
|
||||
@ -4225,15 +4224,14 @@ change_cond_ref_to_const(THD *thd, I_List<COND_CMP> *save_list,
|
||||
Item *tmp=value->new_item();
|
||||
if (tmp)
|
||||
{
|
||||
thd->register_item_tree_change(args, args[0], &thd->mem_root);
|
||||
args[0]= value= tmp;
|
||||
thd->change_item_tree(args, tmp);
|
||||
value= tmp;
|
||||
func->update_used_tables();
|
||||
if ((functype == Item_func::EQ_FUNC || functype == Item_func::EQUAL_FUNC)
|
||||
&& and_father != cond && !right_item->const_item())
|
||||
{
|
||||
args[0]= args[1]; // For easy check
|
||||
thd->register_item_tree_change(args + 1, args[1], &thd->mem_root);
|
||||
args[1]= value;
|
||||
thd->change_item_tree(args + 1, value);
|
||||
cond->marker=1;
|
||||
COND_CMP *tmp2;
|
||||
if ((tmp2=new COND_CMP(and_father,func)))
|
||||
@ -4959,8 +4957,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
|
||||
*blob_field++= new_field;
|
||||
blob_count++;
|
||||
}
|
||||
thd->register_item_tree_change(argp, arg, &thd->mem_root);
|
||||
*argp= new Item_field(new_field);
|
||||
thd->change_item_tree(argp, new Item_field(new_field));
|
||||
if (!(new_field->flags & NOT_NULL_FLAG))
|
||||
{
|
||||
null_count++;
|
||||
|
Reference in New Issue
Block a user