diff options
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r-- | sql/item_sum.cc | 79 |
1 files changed, 54 insertions, 25 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 3bc52159a96..2753c2a5d53 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -42,17 +42,17 @@ Item_sum::Item_sum(List<Item> &list) } // Constructor used in processing select with temporary tebles -Item_sum::Item_sum(THD *thd, Item_sum &item): - Item_result_field(thd, item), quick_group(item.quick_group) +Item_sum::Item_sum(THD *thd, Item_sum *item): + Item_result_field(thd, item), quick_group(item->quick_group) { - arg_count= item.arg_count; + arg_count= item->arg_count; if (arg_count <= 2) args=tmp_args; else if (!(args=(Item**) sql_alloc(sizeof(Item*)*arg_count))) return; for (uint i= 0; i < arg_count; i++) - args[i]= item.args[i]; + args[i]= item->args[i]; } void Item_sum::mark_as_sum_func() @@ -240,7 +240,7 @@ Item_sum_hybrid::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) Item *Item_sum_sum::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_sum(thd, *this); + return new (&thd->mem_root) Item_sum_sum(thd, this); } @@ -383,7 +383,7 @@ double Item_sum_sum_distinct::val() Item *Item_sum_count::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_count(thd, *this); + return new (&thd->mem_root) Item_sum_count(thd, this); } @@ -417,7 +417,7 @@ longlong Item_sum_count::val_int() Item *Item_sum_avg::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_avg(thd, *this); + return new (&thd->mem_root) Item_sum_avg(thd, this); } @@ -462,7 +462,7 @@ double Item_sum_std::val() Item *Item_sum_std::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_std(thd, *this); + return new (&thd->mem_root) Item_sum_std(thd, this); } @@ -472,7 +472,7 @@ Item *Item_sum_std::copy_or_same(THD* thd) Item *Item_sum_variance::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_variance(thd, *this); + return new (&thd->mem_root) Item_sum_variance(thd, this); } @@ -613,7 +613,7 @@ Item_sum_hybrid::val_str(String *str) Item *Item_sum_min::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_min(thd, *this); + return new (&thd->mem_root) Item_sum_min(thd, this); } @@ -666,7 +666,7 @@ bool Item_sum_min::add() Item *Item_sum_max::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_max(thd, *this); + return new (&thd->mem_root) Item_sum_max(thd, this); } @@ -732,7 +732,7 @@ void Item_sum_bit::clear() Item *Item_sum_or::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_or(thd, *this); + return new (&thd->mem_root) Item_sum_or(thd, this); } @@ -746,7 +746,7 @@ bool Item_sum_or::add() Item *Item_sum_xor::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_xor(thd, *this); + return new (&thd->mem_root) Item_sum_xor(thd, this); } @@ -760,7 +760,7 @@ bool Item_sum_xor::add() Item *Item_sum_and::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_and(thd, *this); + return new (&thd->mem_root) Item_sum_and(thd, this); } @@ -1193,8 +1193,9 @@ int dump_leaf(byte* key, uint32 count __attribute__((unused)), } -Item_sum_count_distinct::~Item_sum_count_distinct() +void Item_sum_count_distinct::cleanup() { + Item_sum_int::cleanup(); /* Free table and tree if they belong to this item (if item have not pointer to original item from which was made copy => it own its objects ) @@ -1202,13 +1203,21 @@ Item_sum_count_distinct::~Item_sum_count_distinct() if (!original) { if (table) + { free_tmp_table(current_thd, table); + table= 0; + } delete tmp_table_param; + tmp_table_param= 0; if (use_tree) + { delete_tree(tree); + use_tree= 0; + } } } + bool Item_sum_count_distinct::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) { @@ -1390,7 +1399,7 @@ int Item_sum_count_distinct::tree_to_myisam() Item *Item_sum_count_distinct::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_count_distinct(thd, *this); + return new (&thd->mem_root) Item_sum_count_distinct(thd, this); } @@ -1490,7 +1499,7 @@ bool Item_udf_sum::add() Item *Item_sum_udf_float::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_udf_float(thd, *this); + return new (&thd->mem_root) Item_sum_udf_float(thd, this); } double Item_sum_udf_float::val() @@ -1513,7 +1522,7 @@ String *Item_sum_udf_float::val_str(String *str) Item *Item_sum_udf_int::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_udf_int(thd, *this); + return new (&thd->mem_root) Item_sum_udf_int(thd, this); } @@ -1549,7 +1558,7 @@ void Item_sum_udf_str::fix_length_and_dec() Item *Item_sum_udf_str::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_sum_udf_str(thd, *this); + return new (&thd->mem_root) Item_sum_udf_str(thd, this); } @@ -1772,6 +1781,31 @@ Item_func_group_concat::Item_func_group_concat(bool is_distinct, } +void Item_func_group_concat::cleanup() +{ + /* + Free table and tree if they belong to this item (if item have not pointer + to original item from which was made copy => it own its objects ) + */ + if (!original) + { + THD *thd= current_thd; + if (table) + { + free_tmp_table(thd, table); + table= 0; + } + delete tmp_table_param; + tmp_table_param= 0; + if (tree_mode) + { + tree_mode= 0; + delete_tree(tree); + } + } +} + + Item_func_group_concat::~Item_func_group_concat() { /* @@ -1787,18 +1821,13 @@ Item_func_group_concat::~Item_func_group_concat() sprintf(warn_buff, ER(ER_CUT_VALUE_GROUP_CONCAT), count_cut_values); warning->set_msg(thd, warn_buff); } - if (table) - free_tmp_table(thd, table); - delete tmp_table_param; - if (tree_mode) - delete_tree(tree); } } Item *Item_func_group_concat::copy_or_same(THD* thd) { - return new (&thd->mem_root) Item_func_group_concat(thd, *this); + return new (&thd->mem_root) Item_func_group_concat(thd, this); } |