Skip to content

Commit ab65db6

Browse files
committed
Revert "MDEV-10713: signal 11 error on multi-table update - crash in handler::increment_statistics or in make_select or assertion failure pfs_thread == ((PFS_thread*) pthread_getspecific((THR_PFS)))"
This reverts commit 035a5ac. Two minor problems and one regression: 1. caching the value in str_result. Other Item methods may use it, destroying the cache. See, for example, Item::save_in_field, where str_result is moved to use a local buffer (this failed main.grant) 2. Item_func_conv_charset::safe is now set too late, it's initialized only in val_str() but checked before that, this failed many tests in optimized builds. to fix 1 - use tmp_result instead of str_result, to fix 2, use the else branch in the Item_func_conv_charset constructor to set safe purely from charset properties. But this introduces a regression, constant strings can no longer be converted, say, from utf8 to latin1 (because 'safe' will be false). This fails few tests too. There is no way to fix it without reverting the commit and converting constants, as before, in the constructor.
1 parent f5e0522 commit ab65db6

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

sql/item_strfunc.cc

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,19 +2951,7 @@ String *Item_func_conv::val_str(String *str)
29512951
String *Item_func_conv_charset::val_str(String *str)
29522952
{
29532953
DBUG_ASSERT(fixed == 1);
2954-
if (cached_value == CONST_WILL_BE_CACHED)
2955-
{
2956-
uint errors= 0;
2957-
String tmp, *str= args[0]->val_str(&tmp);
2958-
if (!str || str_value.copy(str->ptr(), str->length(),
2959-
str->charset(), conv_charset, &errors))
2960-
null_value= 1;
2961-
cached_value= CACHED;
2962-
str_value.mark_as_const();
2963-
safe= (errors == 0);
2964-
is_expensive_cache= 0;
2965-
}
2966-
if (cached_value == CACHED)
2954+
if (use_cached_value)
29672955
return null_value ? 0 : &str_value;
29682956
String *arg= args[0]->val_str(str);
29692957
uint dummy_errors;

sql/item_strfunc.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -817,26 +817,31 @@ class Item_func_quote :public Item_str_func
817817

818818
class Item_func_conv_charset :public Item_str_func
819819
{
820+
bool use_cached_value;
820821
String tmp_value;
821-
enum state_of_cache { NOT_CONST, CONST_WILL_BE_CACHED, CACHED };
822-
enum state_of_cache cached_value;
823822
public:
824823
bool safe;
825824
CHARSET_INFO *conv_charset; // keep it public
826-
Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a),
827-
cached_value(NOT_CONST), safe(0), conv_charset(cs)
828-
{}
829-
Item_func_conv_charset(Item *a, CHARSET_INFO *cs, bool cache_if_const)
830-
:Item_str_func(a), conv_charset(cs)
825+
Item_func_conv_charset(Item *a, CHARSET_INFO *cs) :Item_str_func(a)
826+
{ conv_charset= cs; use_cached_value= 0; safe= 0; }
827+
Item_func_conv_charset(Item *a, CHARSET_INFO *cs, bool cache_if_const)
828+
:Item_str_func(a)
831829
{
832-
if (cache_if_const && args[0]->const_item())
830+
conv_charset= cs;
831+
if (cache_if_const && args[0]->const_item() && !args[0]->is_expensive())
833832
{
834-
is_expensive_cache= MY_TEST(args[0]->is_expensive());
835-
cached_value= CONST_WILL_BE_CACHED;
833+
uint errors= 0;
834+
String tmp, *str= args[0]->val_str(&tmp);
835+
if (!str || str_value.copy(str->ptr(), str->length(),
836+
str->charset(), conv_charset, &errors))
837+
null_value= 1;
838+
use_cached_value= 1;
839+
str_value.mark_as_const();
840+
safe= (errors == 0);
836841
}
837842
else
838843
{
839-
cached_value= NOT_CONST;
844+
use_cached_value= 0;
840845
/*
841846
Conversion from and to "binary" is safe.
842847
Conversion to Unicode is safe.
@@ -887,7 +892,6 @@ class Item_func_conv_charset :public Item_str_func
887892
void fix_length_and_dec();
888893
const char *func_name() const { return "convert"; }
889894
virtual void print(String *str, enum_query_type query_type);
890-
virtual bool const_item() const { return cached_value != NOT_CONST; }
891895
};
892896

893897
class Item_func_set_collation :public Item_str_func

0 commit comments

Comments
 (0)