diff options
author | Michael Widenius <monty@mariadb.org> | 2020-08-03 13:13:39 +0300 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2021-05-19 22:27:28 +0200 |
commit | 9448548481c590257f1523731fa81327db8db4ae (patch) | |
tree | 2c81f7c52c91b32816d127dbc9bd1fcd877d25c1 | |
parent | 3105c9e7a5eb3706f6520e1566ed4a2add06c6a5 (diff) | |
download | mariadb-git-9448548481c590257f1523731fa81327db8db4ae.tar.gz |
Remove calls to current_thd() in Item functions
- Added THD argument to functions that calls current_thd() or
new without a mem_root argument:
make_same(), set_comparator_func(), set_cmp_func(), set_cmp_func*(),
set_aggregator() and prepare_sum_aggregators()
- Changed "new Class" to "new (thd->mem_root) Class"
Almost all changes mechanical, no logic changes.
-rw-r--r-- | plugin/type_inet/sql_type_inet.cc | 4 | ||||
-rw-r--r-- | plugin/type_inet/sql_type_inet.h | 4 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 82 | ||||
-rw-r--r-- | sql/item_cmpfunc.h | 49 | ||||
-rw-r--r-- | sql/item_subselect.cc | 77 | ||||
-rw-r--r-- | sql/item_sum.cc | 37 | ||||
-rw-r--r-- | sql/item_sum.h | 4 | ||||
-rw-r--r-- | sql/opt_sum.cc | 3 | ||||
-rw-r--r-- | sql/sql_select.cc | 27 | ||||
-rw-r--r-- | sql/sql_type.cc | 40 | ||||
-rw-r--r-- | sql/sql_type.h | 18 | ||||
-rw-r--r-- | sql/sql_window.cc | 3 |
12 files changed, 184 insertions, 164 deletions
diff --git a/plugin/type_inet/sql_type_inet.cc b/plugin/type_inet/sql_type_inet.cc index ab251d660b3..58aa9ed6bde 100644 --- a/plugin/type_inet/sql_type_inet.cc +++ b/plugin/type_inet/sql_type_inet.cc @@ -601,9 +601,9 @@ public: DBUG_ASSERT(!tmp->m_null_value); return m_native.cmp(tmp->m_native); } - cmp_item *make_same() override + cmp_item *make_same(THD *thd) override { - return new cmp_item_inet6(); + return new (thd->mem_root) cmp_item_inet6(); } }; diff --git a/plugin/type_inet/sql_type_inet.h b/plugin/type_inet/sql_type_inet.h index 0f110314620..a00b2d35f18 100644 --- a/plugin/type_inet/sql_type_inet.h +++ b/plugin/type_inet/sql_type_inet.h @@ -697,9 +697,9 @@ public: DBUG_ASSERT(b.length() == Inet6::binary_length()); return memcmp(a.ptr(), b.ptr(), Inet6::binary_length()); } - bool set_comparator_func(Arg_comparator *cmp) const override + bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override { - return cmp->set_cmp_func_native(); + return cmp->set_cmp_func_native(thd); } bool Item_const_eq(const Item_const *a, const Item_const *b, bool binary_cmp) const override diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 97252b419e4..972ebb44054 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -355,8 +355,9 @@ static bool convert_const_to_int(THD *thd, Item_field *field_item, if (0 == field_cmp) { - Item *tmp= new (thd->mem_root) Item_int_with_ref(thd, field->val_int(), *item, - MY_TEST(field->flags & UNSIGNED_FLAG)); + Item *tmp= (new (thd->mem_root) + Item_int_with_ref(thd, field->val_int(), *item, + MY_TEST(field->flags & UNSIGNED_FLAG))); if (tmp) thd->change_item_tree(item, tmp); result= 1; // Item was replaced @@ -418,7 +419,7 @@ bool Item_func::setup_args_and_comparator(THD *thd, Arg_comparator *cmp) DBUG_ASSERT(functype() != LIKE_FUNC); convert_const_compared_to_int_field(thd); - return cmp->set_cmp_func(this, &args[0], &args[1], true); + return cmp->set_cmp_func(thd, this, &args[0], &args[1], true); } @@ -466,7 +467,7 @@ bool Item_bool_rowready_func2::fix_length_and_dec() items, holding the cached converted value of the original (constant) item. */ -int Arg_comparator::set_cmp_func(Item_func_or_sum *owner_arg, +int Arg_comparator::set_cmp_func(THD *thd, Item_func_or_sum *owner_arg, Item **a1, Item **a2) { owner= owner_arg; @@ -477,15 +478,15 @@ int Arg_comparator::set_cmp_func(Item_func_or_sum *owner_arg, Type_handler_hybrid_field_type tmp; if (tmp.aggregate_for_comparison(owner_arg->func_name(), tmp_args, 2, false)) { - DBUG_ASSERT(current_thd->is_error()); + DBUG_ASSERT(thd->is_error()); return 1; } m_compare_handler= tmp.type_handler(); - return m_compare_handler->set_comparator_func(this); + return m_compare_handler->set_comparator_func(thd, this); } -bool Arg_comparator::set_cmp_func_for_row_arguments() +bool Arg_comparator::set_cmp_func_for_row_arguments(THD *thd) { uint n= (*a)->cols(); if (n != (*b)->cols()) @@ -494,7 +495,7 @@ bool Arg_comparator::set_cmp_func_for_row_arguments() comparators= 0; return true; } - if (!(comparators= new Arg_comparator[n])) + if (!(comparators= new (thd->mem_root) Arg_comparator[n])) return true; for (uint i=0; i < n; i++) { @@ -503,25 +504,24 @@ bool Arg_comparator::set_cmp_func_for_row_arguments() my_error(ER_OPERAND_COLUMNS, MYF(0), (*a)->element_index(i)->cols()); return true; } - if (comparators[i].set_cmp_func(owner, (*a)->addr(i), - (*b)->addr(i), set_null)) + if (comparators[i].set_cmp_func(thd, owner, (*a)->addr(i), + (*b)->addr(i), set_null)) return true; } return false; } -bool Arg_comparator::set_cmp_func_row() +bool Arg_comparator::set_cmp_func_row(THD *thd) { func= is_owner_equal_func() ? &Arg_comparator::compare_e_row : &Arg_comparator::compare_row; - return set_cmp_func_for_row_arguments(); + return set_cmp_func_for_row_arguments(thd); } -bool Arg_comparator::set_cmp_func_string() +bool Arg_comparator::set_cmp_func_string(THD *thd) { - THD *thd= current_thd; func= is_owner_equal_func() ? &Arg_comparator::compare_e_string : &Arg_comparator::compare_string; if (compare_type() == STRING_RESULT && @@ -557,9 +557,8 @@ bool Arg_comparator::set_cmp_func_string() } -bool Arg_comparator::set_cmp_func_time() +bool Arg_comparator::set_cmp_func_time(THD *thd) { - THD *thd= current_thd; m_compare_collation= &my_charset_numeric; func= is_owner_equal_func() ? &Arg_comparator::compare_e_time : &Arg_comparator::compare_time; @@ -569,9 +568,8 @@ bool Arg_comparator::set_cmp_func_time() } -bool Arg_comparator::set_cmp_func_datetime() +bool Arg_comparator::set_cmp_func_datetime(THD *thd) { - THD *thd= current_thd; m_compare_collation= &my_charset_numeric; func= is_owner_equal_func() ? &Arg_comparator::compare_e_datetime : &Arg_comparator::compare_datetime; @@ -581,9 +579,8 @@ bool Arg_comparator::set_cmp_func_datetime() } -bool Arg_comparator::set_cmp_func_native() +bool Arg_comparator::set_cmp_func_native(THD *thd) { - THD *thd= current_thd; m_compare_collation= &my_charset_numeric; func= is_owner_equal_func() ? &Arg_comparator::compare_e_native : &Arg_comparator::compare_native; @@ -593,9 +590,8 @@ bool Arg_comparator::set_cmp_func_native() } -bool Arg_comparator::set_cmp_func_int() +bool Arg_comparator::set_cmp_func_int(THD *thd) { - THD *thd= current_thd; func= is_owner_equal_func() ? &Arg_comparator::compare_e_int : &Arg_comparator::compare_int_signed; if ((*a)->field_type() == MYSQL_TYPE_YEAR && @@ -624,7 +620,7 @@ bool Arg_comparator::set_cmp_func_int() } -bool Arg_comparator::set_cmp_func_real() +bool Arg_comparator::set_cmp_func_real(THD *thd) { if ((((*a)->result_type() == DECIMAL_RESULT && !(*a)->const_item() && (*b)->result_type() == STRING_RESULT && (*b)->const_item()) || @@ -639,10 +635,9 @@ bool Arg_comparator::set_cmp_func_real() Do comparison as decimal rather than float, in order not to lose precision. */ m_compare_handler= &type_handler_newdecimal; - return set_cmp_func_decimal(); + return set_cmp_func_decimal(thd); } - THD *thd= current_thd; func= is_owner_equal_func() ? &Arg_comparator::compare_e_real : &Arg_comparator::compare_real; if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC) @@ -658,9 +653,8 @@ bool Arg_comparator::set_cmp_func_real() return false; } -bool Arg_comparator::set_cmp_func_decimal() +bool Arg_comparator::set_cmp_func_decimal(THD *thd) { - THD *thd= current_thd; func= is_owner_equal_func() ? &Arg_comparator::compare_e_decimal : &Arg_comparator::compare_decimal; a= cache_converted_constant(thd, a, &a_cache, compare_type_handler()); @@ -4019,24 +4013,24 @@ bool Predicant_to_list_comparator::make_unique_cmp_items(THD *thd, } -cmp_item* cmp_item_sort_string::make_same() +cmp_item* cmp_item_sort_string::make_same(THD *thd) { - return new cmp_item_sort_string_in_static(cmp_charset); + return new (thd->mem_root) cmp_item_sort_string_in_static(cmp_charset); } -cmp_item* cmp_item_int::make_same() +cmp_item* cmp_item_int::make_same(THD *thd) { - return new cmp_item_int(); + return new (thd->mem_root) cmp_item_int(); } -cmp_item* cmp_item_real::make_same() +cmp_item* cmp_item_real::make_same(THD *thd) { - return new cmp_item_real(); + return new (thd->mem_root) cmp_item_real(); } -cmp_item* cmp_item_row::make_same() +cmp_item* cmp_item_row::make_same(THD *thd) { - return new cmp_item_row(); + return new (thd->mem_root) cmp_item_row(); } @@ -4100,7 +4094,7 @@ void cmp_item_row::store_value_by_template(THD *thd, cmp_item *t, Item *item) item->null_value= 0; for (uint i=0; i < n; i++) { - if (!(comparators[i]= tmpl->comparators[i]->make_same())) + if (!(comparators[i]= tmpl->comparators[i]->make_same(thd))) break; // new failed comparators[i]->store_value_by_template(thd, tmpl->comparators[i], item->element_index(i)); @@ -4184,9 +4178,9 @@ int cmp_item_decimal::compare(cmp_item *arg) } -cmp_item* cmp_item_decimal::make_same() +cmp_item* cmp_item_decimal::make_same(THD *thd) { - return new cmp_item_decimal(); + return new (thd->mem_root) cmp_item_decimal(); } @@ -4227,15 +4221,15 @@ int cmp_item_temporal::compare(cmp_item *ci) } -cmp_item *cmp_item_datetime::make_same() +cmp_item *cmp_item_datetime::make_same(THD *thd) { - return new cmp_item_datetime(); + return new (thd->mem_root) cmp_item_datetime(); } -cmp_item *cmp_item_time::make_same() +cmp_item *cmp_item_time::make_same(THD *thd) { - return new cmp_item_time(); + return new (thd->mem_root) cmp_item_time(); } @@ -4275,9 +4269,9 @@ int cmp_item_timestamp::compare(cmp_item *arg) } -cmp_item* cmp_item_timestamp::make_same() +cmp_item* cmp_item_timestamp::make_same(THD *thd) { - return new cmp_item_timestamp(); + return new (thd->mem_root) cmp_item_timestamp(); } diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 33838d9f92c..99f17077e3b 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -56,7 +56,8 @@ class Arg_comparator: public Sql_alloc Item *a_cache, *b_cache; // Cached values of a and b items // when one of arguments is NULL. - int set_cmp_func(Item_func_or_sum *owner_arg, Item **a1, Item **a2); + int set_cmp_func(THD *thd, Item_func_or_sum *owner_arg, + Item **a1, Item **a2); int compare_not_null_values(longlong val1, longlong val2) { @@ -83,21 +84,21 @@ public: a_cache(0), b_cache(0) {}; public: - bool set_cmp_func_for_row_arguments(); - bool set_cmp_func_row(); - bool set_cmp_func_string(); - bool set_cmp_func_time(); - bool set_cmp_func_datetime(); - bool set_cmp_func_native(); - bool set_cmp_func_int(); - bool set_cmp_func_real(); - bool set_cmp_func_decimal(); + bool set_cmp_func_for_row_arguments(THD *thd); + bool set_cmp_func_row(THD *thd); + bool set_cmp_func_string(THD *thd); + bool set_cmp_func_time(THD *thd); + bool set_cmp_func_datetime(THD *thd); + bool set_cmp_func_native(THD *thd); + bool set_cmp_func_int(THD *thd); + bool set_cmp_func_real(THD *thd); + bool set_cmp_func_decimal(THD *thd); - inline int set_cmp_func(Item_func_or_sum *owner_arg, + inline int set_cmp_func(THD *thd, Item_func_or_sum *owner_arg, Item **a1, Item **a2, bool set_null_arg) { set_null= set_null_arg; - return set_cmp_func(owner_arg, a1, a2); + return set_cmp_func(thd, owner_arg, a1, a2); } inline int compare() { return (this->*func)(); } @@ -538,9 +539,9 @@ public: return this; } bool fix_length_and_dec(); - int set_cmp_func() + int set_cmp_func(THD *thd) { - return cmp.set_cmp_func(this, tmp_arg, tmp_arg + 1, true); + return cmp.set_cmp_func(thd, this, tmp_arg, tmp_arg + 1, true); } CHARSET_INFO *compare_collation() const { return cmp.compare_collation(); } const Type_handler *compare_type_handler() const @@ -1560,7 +1561,7 @@ public: virtual int cmp_not_null(const Value *value)= 0; // for optimized IN with row virtual int compare(cmp_item *item)= 0; - virtual cmp_item *make_same()= 0; + virtual cmp_item *make_same(THD *thd)= 0; virtual void store_value_by_template(THD *thd, cmp_item *tmpl, Item *item) { store_value(item); @@ -1633,7 +1634,7 @@ public: cmp_item_string *l_cmp= (cmp_item_string *) ci; return sortcmp(value_res, l_cmp->value_res, cmp_charset); } - cmp_item *make_same(); + cmp_item *make_same(THD *thd); void set_charset(CHARSET_INFO *cs) { cmp_charset= cs; @@ -1667,7 +1668,7 @@ public: cmp_item_int *l_cmp= (cmp_item_int *)ci; return (value < l_cmp->value) ? -1 : ((value == l_cmp->value) ? 0 : 1); } - cmp_item *make_same(); + cmp_item *make_same(THD *thd); }; /* @@ -1696,7 +1697,7 @@ public: } int cmp_not_null(const Value *val); int cmp(Item *arg); - cmp_item *make_same(); + cmp_item *make_same(THD *thd); }; @@ -1713,7 +1714,7 @@ public: } int cmp_not_null(const Value *val); int cmp(Item *arg); - cmp_item *make_same(); + cmp_item *make_same(THD *thd); }; @@ -1726,7 +1727,7 @@ public: int cmp_not_null(const Value *val); int cmp(Item *arg); int compare(cmp_item *ci); - cmp_item *make_same(); + cmp_item *make_same(THD *thd); }; @@ -1756,7 +1757,7 @@ public: cmp_item_real *l_cmp= (cmp_item_real *) ci; return (value < l_cmp->value)? -1 : ((value == l_cmp->value) ? 0 : 1); } - cmp_item *make_same(); + cmp_item *make_same(THD *thd); }; @@ -1769,7 +1770,7 @@ public: int cmp(Item *arg); int cmp_not_null(const Value *val); int compare(cmp_item *c); - cmp_item *make_same(); + cmp_item *make_same(THD *thd); }; @@ -1806,7 +1807,7 @@ public: cmp_item_string *l_cmp= (cmp_item_string *) ci; return sortcmp(value_res, l_cmp->value_res, cmp_charset); } - cmp_item *make_same() + cmp_item *make_same(THD *thd) { return new cmp_item_sort_string_in_static(cmp_charset); } @@ -2515,7 +2516,7 @@ public: return TRUE; } int compare(cmp_item *arg); - cmp_item *make_same(); + cmp_item *make_same(THD *thd); void store_value_by_template(THD *thd, cmp_item *tmpl, Item *); friend class Item_func_in; cmp_item *get_comparator(uint i) { return comparators[i]; } diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 58e9a5acd7b..d64f93e917c 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -118,6 +118,7 @@ void Item_subselect::init(st_select_lex *select_lex, else { SELECT_LEX *outer_select= unit->outer_select(); + THD *thd= unit->thd; /* do not take into account expression inside aggregate functions because they can access original table fields @@ -127,9 +128,11 @@ void Item_subselect::init(st_select_lex *select_lex, outer_select->parsing_place); if (unit->is_unit_op() && (unit->first_select()->next_select() || unit->fake_select_lex)) - engine= new subselect_union_engine(unit, result, this); + engine= new (thd->mem_root) + subselect_union_engine(unit, result, this); else - engine= new subselect_single_select_engine(select_lex, result, this); + engine= new (thd->mem_root) + subselect_single_select_engine(select_lex, result, this); } DBUG_PRINT("info", ("engine: %p", engine)); DBUG_VOID_RETURN; @@ -3318,7 +3321,7 @@ bool Item_exists_subselect::exists2in_processor(void *opt_arg) } else { - List<Item> *and_list= new List<Item>; + List<Item> *and_list= new (thd->mem_root) List<Item>; if (!and_list) { res= TRUE; @@ -3598,7 +3601,8 @@ bool Item_in_subselect::setup_mat_engine() select_engine= (subselect_single_select_engine*) engine; /* Create/initialize execution objects. */ - if (!(mat_engine= new subselect_hash_sj_engine(thd, this, select_engine))) + if (!(mat_engine= new (thd->mem_root) + subselect_hash_sj_engine(thd, this, select_engine))) DBUG_RETURN(TRUE); if (mat_engine->prepare(thd) || @@ -3636,7 +3640,7 @@ bool Item_in_subselect::init_left_expr_cache() if (!outer_join || !outer_join->table_count || !outer_join->tables_list) return TRUE; - if (!(left_expr_cache= new List<Cached_item>)) + if (!(left_expr_cache= new (thd->mem_root) List<Cached_item>)) return TRUE; for (uint i= 0; i < left_expr->cols(); i++) @@ -3867,8 +3871,9 @@ int subselect_single_select_engine::prepare(THD *thd) { select_lex->cleanup(); } - join= new JOIN(thd, select_lex->item_list, - select_lex->options | SELECT_NO_UNLOCK, result); + join= (new (thd->mem_root) + JOIN(thd, select_lex->item_list, + select_lex->options | SELECT_NO_UNLOCK, result)); if (!join || !result) return 1; /* Fatal error is set already. */ prepared= 1; @@ -5280,7 +5285,7 @@ bool subselect_hash_sj_engine::make_semi_join_conds() tmp_table_ref->init_one_table(&empty_clex_str, &table_name, NULL, TL_READ); tmp_table_ref->table= tmp_table; - context= new Name_resolution_context; + context= new (thd->mem_root) Name_resolution_context; context->init(); context->first_name_resolution_table= context->last_name_resolution_table= tmp_table_ref; @@ -5348,8 +5353,9 @@ subselect_hash_sj_engine::make_unique_engine() tab->preread_init_done= FALSE; tab->ref.tmp_table_index_lookup_init(thd, tmp_key, it, FALSE); - DBUG_RETURN(new subselect_uniquesubquery_engine(thd, tab, item_in, - semi_join_conds)); + DBUG_RETURN(new (thd->mem_root) + subselect_uniquesubquery_engine(thd, tab, item_in, + semi_join_conds)); } @@ -5745,14 +5751,15 @@ int subselect_hash_sj_engine::exec() if (strategy == PARTIAL_MATCH_MERGE) { pm_engine= - new subselect_rowid_merge_engine((subselect_uniquesubquery_engine*) - lookup_engine, tmp_table, - count_pm_keys, - has_covering_null_row, - has_covering_null_columns, - count_columns_with_nulls, - item, result, - semi_join_conds->argument_list()); + (new (thd->mem_root) + subselect_rowid_merge_engine((subselect_uniquesubquery_engine*) + lookup_engine, tmp_table, + count_pm_keys, + has_covering_null_row, + has_covering_null_columns, + count_columns_with_nulls, + item, result, + semi_join_conds->argument_list())); if (!pm_engine || pm_engine->prepare(thd) || ((subselect_rowid_merge_engine*) pm_engine)-> @@ -5772,13 +5779,14 @@ int subselect_hash_sj_engine::exec() if (strategy == PARTIAL_MATCH_SCAN) { if (!(pm_engine= - new subselect_table_scan_engine((subselect_uniquesubquery_engine*) - lookup_engine, tmp_table, - item, result, - semi_join_conds->argument_list(), - has_covering_null_row, - has_covering_null_columns, - count_columns_with_nulls)) || + (new (thd->mem_root) + subselect_table_scan_engine((subselect_uniquesubquery_engine*) + lookup_engine, tmp_table, + item, result, + semi_join_conds->argument_list(), + has_covering_null_row, + has_covering_null_columns, + count_columns_with_nulls))) || pm_engine->prepare(thd)) { /* This is an irrecoverable error. */ @@ -6409,8 +6417,9 @@ subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts, /* Create the only non-NULL key if there is any. */ if (non_null_key_parts) { - non_null_key= new Ordered_key(cur_keyid, tmp_table, left, - 0, 0, 0, row_num_to_rowid); + non_null_key= (new (thd->mem_root) + Ordered_key(cur_keyid, tmp_table, left, + 0, 0, 0, row_num_to_rowid)); if (non_null_key->init(non_null_key_parts)) return TRUE; merge_keys[cur_keyid]= non_null_key; @@ -6439,13 +6448,13 @@ subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts, result_sink->get_null_count_of_col(i) == row_count) continue; - merge_keys[cur_keyid]= new Ordered_key( - cur_keyid, tmp_table, - left->element_index(i), - result_sink->get_null_count_of_col(i), - result_sink->get_min_null_of_col(i), - result_sink->get_max_null_of_col(i), - row_num_to_rowid); + merge_keys[cur_keyid]= new (thd->mem_root) + Ordered_key(cur_keyid, tmp_table, + left->element_index(i), + result_sink->get_null_count_of_col(i), + result_sink->get_min_null_of_col(i), + result_sink->get_max_null_of_col(i), + row_num_to_rowid); if (merge_keys[cur_keyid]->init(i)) return TRUE; merge_keys[cur_keyid]->first(); diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 6acf7bb234b..e86327e22e5 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -478,7 +478,7 @@ Item_sum::Item_sum(THD *thd, Item_sum *item): init_aggregator(); with_distinct= item->with_distinct; if (item->aggr) - set_aggregator(item->aggr->Aggrtype()); + set_aggregator(thd, item->aggr->Aggrtype()); } @@ -579,7 +579,7 @@ Item *Item_sum::set_arg(uint i, THD *thd, Item *new_val) } -int Item_sum::set_aggregator(Aggregator::Aggregator_type aggregator) +int Item_sum::set_aggregator(THD *thd, Aggregator::Aggregator_type aggregator) { /* Dependent subselects may be executed multiple times, making @@ -600,10 +600,10 @@ int Item_sum::set_aggregator(Aggregator::Aggregator_type aggregator) switch (aggregator) { case Aggregator::DISTINCT_AGGREGATOR: - aggr= new Aggregator_distinct(this); + aggr= new (thd->mem_root) Aggregator_distinct(this); break; case Aggregator::SIMPLE_AGGREGATOR: - aggr= new Aggregator_simple(this); + aggr= new (thd->mem_root) Aggregator_simple(this); break; }; return aggr ? FALSE : TRUE; @@ -763,7 +763,7 @@ bool Aggregator_distinct::setup(THD *thd) List<Item> list; SELECT_LEX *select_lex= thd->lex->current_select; - if (!(tmp_table_param= new TMP_TABLE_PARAM)) + if (!(tmp_table_param= new (thd->mem_root) TMP_TABLE_PARAM)) return TRUE; /* Create a table with an unique key over all parameters */ @@ -863,8 +863,9 @@ bool Aggregator_distinct::setup(THD *thd) } } DBUG_ASSERT(tree == 0); - tree= new Unique(compare_key, cmp_arg, tree_key_length, - item_sum->ram_limitation(thd)); + tree= (new (thd->mem_root) + Unique(compare_key, cmp_arg, tree_key_length, + item_sum->ram_limitation(thd))); /* The only time tree_key_length could be 0 is if someone does count(distinct) on a char(0) field - stupid thing to do, @@ -921,8 +922,9 @@ bool Aggregator_distinct::setup(THD *thd) simple_raw_key_cmp because the table contains numbers only; decimals are converted to binary representation as well. */ - tree= new Unique(simple_raw_key_cmp, &tree_key_length, tree_key_length, - item_sum->ram_limitation(thd)); + tree= (new (thd->mem_root) + Unique(simple_raw_key_cmp, &tree_key_length, tree_key_length, + item_sum->ram_limitation(thd))); DBUG_RETURN(tree == 0); } @@ -1278,9 +1280,9 @@ void Item_sum_min_max::setup_hybrid(THD *thd, Item *item, Item *value_arg) /* Don't cache value, as it will change */ if (!item->const_item()) arg_cache->set_used_tables(RAND_TABLE_BIT); - cmp= new Arg_comparator(); + cmp= new (thd->mem_root) Arg_comparator(); if (cmp) - cmp->set_cmp_func(this, (Item**)&arg_cache, (Item**)&value, FALSE); + cmp->set_cmp_func(thd, this, (Item**)&arg_cache, (Item**)&value, FALSE); DBUG_VOID_RETURN; } @@ -4292,7 +4294,7 @@ bool Item_func_group_concat::setup(THD *thd) if (table || tree) DBUG_RETURN(FALSE); - if (!(tmp_table_param= new TMP_TABLE_PARAM)) + if (!(tmp_table_param= new (thd->mem_root) TMP_TABLE_PARAM)) DBUG_RETURN(TRUE); /* Push all not constant fields to the list and create a temp table */ @@ -4381,7 +4383,7 @@ bool Item_func_group_concat::setup(THD *thd) with ORDER BY | DISTINCT and BLOB field count > 0. */ if (order_or_distinct && table->s->blob_fields) - table->blob_storage= new Blob_mem_storage(); + table->blob_storage= new (thd->mem_root) Blob_mem_storage(); /* Need sorting or uniqueness: init tree and choose a function to sort. @@ -4407,10 +4409,11 @@ bool Item_func_group_concat::setup(THD *thd) } if (distinct) - unique_filter= new Unique(get_comparator_function_for_distinct(), - (void*)this, - tree_key_length + get_null_bytes(), - ram_limitation(thd)); + unique_filter= (new (thd->mem_root) + Unique(get_comparator_function_for_distinct(), + (void*)this, + tree_key_length + get_null_bytes(), + ram_limitation(thd))); if ((row_limit && row_limit->cmp_type() != INT_RESULT) || (offset_limit && offset_limit->cmp_type() != INT_RESULT)) { diff --git a/sql/item_sum.h b/sql/item_sum.h index 9c9ee34037d..02da520048b 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -512,7 +512,7 @@ public: */ virtual void no_rows_in_result() { - set_aggregator(with_distinct ? + set_aggregator(current_thd, with_distinct ? Aggregator::DISTINCT_AGGREGATOR : Aggregator::SIMPLE_AGGREGATOR); aggregator_clear(); @@ -576,7 +576,7 @@ public: May be called multiple times. */ - int set_aggregator(Aggregator::Aggregator_type aggregator); + int set_aggregator(THD *thd, Aggregator::Aggregator_type aggregator); virtual void clear()= 0; virtual bool add()= 0; diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index edefbc83787..b3871254e6e 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -448,7 +448,8 @@ int opt_sum_query(THD *thd, const_result= 0; break; } - item_sum->set_aggregator(item_sum->has_with_distinct() ? + item_sum->set_aggregator(thd, + item_sum->has_with_distinct() ? Aggregator::DISTINCT_AGGREGATOR : Aggregator::SIMPLE_AGGREGATOR); /* diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 48f18ecd64f..fa20e2a8d0d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -277,7 +277,8 @@ static void update_tmptable_sum_func(Item_sum **func,TABLE *tmp_table); static void copy_sum_funcs(Item_sum **func_ptr, Item_sum **end); static bool add_ref_to_table_cond(THD *thd, JOIN_TAB *join_tab); static bool setup_sum_funcs(THD *thd, Item_sum **func_ptr); -static bool prepare_sum_aggregators(Item_sum **func_ptr, bool need_distinct); +static bool prepare_sum_aggregators(THD *thd, Item_sum **func_ptr, + bool need_distinct); static bool init_sum_functions(Item_sum **func, Item_sum **end); static bool update_sum_func(Item_sum **func); static void select_describe(JOIN *join, bool need_tmp_table,bool need_order, @@ -3605,7 +3606,7 @@ bool JOIN::make_aggr_tables_info() { if (make_sum_func_list(*curr_all_fields, *curr_fields_list, true, true)) DBUG_RETURN(true); - if (prepare_sum_aggregators(sum_funcs, + if (prepare_sum_aggregators(thd, sum_funcs, !join_tab->is_using_agg_loose_index_scan())) DBUG_RETURN(true); group_list= NULL; @@ -3715,7 +3716,7 @@ bool JOIN::make_aggr_tables_info() } if (make_sum_func_list(*curr_all_fields, *curr_fields_list, true, true)) DBUG_RETURN(true); - if (prepare_sum_aggregators(sum_funcs, + if (prepare_sum_aggregators(thd, sum_funcs, !join_tab || !join_tab-> is_using_agg_loose_index_scan())) DBUG_RETURN(true); @@ -3920,7 +3921,7 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields, goto err; if (make_sum_func_list(all_fields, fields_list, true)) goto err; - if (prepare_sum_aggregators(sum_funcs, + if (prepare_sum_aggregators(thd, sum_funcs, !(tables_list && join_tab->is_using_agg_loose_index_scan()))) goto err; @@ -3932,7 +3933,7 @@ JOIN::create_postjoin_aggr_table(JOIN_TAB *tab, List<Item> *table_fields, { if (make_sum_func_list(all_fields, fields_list, false)) goto err; - if (prepare_sum_aggregators(sum_funcs, + if (prepare_sum_aggregators(thd, sum_funcs, !join_tab->is_using_agg_loose_index_scan())) goto err; if (setup_sum_funcs(thd, sum_funcs)) @@ -15134,7 +15135,7 @@ static bool check_row_equality(THD *thd, const Arg_comparator *comparators, { Item_func_eq *eq_item; if (!(eq_item= new (thd->mem_root) Item_func_eq(thd, left_item, right_item)) || - eq_item->set_cmp_func()) + eq_item->set_cmp_func(thd)) return FALSE; eq_item->quick_fix_field(); eq_list->push_back(eq_item, thd->mem_root); @@ -15894,7 +15895,7 @@ Item *eliminate_item_equal(THD *thd, COND *cond, COND_EQUAL *upper_levels, Don't produce equality if const is equal to item_const. */ Item_func_eq *func= new (thd->mem_root) Item_func_eq(thd, item_const, upper_const); - func->set_cmp_func(); + func->set_cmp_func(thd); func->quick_fix_field(); if (func->val_int()) item= 0; @@ -15942,7 +15943,7 @@ Item *eliminate_item_equal(THD *thd, COND *cond, COND_EQUAL *upper_levels, field_item->remove_item_direct_ref(), head_item->remove_item_direct_ref()); - if (!eq_item || eq_item->set_cmp_func()) + if (!eq_item || eq_item->set_cmp_func(thd)) return 0; eq_item->quick_fix_field(); } @@ -16360,7 +16361,7 @@ change_cond_ref_to_const(THD *thd, I_List<COND_CMP> *save_list, So make sure to use set_cmp_func() only for non-LIKE operators. */ if (functype != Item_func::LIKE_FUNC) - ((Item_bool_rowready_func2*) func)->set_cmp_func(); + ((Item_bool_rowready_func2*) func)->set_cmp_func(thd); } } else if (can_change_cond_ref_to_const(func, left_item, right_item, @@ -16385,7 +16386,7 @@ change_cond_ref_to_const(THD *thd, I_List<COND_CMP> *save_list, save_list->push_back(tmp2); } if (functype != Item_func::LIKE_FUNC) - ((Item_bool_rowready_func2*) func)->set_cmp_func(); + ((Item_bool_rowready_func2*) func)->set_cmp_func(thd); } } } @@ -25915,13 +25916,15 @@ static bool setup_sum_funcs(THD *thd, Item_sum **func_ptr) } -static bool prepare_sum_aggregators(Item_sum **func_ptr, bool need_distinct) +static bool prepare_sum_aggregators(THD *thd,Item_sum **func_ptr, + bool need_distinct) { Item_sum *func; DBUG_ENTER("prepare_sum_aggregators"); while ((func= *(func_ptr++))) { - if (func->set_aggregator(need_distinct && func->has_with_distinct() ? + if (func->set_aggregator(thd, + need_distinct && func->has_with_distinct() ? Aggregator::DISTINCT_AGGREGATOR : Aggregator::SIMPLE_AGGREGATOR)) DBUG_RETURN(TRUE); diff --git a/sql/sql_type.cc b/sql/sql_type.cc index b2128d1dfce..7c60bf09ae9 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -4347,46 +4347,54 @@ int Type_handler_int_result::Item_save_in_field(Item *item, Field *field, /***********************************************************************/ -bool Type_handler_row::set_comparator_func(Arg_comparator *cmp) const +bool Type_handler_row:: +set_comparator_func(THD *thd, Arg_comparator *cmp) const { - return cmp->set_cmp_func_row(); + return cmp->set_cmp_func_row(thd); } -bool Type_handler_int_result::set_comparator_func(Arg_comparator *cmp) const +bool Type_handler_int_result:: +set_comparator_func(THD *thd, Arg_comparator *cmp) const { - return cmp->set_cmp_func_int(); + return cmp->set_cmp_func_int(thd); } -bool Type_handler_real_result::set_comparator_func(Arg_comparator *cmp) const +bool Type_handler_real_result:: +set_comparator_func(THD *thd, Arg_comparator *cmp) const { - return cmp->set_cmp_func_real(); + return cmp->set_cmp_func_real(thd); } -bool Type_handler_decimal_result::set_comparator_func(Arg_comparator *cmp) const +bool Type_handler_decimal_result:: +set_comparator_func(THD *thd, Arg_comparator *cmp) const { - return cmp->set_cmp_func_decimal(); + return cmp->set_cmp_func_decimal(thd); } -bool Type_handler_string_result::set_comparator_func(Arg_comparator *cmp) const +bool Type_handler_string_result:: +set_comparator_func(THD *thd, Arg_comparator *cmp) const { - return cmp->set_cmp_func_string(); + return cmp->set_cmp_func_string(thd); } -bool Type_handler_time_common::set_comparator_func(Arg_comparator *cmp) const +bool Type_handler_time_common:: +set_comparator_func(THD *thd, Arg_comparator *cmp) const { - return cmp->set_cmp_func_time(); + return cmp->set_cmp_func_time(thd); } bool -Type_handler_temporal_with_date::set_comparator_func(Arg_comparator *cmp) const +Type_handler_temporal_with_date:: +set_comparator_func(THD *thd, Arg_comparator *cmp) const { - return cmp->set_cmp_func_datetime(); + return cmp->set_cmp_func_datetime(thd); } bool -Type_handler_timestamp_common::set_comparator_func(Arg_comparator *cmp) const +Type_handler_timestamp_common:: +set_comparator_func(THD *thd, Arg_comparator *cmp) const { - return cmp->set_cmp_func_native(); + return cmp->set_cmp_func_native(thd); } diff --git a/sql/sql_type.h b/sql/sql_type.h index 6cd462430f9..bf2c92b3f50 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -4181,7 +4181,7 @@ public: DBUG_ASSERT(0); return 0; } - virtual bool set_comparator_func(Arg_comparator *cmp) const= 0; + virtual bool set_comparator_func(THD *thd, Arg_comparator *cmp) const= 0; virtual bool Item_const_eq(const Item_const *a, const Item_const *b, bool binary_cmp) const { @@ -4521,7 +4521,7 @@ public: DBUG_ASSERT(0); return NULL; } - bool set_comparator_func(Arg_comparator *cmp) const override; + bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override; bool Item_hybrid_func_fix_attributes(THD *thd, const char *name, Type_handler_hybrid_field_type *, @@ -4818,7 +4818,7 @@ public: const override; Item *make_const_item_for_comparison(THD *, Item *src, const Item *cmp) const override; - bool set_comparator_func(Arg_comparator *cmp) const override; + bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override; bool Item_hybrid_func_fix_attributes(THD *thd, const char *name, Type_handler_hybrid_field_type *, @@ -4954,7 +4954,7 @@ public: Item *make_const_item_for_comparison(THD *, Item *src, const Item *cmp) const override; Item_cache *Item_get_cache(THD *thd, const Item *item) const override; - bool set_comparator_func(Arg_comparator *cmp) const override; + bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override; bool Item_hybrid_func_fix_attributes(THD *thd, const char *name, Type_handler_hybrid_field_type *, @@ -5188,7 +5188,7 @@ public: int Item_save_in_field(Item *item, Field *field, bool no_conversions) const override; Item *make_const_item_for_comparison(THD *, Item *src, const Item *cmp) const override; Item_cache *Item_get_cache(THD *thd, const Item *item) const override; - bool set_comparator_func(Arg_comparator *cmp) const override; + bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override; bool Item_hybrid_func_fix_attributes(THD *thd, const char *name, Type_handler_hybrid_field_type *, @@ -5452,7 +5452,7 @@ public: Item *make_const_item_for_comparison(THD *, Item *src, const Item *cmp) const override; Item_cache *Item_get_cache(THD *thd, const Item *item) const override; - bool set_comparator_func(Arg_comparator *cmp) const override; + bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override; bool Item_hybrid_func_fix_attributes(THD *thd, const char *name, Type_handler_hybrid_field_type *, @@ -6168,7 +6168,7 @@ public: bool Item_func_int_val_fix_length_and_dec(Item_func_int_val*) const override; Item *make_const_item_for_comparison(THD *, Item *src, const Item *cmp) const override; - bool set_comparator_func(Arg_comparator *cmp) const override; + bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override; cmp_item *make_cmp_item(THD *thd, CHARSET_INFO *cs) const override; in_vector *make_in_vector(THD *, const Item_func_in *, uint nargs) const override; @@ -6262,7 +6262,7 @@ public: const override; Item *make_const_item_for_comparison(THD *, Item *src, const Item *cmp) const override; - bool set_comparator_func(Arg_comparator *cmp) const override; + bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override; cmp_item *make_cmp_item(THD *thd, CHARSET_INFO *cs) const override; in_vector *make_in_vector(THD *, const Item_func_in *, uint nargs) const override; @@ -6632,7 +6632,7 @@ public: longlong Item_func_min_max_val_int(Item_func_min_max *) const override; my_decimal *Item_func_min_max_val_decimal(Item_func_min_max *, my_decimal *) const override; - bool set_comparator_func(Arg_comparator *cmp) const override; + bool set_comparator_func(THD *thd, Arg_comparator *cmp) const override; bool Item_hybrid_func_fix_attributes(THD *thd, const char *name, Type_handler_hybrid_field_type *, diff --git a/sql/sql_window.cc b/sql/sql_window.cc index 621a4b24227..ce0462f1bb0 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -2964,7 +2964,8 @@ bool Window_func_runner::exec(THD *thd, TABLE *tbl, SORT_INFO *filesort_result) win_func->set_phase_to_computation(); // TODO(cvicentiu) Setting the aggregator should probably be done during // setup of Window_funcs_sort. - win_func->window_func()->set_aggregator(Aggregator::SIMPLE_AGGREGATOR); + win_func->window_func()->set_aggregator(thd, + Aggregator::SIMPLE_AGGREGATOR); } it.rewind(); |