From ab9f378b0bed85f67cdaf5868af19f814e6bdfe1 Mon Sep 17 00:00:00 2001 From: Varun Gupta Date: Mon, 23 Sep 2019 13:47:52 +0530 Subject: Backporting 273d8eb12c40a6dcd05a8148bdfba3f1fd96e764 Proper fix for disabling warnings in read_statistics_for_table() --- sql/field.cc | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'sql/field.cc') diff --git a/sql/field.cc b/sql/field.cc index fd4cd8d5c54..a23004ebd96 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -79,7 +79,7 @@ const char field_separator=','; ptr < table->record[0] + table->s->reclength)))) #define ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED \ - DBUG_ASSERT(is_stat_field || !table || \ + DBUG_ASSERT(!table || \ (!table->write_set || \ bitmap_is_set(table->write_set, field_index) || \ (!(ptr >= table->record[0] && \ @@ -1822,8 +1822,7 @@ Field::Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg, flags=null_ptr ? 0: NOT_NULL_FLAG; comment.str= (char*) ""; comment.length=0; - field_index= 0; - is_stat_field= FALSE; + field_index= 0; cond_selectivity= 1.0; next_equal_field= NULL; } @@ -2436,8 +2435,7 @@ Field *Field::clone(MEM_ROOT *root, TABLE *new_table) } -Field *Field::clone(MEM_ROOT *root, TABLE *new_table, my_ptrdiff_t diff, - bool stat_flag) +Field *Field::clone(MEM_ROOT *root, TABLE *new_table, my_ptrdiff_t diff) { Field *tmp; if ((tmp= (Field*) memdup_root(root,(char*) this,size_of()))) @@ -2446,7 +2444,6 @@ Field *Field::clone(MEM_ROOT *root, TABLE *new_table, my_ptrdiff_t diff, tmp->init(new_table); tmp->move_field_offset(diff); } - tmp->is_stat_field= stat_flag; return tmp; } @@ -2829,7 +2826,7 @@ int Field_decimal::store(const char *from_arg, uint len, CHARSET_INFO *cs) /* Write digits of the frac_% parts ; - Depending on get_thd()->count_cutted_fields, we may also want + Depending on get_thd()->count_cuted_fields, we may also want to know if some non-zero tail of these parts will be truncated (for example, 0.002->0.00 will generate a warning, while 0.000->0.00 will not) @@ -7069,7 +7066,7 @@ Field_longstr::check_string_copy_error(const String_copier *copier, if (!(pos= copier->most_important_error_pos())) return FALSE; - if (!is_stat_field) + if (get_thd()->count_cuted_fields) { convert_to_printable(tmp, sizeof(tmp), pos, (end - pos), cs, 6); set_warning_truncated_wrong_value("string", tmp); @@ -7102,8 +7099,9 @@ int Field_longstr::report_if_important_data(const char *pstr, const char *end, bool count_spaces) { - THD *thd= get_thd(); - if ((pstr < end) && thd->count_cuted_fields) + THD *thd; + if ((pstr < end) && + (thd=get_thd())->count_cuted_fields) { if (test_if_important_data(field_charset, pstr, end)) { @@ -7114,7 +7112,8 @@ Field_longstr::report_if_important_data(const char *pstr, const char *end, return 2; } else if (count_spaces) - { /* If we lost only spaces then produce a NOTE, not a WARNING */ + { + /* If we lost only spaces then produce a NOTE, not a WARNING */ set_note(WARN_DATA_TRUNCATED, 1); return 2; } @@ -11054,13 +11053,17 @@ void Field::set_warning_truncated_wrong_value(const char *type_arg, const char *value) { THD *thd= get_thd(); - const char *db_name= table->s->db.str; - const char *table_name= table->s->table_name.str; + const char *db_name; + const char *table_name; + /* + table has in the past been 0 in case of wrong calls when processing + statistics tables. Let's protect against that. + */ + DBUG_ASSERT(table); - if (!db_name) - db_name= ""; - if (!table_name) - table_name= ""; + db_name= (table && table->s->db.str) ? table->s->db.str : ""; + table_name= (table && table->s->table_name.str) ? + table->s->table_name.str : ""; push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, -- cgit v1.2.1