From 703e396b6ebb6ee156987abe7fa31c7853afafe9 Mon Sep 17 00:00:00 2001 From: "konstantin@mysql.com" <> Date: Sun, 10 Oct 2004 03:10:00 +0400 Subject: [PATCH] A small simplification: perform two actions at once, register a change, and perform it (the new Item changes registry). --- sql/item.cc | 25 ++++++++++--------------- sql/item_cmpfunc.cc | 9 +++------ sql/item_func.cc | 4 ++-- sql/item_row.cc | 4 ++-- sql/item_strfunc.cc | 8 ++++---- sql/sql_class.h | 9 +++++---- sql/sql_select.cc | 13 +++++-------- 7 files changed, 31 insertions(+), 41 deletions(-) diff --git a/sql/item.cc b/sql/item.cc index 36ed56a3481..0366ea29485 100644 --- a/sql/item.cc +++ b/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), - (char*) where->alias, (char*) field_name); + 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); } /* diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index d3b73604f7f..248b56fe064 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -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(); diff --git a/sql/item_func.cc b/sql/item_func.cc index 2a3633bf02b..ccdde399e0a 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -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); } } } diff --git a/sql/item_row.cc b/sql/item_row.cc index b746029947f..289efe45300 100644 --- a/sql/item_row.cc +++ b/sql/item_row.cc @@ -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); } } } diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 843177a850f..301836fa839 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -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); } diff --git a/sql/sql_class.h b/sql/sql_class.h index 8c6634efa50..1e314bb0cb8 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1054,14 +1054,15 @@ 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); + MEM_ROOT *runtime_memroot); void rollback_item_tree_changes(); }; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 2c702e21311..aab00fb8629 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4203,8 +4203,7 @@ change_cond_ref_to_const(THD *thd, I_List *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 *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 &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++;