Commit 451e9b7a authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-7499 - System variables have broken default values on big endian

INFORMATION_SCHEMA.SYSTEM_VARIABLES.DEFAULT_VALUE had broken values on
big endian.

Default value is internally stored as longlong, while I_S references it's
pointer (longlong *) according to variable type (e.g. int, my_bool, etc). This
works well on little endian, but on big endian we always get 0 for such
variables.
parent b08126aa
......@@ -2731,10 +2731,13 @@ public:
union
{
my_bool my_bool_value;
int int_value;
uint uint_value;
long long_value;
ulong ulong_value;
ulonglong ulonglong_value;
double double_value;
void *ptr_value;
} sys_var_tmp;
struct {
......
......@@ -3253,7 +3253,31 @@ sys_var_pluginvar::sys_var_pluginvar(sys_var_chain *chain, const char *name_arg,
uchar* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type)
{
if (type == OPT_DEFAULT)
return (uchar*)&option.def_value;
{
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
case PLUGIN_VAR_BOOL:
thd->sys_var_tmp.my_bool_value= option.def_value;
return (uchar*) &thd->sys_var_tmp.my_bool_value;
case PLUGIN_VAR_INT:
thd->sys_var_tmp.int_value= option.def_value;
return (uchar*) &thd->sys_var_tmp.int_value;
case PLUGIN_VAR_LONG:
case PLUGIN_VAR_ENUM:
thd->sys_var_tmp.long_value= option.def_value;
return (uchar*) &thd->sys_var_tmp.long_value;
case PLUGIN_VAR_LONGLONG:
case PLUGIN_VAR_SET:
return (uchar*) &option.def_value;
case PLUGIN_VAR_STR:
thd->sys_var_tmp.ptr_value= (void*) option.def_value;
return (uchar*) &thd->sys_var_tmp.ptr_value;
case PLUGIN_VAR_DOUBLE:
thd->sys_var_tmp.double_value= getopt_ulonglong2double(option.def_value);
return (uchar*) &thd->sys_var_tmp.double_value;
default:
DBUG_ASSERT(0);
}
}
DBUG_ASSERT(thd || (type == OPT_GLOBAL));
if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
......
......@@ -219,6 +219,7 @@ public:
return scope() == SESSION ? (T*)(((uchar*)&max_system_variables) + offset)
: 0;
}
uchar *default_value_ptr(THD *thd) { return (uchar*) &option.def_value; }
};
typedef Sys_var_integer<int, GET_INT, SHOW_SINT> Sys_var_int;
......@@ -229,6 +230,31 @@ typedef Sys_var_integer<ulonglong, GET_ULL, SHOW_ULONGLONG> Sys_var_ulonglong;
typedef Sys_var_integer<long, GET_LONG, SHOW_SLONG> Sys_var_long;
template<> uchar *Sys_var_int::default_value_ptr(THD *thd)
{
thd->sys_var_tmp.int_value= option.def_value;
return (uchar*) &thd->sys_var_tmp.int_value;
}
template<> uchar *Sys_var_uint::default_value_ptr(THD *thd)
{
thd->sys_var_tmp.uint_value= option.def_value;
return (uchar*) &thd->sys_var_tmp.uint_value;
}
template<> uchar *Sys_var_long::default_value_ptr(THD *thd)
{
thd->sys_var_tmp.long_value= option.def_value;
return (uchar*) &thd->sys_var_tmp.long_value;
}
template<> uchar *Sys_var_ulong::default_value_ptr(THD *thd)
{
thd->sys_var_tmp.ulong_value= option.def_value;
return (uchar*) &thd->sys_var_tmp.ulong_value;
}
/**
Helper class for variables that take values from a TYPELIB
*/
......@@ -386,6 +412,11 @@ public:
{ var->save_result.ulonglong_value= (ulonglong)*(my_bool *)global_value_ptr(thd, 0); }
void global_save_default(THD *thd, set_var *var)
{ var->save_result.ulonglong_value= option.def_value; }
uchar *default_value_ptr(THD *thd)
{
thd->sys_var_tmp.my_bool_value= option.def_value;
return (uchar*) &thd->sys_var_tmp.my_bool_value;
}
};
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment