diff options
Diffstat (limited to 'sql')
36 files changed, 225 insertions, 144 deletions
diff --git a/sql/compat56.cc b/sql/compat56.cc index 6cbf4a66ac8..f2be7da8934 100644 --- a/sql/compat56.cc +++ b/sql/compat56.cc @@ -45,8 +45,10 @@ */ longlong TIME_to_longlong_time_packed(const MYSQL_TIME *ltime) { - /* If month is 0, we mix day with hours: "1 00:10:10" -> "24:00:10" */ - long hms= (((ltime->month ? 0 : ltime->day * 24) + ltime->hour) << 12) | + DBUG_ASSERT(ltime->year == 0); + DBUG_ASSERT(ltime->month == 0); + // Mix days with hours: "1 00:10:10" -> "24:00:10" + long hms= ((ltime->day * 24 + ltime->hour) << 12) | (ltime->minute << 6) | ltime->second; longlong tmp= MY_PACKED_TIME_MAKE(hms, ltime->second_part); return ltime->neg ? -tmp : tmp; diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index 66c07574cab..59aa6bcabc6 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -209,7 +209,7 @@ Event_basic::Event_basic() { DBUG_ENTER("Event_basic::Event_basic"); /* init memory root */ - init_sql_alloc(&mem_root, 256, 512, MYF(0)); + init_sql_alloc(&mem_root, "Event_basic", 256, 512, MYF(0)); dbname.str= name.str= NULL; dbname.length= name.length= 0; time_zone= NULL; diff --git a/sql/field.cc b/sql/field.cc index 4accd26127e..bba6d9ee1e5 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -2239,7 +2239,7 @@ bool Field::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate) Needs to be changed if/when we want to support different time formats. */ -int Field::store_time_dec(MYSQL_TIME *ltime, uint dec) +int Field::store_time_dec(const MYSQL_TIME *ltime, uint dec) { ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED; char buff[MAX_DATE_STRING_REP_LENGTH]; @@ -3288,7 +3288,7 @@ int Field_new_decimal::store_decimal(const my_decimal *decimal_value) } -int Field_new_decimal::store_time_dec(MYSQL_TIME *ltime, uint dec_arg) +int Field_new_decimal::store_time_dec(const MYSQL_TIME *ltime, uint dec_arg) { my_decimal decimal_value; return store_value(date2my_decimal(ltime, &decimal_value)); @@ -3527,7 +3527,7 @@ Item *Field_new_decimal::get_equal_const_item(THD *thd, const Context &ctx, } -int Field_num::store_time_dec(MYSQL_TIME *ltime, uint dec_arg) +int Field_num::store_time_dec(const MYSQL_TIME *ltime, uint dec_arg) { longlong v= TIME_to_ulonglong(ltime); if (ltime->neg == 0) @@ -4801,7 +4801,7 @@ int Field_real::store_decimal(const my_decimal *dm) return store(dbl); } -int Field_real::store_time_dec(MYSQL_TIME *ltime, uint dec_arg) +int Field_real::store_time_dec(const MYSQL_TIME *ltime, uint dec_arg) { return store(TIME_to_double(ltime)); } @@ -5083,7 +5083,7 @@ copy_or_convert_to_datetime(THD *thd, const MYSQL_TIME *from, MYSQL_TIME *to) } -int Field_timestamp::store_time_dec(MYSQL_TIME *ltime, uint dec) +int Field_timestamp::store_time_dec(const MYSQL_TIME *ltime, uint dec) { int unused; ErrConvTime str(ltime); @@ -5640,7 +5640,7 @@ int Field_temporal_with_date::store(longlong nr, bool unsigned_val) } -int Field_temporal_with_date::store_time_dec(MYSQL_TIME *ltime, uint dec) +int Field_temporal_with_date::store_time_dec(const MYSQL_TIME *ltime, uint dec) { int error= 0, have_smth_to_conv= 1; ErrConvTime str(ltime); @@ -5757,34 +5757,38 @@ int Field_time::store_TIME_with_warning(MYSQL_TIME *ltime, int was_cut, int have_smth_to_conv) { - Sql_condition::enum_warning_level trunc_level= Sql_condition::WARN_LEVEL_WARN; - int ret= 2; ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED; if (!have_smth_to_conv) { bzero(ltime, sizeof(*ltime)); - was_cut= MYSQL_TIME_WARN_TRUNCATED; - ret= 1; + store_TIME(ltime); + set_warnings(Sql_condition::WARN_LEVEL_WARN, str, MYSQL_TIME_WARN_TRUNCATED); + return 1; } - else if (!MYSQL_TIME_WARN_HAVE_WARNINGS(was_cut) && - ((ltime->year || ltime->month) || - MYSQL_TIME_WARN_HAVE_NOTES(was_cut))) + if (ltime->year != 0 || ltime->month != 0) { - if (ltime->year || ltime->month) - ltime->year= ltime->month= ltime->day= 0; - trunc_level= Sql_condition::WARN_LEVEL_NOTE; - was_cut|= MYSQL_TIME_WARN_TRUNCATED; - ret= 3; + ltime->year= ltime->month= ltime->day= 0; + was_cut|= MYSQL_TIME_NOTE_TRUNCATED; } - set_warnings(trunc_level, str, was_cut, MYSQL_TIMESTAMP_TIME); + my_time_trunc(ltime, decimals()); store_TIME(ltime); - return was_cut ? ret : 0; + if (!MYSQL_TIME_WARN_HAVE_WARNINGS(was_cut) && + MYSQL_TIME_WARN_HAVE_NOTES(was_cut)) + { + set_warnings(Sql_condition::WARN_LEVEL_NOTE, str, + was_cut | MYSQL_TIME_WARN_TRUNCATED); + return 3; + } + set_warnings(Sql_condition::WARN_LEVEL_WARN, str, was_cut); + return was_cut ? 2 : 0; } -void Field_time::store_TIME(MYSQL_TIME *ltime) +void Field_time::store_TIME(const MYSQL_TIME *ltime) { + DBUG_ASSERT(ltime->year == 0); + DBUG_ASSERT(ltime->month == 0); long tmp= (ltime->day*24L+ltime->hour)*10000L + (ltime->minute*100+ltime->second); if (ltime->neg) @@ -5832,7 +5836,7 @@ static void calc_datetime_days_diff(MYSQL_TIME *ltime, long days) } -int Field_time::store_time_dec(MYSQL_TIME *ltime, uint dec) +int Field_time::store_time_dec(const MYSQL_TIME *ltime, uint dec) { MYSQL_TIME l_time= *ltime; ErrConvTime str(ltime); @@ -6018,8 +6022,10 @@ int Field_time_hires::reset() } -void Field_time_hires::store_TIME(MYSQL_TIME *ltime) +void Field_time_hires::store_TIME(const MYSQL_TIME *ltime) { + DBUG_ASSERT(ltime->year == 0); + DBUG_ASSERT(ltime->month == 0); ulonglong packed= sec_part_shift(pack_time(ltime), dec) + zero_point; store_bigendian(packed, ptr, Field_time_hires::pack_length()); } @@ -6201,9 +6207,8 @@ int Field_timef::reset() return 0; } -void Field_timef::store_TIME(MYSQL_TIME *ltime) +void Field_timef::store_TIME(const MYSQL_TIME *ltime) { - my_time_trunc(ltime, decimals()); longlong tmp= TIME_to_longlong_time_packed(ltime); my_time_packed_to_binary(tmp, ptr, dec); } @@ -6292,7 +6297,7 @@ int Field_year::store(longlong nr, bool unsigned_val) } -int Field_year::store_time_dec(MYSQL_TIME *ltime, uint dec_arg) +int Field_year::store_time_dec(const MYSQL_TIME *ltime, uint dec_arg) { ErrConvTime str(ltime); if (Field_year::store(ltime->year, 0)) diff --git a/sql/field.h b/sql/field.h index 43b3aab1ff4..d2274aaf7e8 100644 --- a/sql/field.h +++ b/sql/field.h @@ -829,9 +829,9 @@ public: virtual int store(double nr)=0; virtual int store(longlong nr, bool unsigned_val)=0; virtual int store_decimal(const my_decimal *d)=0; - virtual int store_time_dec(MYSQL_TIME *ltime, uint dec); + virtual int store_time_dec(const MYSQL_TIME *ltime, uint dec); virtual int store_timestamp(my_time_t timestamp, ulong sec_part); - int store_time(MYSQL_TIME *ltime) + int store_time(const MYSQL_TIME *ltime) { return store_time_dec(ltime, TIME_SECOND_PART_DIGITS); } int store(const char *to, uint length, CHARSET_INFO *cs, enum_check_fields check_level); @@ -1711,7 +1711,7 @@ public: field_metadata, length)); return length; } - int store_time_dec(MYSQL_TIME *ltime, uint dec); + int store_time_dec(const MYSQL_TIME *ltime, uint dec); double pos_in_interval(Field *min, Field *max) { return pos_in_interval_val_real(min, max); @@ -1856,7 +1856,7 @@ public: field_length >= from->field_length; } int store_decimal(const my_decimal *); - int store_time_dec(MYSQL_TIME *ltime, uint dec); + int store_time_dec(const MYSQL_TIME *ltime, uint dec); bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); my_decimal *val_decimal(my_decimal *); bool val_bool() { return val_real() != 0e0; } @@ -1946,7 +1946,7 @@ public: int store(const char *to, uint length, CHARSET_INFO *charset); int store(double nr); int store(longlong nr, bool unsigned_val); - int store_time_dec(MYSQL_TIME *ltime, uint dec); + int store_time_dec(const MYSQL_TIME *ltime, uint dec); int store_decimal(const my_decimal *); double val_real(void); longlong val_int(void); @@ -2474,7 +2474,7 @@ public: int store(const char *to, uint length, CHARSET_INFO *charset); int store(double nr); int store(longlong nr, bool unsigned_val); - int store_time_dec(MYSQL_TIME *ltime, uint dec); + int store_time_dec(const MYSQL_TIME *ltime, uint dec); int store_decimal(const my_decimal *); bool validate_value_in_record(THD *thd, const uchar *record) const; }; @@ -2496,7 +2496,7 @@ public: int store(const char *to,uint length,CHARSET_INFO *charset); int store(double nr); int store(longlong nr, bool unsigned_val); - int store_time_dec(MYSQL_TIME *ltime, uint dec); + int store_time_dec(const MYSQL_TIME *ltime, uint dec); int store_decimal(const my_decimal *); int store_timestamp(my_time_t timestamp, ulong sec_part); int save_in_field(Field *to); @@ -2699,7 +2699,7 @@ public: int store(const char *to,uint length,CHARSET_INFO *charset); int store(double nr); int store(longlong nr, bool unsigned_val); - int store_time_dec(MYSQL_TIME *ltime, uint dec); + int store_time_dec(const MYSQL_TIME *ltime, uint dec); double val_real(void); longlong val_int(void); String *val_str(String*,String *); @@ -2780,9 +2780,14 @@ class Field_time :public Field_temporal { */ long curdays; protected: - virtual void store_TIME(MYSQL_TIME *ltime); + virtual void store_TIME(const MYSQL_TIME *ltime); int store_TIME_with_warning(MYSQL_TIME *ltime, const ErrConv *str, int was_cut, int have_smth_to_conv); + void set_warnings(Sql_condition::enum_warning_level level, + const ErrConv *str, int was_cut) + { + Field_temporal::set_warnings(level, str, was_cut, MYSQL_TIMESTAMP_TIME); + } bool check_zero_in_date_with_warn(ulonglong fuzzydate); static void do_field_time(Copy_field *copy); public: @@ -2809,7 +2814,7 @@ public: return real_type() == from->real_type() && decimals() == from->decimals(); } - int store_time_dec(MYSQL_TIME *ltime, uint dec); + int store_time_dec(const MYSQL_TIME *ltime, uint dec); int store(const char *to,uint length,CHARSET_INFO *charset); int store(double nr); int store(longlong nr, bool unsigned_val); @@ -2864,7 +2869,7 @@ public: */ class Field_time_hires :public Field_time_with_dec { longlong zero_point; - void store_TIME(MYSQL_TIME *ltime); + void store_TIME(const MYSQL_TIME *); public: Field_time_hires(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const LEX_CSTRING *field_name_arg, @@ -2890,7 +2895,7 @@ public: TIME(0..6) - MySQL56 version */ class Field_timef :public Field_time_with_dec { - void store_TIME(MYSQL_TIME *ltime); + void store_TIME(const MYSQL_TIME *ltime); int save_field_metadata(uchar *metadata_ptr) { *metadata_ptr= (uchar) decimals(); diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index b32bdd6c2bd..0df2c748ccc 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -244,7 +244,7 @@ ha_partition::ha_partition(handlerton *hton, TABLE_SHARE *share) void ha_partition::ha_partition_init() { - init_alloc_root(&m_mem_root, 512, 512, MYF(0)); + init_alloc_root(&m_mem_root, "ha_partition", 512, 512, MYF(0)); init_handler_variables(); } diff --git a/sql/item.cc b/sql/item.cc index 7a55486f997..b36c1518eb8 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1793,7 +1793,7 @@ Item_splocal::Item_splocal(THD *thd, const LEX_CSTRING *sp_var_name, bool Item_splocal::fix_fields(THD *thd, Item **ref) { - Item *item= thd->spcont->get_item(m_var_idx); + Item_field *item= thd->spcont->get_variable(m_var_idx); set_handler(item->type_handler()); return fix_fields_from_item(thd, ref, item); } @@ -1804,7 +1804,7 @@ Item_splocal::this_item() { DBUG_ASSERT(m_sp == m_thd->spcont->m_sp); DBUG_ASSERT(fixed); - return m_thd->spcont->get_item(m_var_idx); + return m_thd->spcont->get_variable(m_var_idx); } const Item * @@ -1812,7 +1812,7 @@ Item_splocal::this_item() const { DBUG_ASSERT(m_sp == m_thd->spcont->m_sp); DBUG_ASSERT(fixed); - return m_thd->spcont->get_item(m_var_idx); + return m_thd->spcont->get_variable(m_var_idx); } @@ -1821,7 +1821,7 @@ Item_splocal::this_item_addr(THD *thd, Item **) { DBUG_ASSERT(m_sp == thd->spcont->m_sp); DBUG_ASSERT(fixed); - return thd->spcont->get_item_addr(m_var_idx); + return thd->spcont->get_variable_addr(m_var_idx); } @@ -1918,7 +1918,7 @@ bool Item_splocal::check_cols(uint n) bool Item_splocal_row_field::fix_fields(THD *thd, Item **ref) { - Item *item= thd->spcont->get_item(m_var_idx)->element_index(m_field_idx); + Item *item= thd->spcont->get_variable(m_var_idx)->element_index(m_field_idx); return fix_fields_from_item(thd, ref, item); } @@ -1928,7 +1928,7 @@ Item_splocal_row_field::this_item() { DBUG_ASSERT(m_sp == m_thd->spcont->m_sp); DBUG_ASSERT(fixed); - return m_thd->spcont->get_item(m_var_idx)->element_index(m_field_idx); + return m_thd->spcont->get_variable(m_var_idx)->element_index(m_field_idx); } @@ -1937,7 +1937,7 @@ Item_splocal_row_field::this_item() const { DBUG_ASSERT(m_sp == m_thd->spcont->m_sp); DBUG_ASSERT(fixed); - return m_thd->spcont->get_item(m_var_idx)->element_index(m_field_idx); + return m_thd->spcont->get_variable(m_var_idx)->element_index(m_field_idx); } @@ -1946,7 +1946,7 @@ Item_splocal_row_field::this_item_addr(THD *thd, Item **) { DBUG_ASSERT(m_sp == thd->spcont->m_sp); DBUG_ASSERT(fixed); - return thd->spcont->get_item(m_var_idx)->addr(m_field_idx); + return thd->spcont->get_variable(m_var_idx)->addr(m_field_idx); } @@ -1977,7 +1977,7 @@ bool Item_splocal_row_field_by_name::fix_fields(THD *thd, Item **it) m_var_idx, m_field_name)) return true; - Item *item= thd->spcont->get_item(m_var_idx)->element_index(m_field_idx); + Item *item= thd->spcont->get_variable(m_var_idx)->element_index(m_field_idx); set_handler(item->type_handler()); return fix_fields_from_item(thd, it, item); } @@ -2899,7 +2899,7 @@ Item_sp::execute_impl(THD *thd, Item **args, uint arg_count) (m_sp->agg_type() == NOT_AGGREGATE && !func_ctx)); if (!func_ctx) { - init_sql_alloc(&sp_mem_root, MEM_ROOT_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(&sp_mem_root, "Item_sp", MEM_ROOT_BLOCK_SIZE, 0, MYF(0)); *sp_query_arena= Query_arena(&sp_mem_root, Query_arena::STMT_INITIALIZED_FOR_SP); } @@ -4009,7 +4009,10 @@ Item_param::Item_param(THD *thd, const LEX_CSTRING *name_arg, void Item_param::set_null() { DBUG_ENTER("Item_param::set_null"); - /* These are cleared after each execution by reset() method */ + /* + These are cleared after each execution by reset() method or by setting + other value. + */ null_value= 1; /* Because of NULL and string values we need to set max_length for each new @@ -4033,6 +4036,7 @@ void Item_param::set_int(longlong i, uint32 max_length_arg) max_length= max_length_arg; decimals= 0; maybe_null= 0; + null_value= 0; fix_type(Item::INT_ITEM); DBUG_VOID_RETURN; } @@ -4047,6 +4051,7 @@ void Item_param::set_double(double d) max_length= DBL_DIG + 8; decimals= NOT_FIXED_DEC; maybe_null= 0; + null_value= 0; fix_type(Item::REAL_ITEM); DBUG_VOID_RETURN; } @@ -4079,6 +4084,7 @@ void Item_param::set_decimal(const char *str, ulong length) my_decimal_precision_to_length_no_truncation(value.m_decimal.precision(), decimals, unsigned_flag); maybe_null= 0; + null_value= 0; fix_type(Item::DECIMAL_ITEM); DBUG_VOID_RETURN; } @@ -4095,6 +4101,8 @@ void Item_param::set_decimal(const my_decimal *dv, bool unsigned_arg) unsigned_flag= unsigned_arg; max_length= my_decimal_precision_to_length(value.m_decimal.intg + decimals, decimals, unsigned_flag); + maybe_null= 0; + null_value= 0; fix_type(Item::DECIMAL_ITEM); } @@ -4105,6 +4113,8 @@ void Item_param::fix_temporal(uint32 max_length_arg, uint decimals_arg) collation.set_numeric(); max_length= max_length_arg; decimals= decimals_arg; + maybe_null= 0; + null_value= 0; fix_type(Item::DATE_ITEM); } @@ -4114,6 +4124,8 @@ void Item_param::set_time(const MYSQL_TIME *tm, { DBUG_ASSERT(value.type_handler()->cmp_type() == TIME_RESULT); value.time= *tm; + maybe_null= 0; + null_value= 0; fix_temporal(max_length_arg, decimals_arg); } @@ -4148,6 +4160,7 @@ void Item_param::set_time(MYSQL_TIME *tm, timestamp_type time_type, set_zero_time(&value.time, MYSQL_TIMESTAMP_ERROR); } maybe_null= 0; + null_value= 0; fix_temporal(max_length_arg, tm->second_part > 0 ? TIME_SECOND_PART_DIGITS : 0); DBUG_VOID_RETURN; @@ -4184,6 +4197,7 @@ bool Item_param::set_str(const char *str, ulong length, collation.set(tocs, DERIVATION_COERCIBLE); max_length= length; maybe_null= 0; + null_value= 0; /* max_length and decimals are set after charset conversion */ /* sic: str may be not null-terminated, don't add DBUG_PRINT here */ fix_type(Item::STRING_ITEM); @@ -4219,6 +4233,7 @@ bool Item_param::set_longdata(const char *str, ulong length) DBUG_RETURN(TRUE); state= LONG_DATA_VALUE; maybe_null= 0; + null_value= 0; fix_type(Item::STRING_ITEM); DBUG_RETURN(FALSE); @@ -4878,7 +4893,9 @@ Item_param::set_value(THD *thd, sp_rcontext *ctx, Item **it) set_null(); return false; } - return null_value= false; + /* It is wrapper => other set_* shoud set null_value */ + DBUG_ASSERT(null_value == false); + return false; } diff --git a/sql/log.cc b/sql/log.cc index c709734028d..dfbe2c33e2e 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -10005,7 +10005,8 @@ int TC_LOG_BINLOG::recover(LOG_INFO *linfo, const char *last_log_name, goto err1; if (do_xa) - init_alloc_root(&mem_root, TC_LOG_PAGE_SIZE, TC_LOG_PAGE_SIZE, MYF(0)); + init_alloc_root(&mem_root, "TC_LOG_BINLOG", TC_LOG_PAGE_SIZE, + TC_LOG_PAGE_SIZE, MYF(0)); fdle->flags&= ~LOG_EVENT_BINLOG_IN_USE_F; // abort on the first error diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 1e23d3eba61..073788370f1 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1375,7 +1375,7 @@ private: void Buffered_logs::init() { - init_alloc_root(&m_root, 1024, 0, MYF(0)); + init_alloc_root(&m_root, "Buffered_logs", 1024, 0, MYF(0)); } void Buffered_logs::cleanup() @@ -8753,7 +8753,7 @@ static int option_cmp(my_option *a, my_option *b) static void print_help() { MEM_ROOT mem_root; - init_alloc_root(&mem_root, 4096, 4096, MYF(0)); + init_alloc_root(&mem_root, "help", 4096, 4096, MYF(0)); pop_dynamic(&all_options); add_many_options(&all_options, pfs_early_options, diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 369729127dd..636e9bd496a 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -1254,7 +1254,8 @@ QUICK_RANGE_SELECT::QUICK_RANGE_SELECT(THD *thd, TABLE *table, uint key_nr, if (!no_alloc && !parent_alloc) { // Allocates everything through the internal memroot - init_sql_alloc(&alloc, thd->variables.range_alloc_block_size, 0, + init_sql_alloc(&alloc, "QUICK_RANGE_SELECT", + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); thd->mem_root= &alloc; } @@ -1351,7 +1352,8 @@ QUICK_INDEX_SORT_SELECT::QUICK_INDEX_SORT_SELECT(THD *thd_param, index= MAX_KEY; head= table; bzero(&read_record, sizeof(read_record)); - init_sql_alloc(&alloc, thd->variables.range_alloc_block_size, 0, + init_sql_alloc(&alloc, "QUICK_INDEX_SORT_SELECT", + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); DBUG_VOID_RETURN; } @@ -1422,7 +1424,8 @@ QUICK_ROR_INTERSECT_SELECT::QUICK_ROR_INTERSECT_SELECT(THD *thd_param, head= table; record= head->record[0]; if (!parent_alloc) - init_sql_alloc(&alloc, thd->variables.range_alloc_block_size, 0, + init_sql_alloc(&alloc, "QUICK_ROR_INTERSECT_SELECT", + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); else bzero(&alloc, sizeof(MEM_ROOT)); @@ -1698,7 +1701,8 @@ QUICK_ROR_UNION_SELECT::QUICK_ROR_UNION_SELECT(THD *thd_param, head= table; rowid_length= table->file->ref_length; record= head->record[0]; - init_sql_alloc(&alloc, thd->variables.range_alloc_block_size, 0, + init_sql_alloc(&alloc, "QUICK_ROR_UNION_SELECT", + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); thd_param->mem_root= &alloc; } @@ -2453,7 +2457,8 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, param.possible_keys.clear_all(); thd->no_errors=1; // Don't warn about NULL - init_sql_alloc(&alloc, thd->variables.range_alloc_block_size, 0, + init_sql_alloc(&alloc, "test_quick_select", + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); if (!(param.key_parts= (KEY_PART*) alloc_root(&alloc, @@ -3027,7 +3032,8 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond) SEL_TREE *tree; double rows; - init_sql_alloc(&alloc, thd->variables.range_alloc_block_size, 0, + init_sql_alloc(&alloc, "calculate_cond_selectivity_for_table", + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); param.thd= thd; param.mem_root= &alloc; @@ -3444,7 +3450,8 @@ bool prune_partitions(THD *thd, TABLE *table, Item *pprune_cond) my_bitmap_map *old_sets[2]; prune_param.part_info= part_info; - init_sql_alloc(&alloc, thd->variables.range_alloc_block_size, 0, + init_sql_alloc(&alloc, "prune_partitions", + thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); range_par->mem_root= &alloc; range_par->old_root= thd->mem_root; @@ -13621,7 +13628,8 @@ QUICK_GROUP_MIN_MAX_SELECT(TABLE *table, JOIN *join_arg, bool have_min_arg, DBUG_ASSERT(!parent_alloc); if (!parent_alloc) { - init_sql_alloc(&alloc, join->thd->variables.range_alloc_block_size, 0, + init_sql_alloc(&alloc, "QUICK_GROUP_MIN_MAX_SELECT", + join->thd->variables.range_alloc_block_size, 0, MYF(MY_THREAD_SPECIFIC)); join->thd->mem_root= &alloc; } diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 8adc685df35..eff28d0c27d 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -4129,7 +4129,8 @@ SJ_TMP_TABLE::create_sj_weedout_tmp_table(THD *thd) using_unique_constraint= TRUE; /* STEP 3: Allocate memory for temptable description */ - init_sql_alloc(&own_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(&own_root, "SJ_TMP_TABLE", + TABLE_ALLOC_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); if (!multi_alloc_root(&own_root, &table, sizeof(*table), &share, sizeof(*share), diff --git a/sql/rpl_tblmap.cc b/sql/rpl_tblmap.cc index 80d093722f7..7284e4be15c 100644 --- a/sql/rpl_tblmap.cc +++ b/sql/rpl_tblmap.cc @@ -46,7 +46,8 @@ table_mapping::table_mapping() offsetof(entry,table_id),sizeof(ulong), 0,0,0); /* We don't preallocate any block, this is consistent with m_free=0 above */ - init_alloc_root(&m_mem_root, TABLE_ID_HASH_SIZE*sizeof(entry), 0, MYF(0)); + init_alloc_root(&m_mem_root, "table_mapping", + TABLE_ID_HASH_SIZE*sizeof(entry), 0, MYF(0)); DBUG_VOID_RETURN; } diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 2387429ea79..d451f25db8a 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -471,7 +471,8 @@ sp_head::operator new(size_t size) throw() MEM_ROOT own_root; sp_head *sp; - init_sql_alloc(&own_root, MEM_ROOT_BLOCK_SIZE, MEM_ROOT_PREALLOC, MYF(0)); + init_sql_alloc(&own_root, "sp_head", + MEM_ROOT_BLOCK_SIZE, MEM_ROOT_PREALLOC, MYF(0)); sp= (sp_head *) alloc_root(&own_root, size); if (sp == NULL) DBUG_RETURN(NULL); @@ -999,7 +1000,8 @@ sp_head::execute(THD *thd, bool merge_da_on_success) thd->select_number+= m_select_number; /* init per-instruction memroot */ - init_sql_alloc(&execute_mem_root, MEM_ROOT_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(&execute_mem_root, "per_instruction_memroot", + MEM_ROOT_BLOCK_SIZE, 0, MYF(0)); DBUG_ASSERT(!(m_flags & IS_INVOKED)); m_flags|= IS_INVOKED; @@ -1520,7 +1522,6 @@ sp_head::execute_trigger(THD *thd, MEM_ROOT call_mem_root; Query_arena call_arena(&call_mem_root, Query_arena::STMT_INITIALIZED_FOR_SP); Query_arena backup_arena; - DBUG_ENTER("sp_head::execute_trigger"); DBUG_PRINT("info", ("trigger %s", m_name.str)); @@ -1576,7 +1577,8 @@ sp_head::execute_trigger(THD *thd, TODO: we should create sp_rcontext once per command and reuse it on subsequent executions of a trigger. */ - init_sql_alloc(&call_mem_root, MEM_ROOT_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(&call_mem_root, "execute_trigger", MEM_ROOT_BLOCK_SIZE, 0, + MYF(0)); thd->set_n_backup_active_arena(&call_arena, &backup_arena); Row_definition_list defs; @@ -1713,7 +1715,7 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, /* Arguments must be fixed in Item_func_sp::fix_fields */ DBUG_ASSERT(argp[arg_no]->fixed); - if ((err_status= (*func_ctx)->set_variable(thd, arg_no, &(argp[arg_no])))) + if ((err_status= (*func_ctx)->set_parameter(thd, arg_no, &(argp[arg_no])))) goto err_with_cleanup; } @@ -1745,7 +1747,7 @@ sp_head::execute_function(THD *thd, Item **argp, uint argcount, if (arg_no) binlog_buf.append(','); - Item *item= (*func_ctx)->get_item(arg_no); + Item_field *item= (*func_ctx)->get_parameter(arg_no); str_value= item->type_handler()->print_item_value(thd, item, &str_value_holder); if (str_value) @@ -1958,7 +1960,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) Item *tmp_item= null_item; if (!null_item || - nctx->set_variable(thd, i, &tmp_item)) + nctx->set_parameter(thd, i, &tmp_item)) { DBUG_PRINT("error", ("set variable failed")); err_status= TRUE; @@ -1967,7 +1969,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) } else { - if (nctx->set_variable(thd, i, it_args.ref())) + if (nctx->set_parameter(thd, i, it_args.ref())) { DBUG_PRINT("error", ("set variable 2 failed")); err_status= TRUE; @@ -2095,7 +2097,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) DBUG_ASSERT(srp); - if (srp->set_value(thd, octx, nctx->get_item_addr(i))) + if (srp->set_value(thd, octx, nctx->get_variable_addr(i))) { DBUG_PRINT("error", ("set value failed")); err_status= TRUE; @@ -2103,7 +2105,7 @@ sp_head::execute_procedure(THD *thd, List<Item> *args) } Send_field *out_param_info= new (thd->mem_root) Send_field(); - nctx->get_item(i)->make_field(thd, out_param_info); + nctx->get_parameter(i)->make_field(thd, out_param_info); out_param_info->db_name= m_db.str; out_param_info->table_name= m_name.str; out_param_info->org_table_name= m_name.str; @@ -4204,7 +4206,7 @@ sp_instr_cursor_copy_struct::exec_core(THD *thd, uint *nextp) { DBUG_ENTER("sp_instr_cursor_copy_struct::exec_core"); int ret= 0; - Item_field_row *row= (Item_field_row*) thd->spcont->get_item(m_var); + Item_field_row *row= (Item_field_row*) thd->spcont->get_variable(m_var); DBUG_ASSERT(row->type_handler() == &type_handler_row); /* diff --git a/sql/sp_rcontext.cc b/sql/sp_rcontext.cc index 825141d4a5b..eab0e10a3f0 100644 --- a/sql/sp_rcontext.cc +++ b/sql/sp_rcontext.cc @@ -316,7 +316,7 @@ bool sp_rcontext::init_var_items(THD *thd, uint num_vars= m_root_parsing_ctx->max_var_index(); m_var_items.reset( - static_cast<Item **> ( + static_cast<Item_field **> ( thd->alloc(num_vars * sizeof (Item *))), num_vars); @@ -633,7 +633,7 @@ int sp_rcontext::set_variable_row_field_by_name(THD *thd, uint var_idx, int sp_rcontext::set_variable_row(THD *thd, uint var_idx, List<Item> &items) { DBUG_ENTER("sp_rcontext::set_variable_row"); - DBUG_ASSERT(get_item(var_idx)->cols() == items.elements); + DBUG_ASSERT(get_variable(var_idx)->cols() == items.elements); Virtual_tmp_table *vtable= virtual_tmp_table_for_row(var_idx); Sp_eval_expr_state state(thd); DBUG_RETURN(vtable->sp_set_all_fields_from_item_list(thd, items)); @@ -642,8 +642,8 @@ int sp_rcontext::set_variable_row(THD *thd, uint var_idx, List<Item> &items) Virtual_tmp_table *sp_rcontext::virtual_tmp_table_for_row(uint var_idx) { - DBUG_ASSERT(get_item(var_idx)->type() == Item::FIELD_ITEM); - DBUG_ASSERT(get_item(var_idx)->cmp_type() == ROW_RESULT); + DBUG_ASSERT(get_variable(var_idx)->type() == Item::FIELD_ITEM); + DBUG_ASSERT(get_variable(var_idx)->cmp_type() == ROW_RESULT); Field *field= m_var_table->field[var_idx]; Virtual_tmp_table **ptable= field->virtual_tmp_table_addr(); DBUG_ASSERT(ptable); @@ -808,7 +808,7 @@ int sp_cursor::fetch(THD *thd, List<sp_variable> *vars, bool error_on_no_data) if (vars->elements != result.get_field_count() && (vars->elements != 1 || result.get_field_count() != - thd->spcont->get_item(vars->head()->offset)->cols())) + thd->spcont->get_variable(vars->head()->offset)->cols())) { my_message(ER_SP_WRONG_NO_OF_FETCH_ARGS, ER_THD(thd, ER_SP_WRONG_NO_OF_FETCH_ARGS), MYF(0)); @@ -906,7 +906,7 @@ int sp_cursor::Select_fetch_into_spvars::send_data(List<Item> &items) on attempt to assign a scalar value to a ROW variable. */ return spvar_list->elements == 1 && - (item= thd->spcont->get_item(spvar_list->head()->offset)) && + (item= thd->spcont->get_variable(spvar_list->head()->offset)) && item->type_handler() == &type_handler_row && item->cols() == items.elements ? thd->spcont->set_variable_row(thd, spvar_list->head()->offset, items) : diff --git a/sql/sp_rcontext.h b/sql/sp_rcontext.h index ab1238c5f25..8a03dca435d 100644 --- a/sql/sp_rcontext.h +++ b/sql/sp_rcontext.h @@ -191,6 +191,11 @@ public: // SP-variables. ///////////////////////////////////////////////////////////////////////// + uint argument_count() const + { + return m_root_parsing_ctx->context_var_count(); + } + int set_variable(THD *thd, uint var_idx, Item **value); int set_variable_row_field(THD *thd, uint var_idx, uint field_idx, Item **value); @@ -198,11 +203,24 @@ public: const LEX_CSTRING &field_name, Item **value); int set_variable_row(THD *thd, uint var_idx, List<Item> &items); - Item *get_item(uint var_idx) const + + int set_parameter(THD *thd, uint var_idx, Item **value) + { + DBUG_ASSERT(var_idx < argument_count()); + return set_variable(thd, var_idx, value); + } + + Item_field *get_variable(uint var_idx) const { return m_var_items[var_idx]; } - Item **get_item_addr(uint var_idx) const - { return m_var_items.array() + var_idx; } + Item **get_variable_addr(uint var_idx) const + { return ((Item **) m_var_items.array()) + var_idx; } + + Item_field *get_parameter(uint var_idx) const + { + DBUG_ASSERT(var_idx < argument_count()); + return get_variable(var_idx); + } bool find_row_field_by_name_or_error(uint *field_idx, uint var_idx, const LEX_CSTRING &field_name); @@ -381,7 +399,7 @@ private: /// Collection of Item_field proxies, each of them points to the /// corresponding field in m_var_table. - Bounds_checked_array<Item *> m_var_items; + Bounds_checked_array<Item_field *> m_var_items; /// This is a pointer to a field, which should contain return value for /// stored functions (only). For stored procedures, this pointer is NULL. diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 6b31bdf1f35..3964424af62 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1818,7 +1818,7 @@ static bool acl_load(THD *thd, const Grant_tables& tables) grant_version++; /* Privileges updated */ const Host_table& host_table= tables.host_table(); - init_sql_alloc(&acl_memroot, ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(&acl_memroot, "ACL", ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); if (host_table.table_exists()) // "host" table may not exist (e.g. in MySQL 5.6.7+) { if (host_table.init_read_record(&read_record_info, thd)) @@ -2237,7 +2237,7 @@ static bool acl_load(THD *thd, const Grant_tables& tables) DBUG_RETURN(TRUE); MEM_ROOT temp_root; - init_alloc_root(&temp_root, ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_alloc_root(&temp_root, "ACL_tmp", ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); while (!(read_record_info.read_record())) { char *hostname= safe_str(get_field(&temp_root, roles_mapping_table.host())); @@ -7304,7 +7304,7 @@ static bool grant_load(THD *thd, 0,0,0, (my_hash_get_key) get_grant_table, 0,0); (void) my_hash_init(&func_priv_hash, &my_charset_utf8_bin, 0,0,0, (my_hash_get_key) get_grant_table, 0,0); - init_sql_alloc(&grant_memroot, ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(&grant_memroot, "GRANT", ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); t_table= tables_priv.table(); c_table= columns_priv.table(); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 82d86b9404a..5cb6ad53b51 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -781,8 +781,8 @@ THD::THD(my_thread_id id, bool is_wsrep_applier, bool skip_global_sys_var_lock) the destructor works OK in case of an error. The main_mem_root will be re-initialized in init_for_queries(). */ - init_sql_alloc(&main_mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0, - MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(&main_mem_root, "THD::main_mem_root", + ALLOC_ROOT_MIN_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); stmt_arena= this; thread_stack= 0; @@ -3727,7 +3727,7 @@ int select_dumpvar::prepare(List<Item> &list, SELECT_LEX_UNIT *u) mvsp->type_handler() == &type_handler_row) { // SELECT INTO row_type_sp_variable - if (thd->spcont->get_item(mvsp->offset)->cols() != list.elements) + if (thd->spcont->get_variable(mvsp->offset)->cols() != list.elements) goto error; m_var_sp_row= mvsp; return 0; diff --git a/sql/sql_class.h b/sql/sql_class.h index 8199418cd8f..9775aa71193 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1845,7 +1845,8 @@ public: m_reopen_array(NULL), m_locked_tables_count(0) { - init_sql_alloc(&m_locked_tables_root, MEM_ROOT_BLOCK_SIZE, 0, + init_sql_alloc(&m_locked_tables_root, "Locked_tables_list", + MEM_ROOT_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); } void unlock_locked_tables(THD *thd); @@ -2610,7 +2611,8 @@ public: { bzero((char*)this, sizeof(*this)); xid_state.xid.null(); - init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0, + init_sql_alloc(&mem_root, "THD::transactions", + ALLOC_ROOT_MIN_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); } } transaction; diff --git a/sql/sql_error.cc b/sql/sql_error.cc index b4c6aff4f6d..24fb934c279 100644 --- a/sql/sql_error.cc +++ b/sql/sql_error.cc @@ -506,7 +506,7 @@ void Warning_info::init() { /* Initialize sub structures */ DBUG_ASSERT(initialized == 0); - init_sql_alloc(&m_warn_root, WARN_ALLOC_BLOCK_SIZE, + init_sql_alloc(&m_warn_root, "Warning_info", WARN_ALLOC_BLOCK_SIZE, WARN_ALLOC_PREALLOC_SIZE, MYF(MY_THREAD_SPECIFIC)); initialized= 1; } diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 1f52041917e..ddc9c4a99d7 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -382,7 +382,8 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen) /* copy data to sql_handler */ if (!(sql_handler= new SQL_HANDLER(thd))) goto err; - init_alloc_root(&sql_handler->mem_root, 1024, 0, MYF(MY_THREAD_SPECIFIC)); + init_alloc_root(&sql_handler->mem_root, "sql_handler", 1024, 0, + MYF(MY_THREAD_SPECIFIC)); sql_handler->db.length= tables->db.length; sql_handler->table_name.length= tables->table_name.length; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 243a8bf8b3f..0106f189ca8 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -4851,8 +4851,8 @@ bool LEX::set_arena_for_set_stmt(Query_arena *backup) mem_root_for_set_stmt= new MEM_ROOT(); if (!(mem_root_for_set_stmt)) DBUG_RETURN(1); - init_sql_alloc(mem_root_for_set_stmt, ALLOC_ROOT_SET, ALLOC_ROOT_SET, - MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(mem_root_for_set_stmt, "set_stmt", + ALLOC_ROOT_SET, ALLOC_ROOT_SET, MYF(MY_THREAD_SPECIFIC)); } if (!(arena_for_set_stmt= new(mem_root_for_set_stmt) Query_arena_memroot(mem_root_for_set_stmt, diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 7ea7ed431d1..d5f1e88bc11 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1187,7 +1187,7 @@ static bool plugin_add(MEM_ROOT *tmp_root, goto err; if (my_hash_insert(&plugin_hash[plugin->type], (uchar*)tmp_plugin_ptr)) tmp_plugin_ptr->state= PLUGIN_IS_FREED; - init_alloc_root(&tmp_plugin_ptr->mem_root, 4096, 4096, MYF(0)); + init_alloc_root(&tmp_plugin_ptr->mem_root, "plugin", 4096, 4096, MYF(0)); if (name->str) DBUG_RETURN(FALSE); // all done @@ -1577,9 +1577,9 @@ int plugin_init(int *argc, char **argv, int flags) dlopen_count =0; - init_alloc_root(&plugin_mem_root, 4096, 4096, MYF(0)); - init_alloc_root(&plugin_vars_mem_root, 4096, 4096, MYF(0)); - init_alloc_root(&tmp_root, 4096, 4096, MYF(0)); + init_alloc_root(&plugin_mem_root, "plugin", 4096, 4096, MYF(0)); + init_alloc_root(&plugin_vars_mem_root, "plugin_vars", 4096, 4096, MYF(0)); + init_alloc_root(&tmp_root, "plugin_tmp", 4096, 4096, MYF(0)); if (my_hash_init(&bookmark_hash, &my_charset_bin, 32, 0, 0, get_bookmark_hash_key, NULL, HASH_UNIQUE)) diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 06ce5187f04..97325050628 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -3699,8 +3699,10 @@ Prepared_statement::Prepared_statement(THD *thd_arg) read_types(0), m_sql_mode(thd->variables.sql_mode) { - init_sql_alloc(&main_mem_root, thd_arg->variables.query_alloc_block_size, - thd_arg->variables.query_prealloc_size, MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(&main_mem_root, "Prepared_statement", + thd_arg->variables.query_alloc_block_size, + thd_arg->variables.query_prealloc_size, + MYF(MY_THREAD_SPECIFIC)); *last_error= '\0'; } @@ -5359,7 +5361,8 @@ bool Protocol_local::send_result_set_metadata(List<Item> *columns, uint) { DBUG_ASSERT(m_rset == 0 && !alloc_root_inited(&m_rset_root)); - init_sql_alloc(&m_rset_root, MEM_ROOT_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(&m_rset_root, "send_result_set_metadata", + MEM_ROOT_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); if (! (m_rset= new (&m_rset_root) List<Ed_row>)) return TRUE; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 84976b1e8a4..2bca32ddcda 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1224,8 +1224,9 @@ gtid_find_binlog_file(slave_connection_state *state, char *out_name, const char *errormsg= NULL; char buf[FN_REFLEN]; - init_alloc_root(&memroot, 10*(FN_REFLEN+sizeof(binlog_file_entry)), 0, - MYF(MY_THREAD_SPECIFIC)); + init_alloc_root(&memroot, "gtid_find_binlog_file", + 10*(FN_REFLEN+sizeof(binlog_file_entry)), + 0, MYF(MY_THREAD_SPECIFIC)); if (!(list= get_binlog_list(&memroot))) { errormsg= "Out of memory while looking for GTID position in binlog"; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index b19cfefb3e3..2c1452e8096 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -17145,7 +17145,8 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields, if (param->precomputed_group_by) copy_func_count+= param->sum_func_count; - init_sql_alloc(&own_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(&own_root, "tmp_table", TABLE_ALLOC_BLOCK_SIZE, 0, + MYF(MY_THREAD_SPECIFIC)); if (!multi_alloc_root(&own_root, &table, sizeof(*table), @@ -17899,18 +17900,19 @@ bool Virtual_tmp_table::init(uint field_count) { uint *blob_field; uchar *bitmaps; + DBUG_ENTER("Virtual_tmp_table::init"); if (!multi_alloc_root(in_use->mem_root, &s, sizeof(*s), &field, (field_count + 1) * sizeof(Field*), &blob_field, (field_count + 1) * sizeof(uint), &bitmaps, bitmap_buffer_size(field_count) * 6, NullS)) - return true; + DBUG_RETURN(true); bzero(s, sizeof(*s)); s->blob_field= blob_field; setup_tmp_table_column_bitmaps(this, bitmaps, field_count); m_alloced_field_count= field_count; - return false; + DBUG_RETURN(false); }; @@ -17919,17 +17921,18 @@ bool Virtual_tmp_table::add(List<Spvar_definition> &field_list) /* Create all fields and calculate the total length of record */ Spvar_definition *cdef; /* column definition */ List_iterator_fast<Spvar_definition> it(field_list); - for ( ; (cdef= it++); ) + DBUG_ENTER("Virtual_tmp_table::add"); + while ((cdef= it++)) { Field *tmp; if (!(tmp= cdef->make_field(s, in_use->mem_root, 0, (uchar*) (f_maybe_null(cdef->pack_flag) ? "" : 0), f_maybe_null(cdef->pack_flag) ? 1 : 0, &cdef->field_name))) - return true; - add(tmp); + DBUG_RETURN(true); + add(tmp); } - return false; + DBUG_RETURN(false); } diff --git a/sql/sql_select.h b/sql/sql_select.h index 08ad7fa9464..4642fe04dbc 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -2161,7 +2161,7 @@ public: DBUG_ASSERT(s->blob_fields <= m_alloced_field_count); s->blob_field[s->blob_fields - 1]= s->fields; } - s->fields++; + new_field->field_index= s->fields++; return false; } diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index 599073f0adf..4a0addc7b07 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -156,7 +156,8 @@ bool servers_init(bool dont_read_servers_table) } /* Initialize the mem root for data */ - init_sql_alloc(&mem, ACL_ALLOC_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(&mem, "servers", ACL_ALLOC_BLOCK_SIZE, 0, + MYF(MY_THREAD_SPECIFIC)); if (dont_read_servers_table) goto end; @@ -205,7 +206,7 @@ static bool servers_load(THD *thd, TABLE_LIST *tables) my_hash_reset(&servers_cache); free_root(&mem, MYF(0)); - init_sql_alloc(&mem, ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(&mem, "servers_load", ACL_ALLOC_BLOCK_SIZE, 0, MYF(0)); if (init_read_record(&read_record_info,thd,table=tables[0].table, NULL, NULL, 1,0, FALSE)) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 98db2bb64e1..4fc0b65b774 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -4891,7 +4891,8 @@ static int fill_schema_table_from_frm(THD *thd, TABLE *table, if (schema_table->i_s_requested_object & OPEN_TRIGGER_ONLY) { - init_sql_alloc(&tbl.mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(&tbl.mem_root, "fill_schema_table_from_frm", + TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); if (!Table_triggers_list::check_n_load(thd, db_name, table_name, &tbl, 1)) { @@ -5174,8 +5175,8 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) goto err; /* Use tmp_mem_root to allocate data for opened tables */ - init_alloc_root(&tmp_mem_root, SHOW_ALLOC_BLOCK_SIZE, SHOW_ALLOC_BLOCK_SIZE, - MY_THREAD_SPECIFIC); + init_alloc_root(&tmp_mem_root, "get_all_tables", SHOW_ALLOC_BLOCK_SIZE, + SHOW_ALLOC_BLOCK_SIZE, MY_THREAD_SPECIFIC); for (size_t i=0; i < db_names.elements(); i++) { diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 1ad9be1ea93..f96b9c40930 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1131,7 +1131,8 @@ static int execute_ddl_log_action(THD *thd, DDL_LOG_ENTRY *ddl_log_entry) ddl_log_entry->tmp_name)); handler_name.str= (char*)ddl_log_entry->handler_name; handler_name.length= strlen(ddl_log_entry->handler_name); - init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(MY_THREAD_SPECIFIC)); + init_sql_alloc(&mem_root, "execute_ddl_log_action", TABLE_ALLOC_BLOCK_SIZE, + 0, MYF(MY_THREAD_SPECIFIC)); if (!strcmp(ddl_log_entry->handler_name, reg_ext)) frm_action= TRUE; else diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index fac86ab5ab7..cf772ca9ccc 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -1792,10 +1792,11 @@ bool Table_triggers_list::drop_all_triggers(THD *thd, const LEX_CSTRING *db, TABLE table; char path[FN_REFLEN]; bool result= 0; - DBUG_ENTER("drop_all_triggers"); + DBUG_ENTER("Triggers::drop_all_triggers"); bzero(&table, sizeof(table)); - init_sql_alloc(&table.mem_root, 8192, 0, MYF(0)); + init_sql_alloc(&table.mem_root, "Triggers::drop_all_triggers", 8192, 0, + MYF(0)); if (Table_triggers_list::check_n_load(thd, db, name, &table, 1)) { @@ -2043,10 +2044,11 @@ bool Table_triggers_list::change_table_name(THD *thd, const LEX_CSTRING *db, bool result= 0; bool upgrading50to51= FALSE; Trigger *err_trigger; - DBUG_ENTER("change_table_name"); + DBUG_ENTER("Triggers::change_table_name"); bzero(&table, sizeof(table)); - init_sql_alloc(&table.mem_root, 8192, 0, MYF(0)); + init_sql_alloc(&table.mem_root, "Triggers::change_table_name", 8192, 0, + MYF(0)); /* This method interfaces the mysql server code protected by diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index ecf05d86193..0f4310fdec1 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -152,7 +152,7 @@ void udf_init() mysql_rwlock_init(key_rwlock_THR_LOCK_udf, &THR_LOCK_udf); - init_sql_alloc(&mem, UDF_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(&mem, "udf", UDF_ALLOC_BLOCK_SIZE, 0, MYF(0)); THD *new_thd = new THD(0); if (!new_thd || my_hash_init(&udf_hash,system_charset_info,32,0,0,get_hash_key, NULL, 0)) diff --git a/sql/table.cc b/sql/table.cc index 420c71876f3..f220e21920d 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -302,7 +302,7 @@ TABLE_SHARE *alloc_table_share(const char *db, const char *table_name, path_length= build_table_filename(path, sizeof(path) - 1, db, table_name, "", 0); - init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(&mem_root, "table_share", TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); if (multi_alloc_root(&mem_root, &share, sizeof(*share), &key_buff, key_length, @@ -328,7 +328,8 @@ TABLE_SHARE *alloc_table_share(const char *db, const char *table_name, (const uchar*) "mysql", 6) == 0) share->not_usable_by_query_cache= 1; - init_sql_alloc(&share->stats_cb.mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(&share->stats_cb.mem_root, "share_stats", + TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); memcpy((char*) &share->mem_root, (char*) &mem_root, sizeof(mem_root)); mysql_mutex_init(key_TABLE_SHARE_LOCK_share, @@ -385,8 +386,8 @@ void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key, This can't be MY_THREAD_SPECIFIC for slaves as they are freed during cleanup() from Relay_log_info::close_temporary_tables() */ - init_sql_alloc(&share->mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, - MYF(thd->slave_thread ? 0 : MY_THREAD_SPECIFIC)); + init_sql_alloc(&share->mem_root, "tmp_table_share", TABLE_ALLOC_BLOCK_SIZE, + 0, MYF(thd->slave_thread ? 0 : MY_THREAD_SPECIFIC)); share->table_category= TABLE_CATEGORY_TEMPORARY; share->tmp_table= INTERNAL_TMP_TABLE; share->db.str= (char*) key; @@ -3150,7 +3151,8 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, error= OPEN_FRM_NEEDS_REBUILD; goto err; } - init_sql_alloc(&outparam->mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0)); + init_sql_alloc(&outparam->mem_root, "table", TABLE_ALLOC_BLOCK_SIZE, 0, + MYF(0)); if (outparam->alias.copy(alias->str, alias->length, table_alias_charset)) goto err; diff --git a/sql/table.h b/sql/table.h index 7f8a579ef56..79742ff7111 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1052,7 +1052,8 @@ private: public: Blob_mem_storage() :truncated_value(false) { - init_alloc_root(&storage, MAX_FIELD_VARCHARLENGTH, 0, MYF(0)); + init_alloc_root(&storage, "Blob_mem_storage", MAX_FIELD_VARCHARLENGTH, 0, + MYF(0)); } ~ Blob_mem_storage() { diff --git a/sql/table_cache.cc b/sql/table_cache.cc index ba7047773b9..5ca4dd9f175 100644 --- a/sql/table_cache.cc +++ b/sql/table_cache.cc @@ -1301,7 +1301,8 @@ int tdc_iterate(THD *thd, my_hash_walk_action action, void *argument, if (no_dups) { - init_alloc_root(&no_dups_argument.root, 4096, 4096, MYF(alloc_flags)); + init_alloc_root(&no_dups_argument.root, "no_dups", 4096, 4096, + MYF(alloc_flags)); my_hash_init(&no_dups_argument.hash, &my_charset_bin, tdc_records(), 0, 0, eliminate_duplicates_get_key, 0, hash_flags); no_dups_argument.action= action; diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc index 74763e81b15..e0385c33fd8 100644 --- a/sql/thr_malloc.cc +++ b/sql/thr_malloc.cc @@ -58,10 +58,11 @@ extern "C" { } } -void init_sql_alloc(MEM_ROOT *mem_root, uint block_size, uint pre_alloc, - myf my_flags) +void init_sql_alloc(MEM_ROOT *mem_root, + const char *area_name __attribute__((unused)), + uint block_size, uint pre_alloc, myf my_flags) { - init_alloc_root(mem_root, block_size, pre_alloc, my_flags); + init_alloc_root(mem_root, area_name, block_size, pre_alloc, my_flags); mem_root->error_handler=sql_alloc_error_handler; } diff --git a/sql/thr_malloc.h b/sql/thr_malloc.h index 574dc7966b0..b56b7175ed1 100644 --- a/sql/thr_malloc.h +++ b/sql/thr_malloc.h @@ -18,8 +18,8 @@ typedef struct st_mem_root MEM_ROOT; -void init_sql_alloc(MEM_ROOT *root, uint block_size, uint pre_alloc_size, - myf my_flags); +void init_sql_alloc(MEM_ROOT *root, const char *area_name, uint block_size, + uint pre_alloc_size, myf my_flags); char *sql_strmake_with_convert(THD *thd, const char *str, size_t arg_length, CHARSET_INFO *from_cs, size_t max_res_length, diff --git a/sql/tztime.cc b/sql/tztime.cc index ad84c6c9bf0..7af218b3cb6 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -1631,7 +1631,7 @@ my_tz_init(THD *org_thd, const char *default_tzname, my_bool bootstrap) my_hash_free(&tz_names); goto end; } - init_sql_alloc(&tz_storage, 32 * 1024, 0, MYF(0)); + init_sql_alloc(&tz_storage, "timezone_storage", 32 * 1024, 0, MYF(0)); mysql_mutex_init(key_tz_LOCK, &tz_LOCK, MY_MUTEX_INIT_FAST); tz_inited= 1; @@ -2554,7 +2554,8 @@ scan_tz_dir(char * name_end, uint symlink_recursion_level, uint verbose) } else if (MY_S_ISREG(cur_dir->dir_entry[i].mystat->st_mode)) { - init_alloc_root(&tz_storage, 32768, 0, MYF(MY_THREAD_SPECIFIC)); + init_alloc_root(&tz_storage, "timezone_storage", 32768, 0, + MYF(MY_THREAD_SPECIFIC)); if (!tz_load(fullname, &tz_info, &tz_storage)) print_tz_as_sql(root_name_end + 1, &tz_info); else @@ -2728,7 +2729,7 @@ main(int argc, char **argv) First argument is timezonefile. The second is timezonename if opt_leap is not given */ - init_alloc_root(&tz_storage, 32768, 0, MYF(0)); + init_alloc_root(&tz_storage, "timezone_storage", 32768, 0, MYF(0)); if (tz_load(argv[0], &tz_info, &tz_storage)) { @@ -2802,7 +2803,7 @@ main(int argc, char **argv) MY_INIT(argv[0]); - init_alloc_root(&tz_storage, 32768, MYF(0)); + init_alloc_root(&tz_storage, "timezone_storage", 32768, MYF(0)); /* let us set some well known timezone */ setenv("TZ", "MET", 1); |