25 #include <my_getopt.h>
28 #include "keycaches.h"
38 #define VALID_RANGE(X,Y) X,Y
40 #define BLOCK_SIZE(X) X
41 #define GLOBAL_VAR(X) sys_var::GLOBAL, (((char*)&(X))-(char*)&global_system_variables), sizeof(X)
42 #define SESSION_VAR(X) sys_var::SESSION, offsetof(SV, X), sizeof(((SV *)0)->X)
43 #define SESSION_ONLY(X) sys_var::ONLY_SESSION, offsetof(SV, X), sizeof(((SV *)0)->X)
44 #define NO_CMD_LINE CMD_LINE(NO_ARG, -1)
49 #define NO_MUTEX_GUARD ((PolyLock*)0)
50 #define IN_BINLOG sys_var::SESSION_VARIABLE_IN_BINLOG
51 #define NOT_IN_BINLOG sys_var::VARIABLE_NOT_IN_BINLOG
54 #define ON_UPDATE(X) X
55 #define READ_ONLY sys_var::READONLY+
56 #define NOT_VISIBLE sys_var::INVISIBLE+
58 #define PREALLOCATED sys_var::ALLOCATED+
63 #define REVERSE(X) ~(X)
64 #define DEPRECATED(X) X
66 #define session_var(THD, TYPE) (*(TYPE*)session_var_ptr(THD))
67 #define global_var(TYPE) (*(TYPE*)global_var_ptr())
69 #if SIZEOF_OFF_T > 4 && defined(BIG_TABLES)
70 #define GET_HA_ROWS GET_ULL
72 #define GET_HA_ROWS GET_ULONG
75 enum charset_enum {IN_SYSTEM_CHARSET, IN_FS_CHARSET};
77 static const char *bool_values[3]= {
"OFF",
"ON", 0};
87 enum get_opt_arg_type arg_type;
88 CMD_LINE(
enum get_opt_arg_type getopt_arg_type,
int getopt_id=0)
89 : id(getopt_id), arg_type(getopt_arg_type) {}
106 <
typename T, ulong ARGT,
enum enum_mysql_show_type SHOWT,
bool SIGNED>
111 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
113 T min_val, T max_val, T def_val, uint block_size,
PolyLock *lock=0,
115 on_check_function on_check_func=0,
116 on_update_function on_update_func=0,
117 const char *substitute=0,
118 int parse_flag= PARSE_NORMAL)
119 :
sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
120 getopt.arg_type, SHOWT, def_val, lock, binlog_status_arg,
121 on_check_func, on_update_func,
122 substitute, parse_flag)
125 option.min_value= min_val;
126 option.max_value= max_val;
127 option.block_size= block_size;
128 option.u_max_value= (uchar**)max_var_ptr();
130 *max_var_ptr()= max_val;
134 global_var(T)= def_val;
136 DBUG_ASSERT(size ==
sizeof(T));
137 DBUG_ASSERT(min_val < max_val);
138 DBUG_ASSERT(min_val <= def_val);
139 DBUG_ASSERT(max_val >= def_val);
140 DBUG_ASSERT(block_size > 0);
141 DBUG_ASSERT(def_val % block_size == 0);
143 bool do_check(THD *thd,
set_var *var)
145 my_bool fixed= FALSE;
149 v= var->
value->val_int();
152 if (var->
value->unsigned_flag)
164 uv= max_of_int_range(ARGT);
172 getopt_ll_limit_value(uv, &
option, &fixed);
176 if (var->
value->unsigned_flag)
187 uv= (ulonglong) (v < 0 ? 0 : v);
190 getopt_ull_limit_value(uv, &
option, &fixed);
198 longlong max_val= *max_var_ptr();
211 ulonglong max_val= *max_var_ptr();
217 return throw_bounds_warning(thd, name.str,
220 var->
value->unsigned_flag, v);
222 bool session_update(THD *thd,
set_var *var)
227 bool global_update(THD *thd,
set_var *var)
232 bool check_update_type(Item_result
type)
233 {
return type != INT_RESULT; }
235 { var->save_result.
ulonglong_value= (ulonglong)*(T*)global_value_ptr(thd, 0); }
241 return scope() == SESSION ? (T*)(((uchar*)&max_system_variables) +
offset)
264 const char *comment,
int flag_args, ptrdiff_t off,
266 SHOW_TYPE show_val_type_arg,
const char *values[],
269 on_check_function on_check_func, on_update_function on_update_func,
270 const char *substitute,
int parse_flag= PARSE_NORMAL)
271 :
sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
272 getopt.arg_type, show_val_type_arg, def_val, lock,
273 binlog_status_arg, on_check_func,
274 on_update_func, substitute, parse_flag)
276 for (typelib.count= 0; values[typelib.count]; typelib.count++) ;
278 typelib.type_names= values;
279 typelib.type_lengths= 0;
282 bool do_check(THD *thd,
set_var *var)
284 char buff[STRING_BUFFER_USUAL_SIZE];
285 String str(buff,
sizeof(buff), system_charset_info), *res;
287 if (var->
value->result_type() == STRING_RESULT)
289 if (!(res=var->
value->val_str(&str)))
293 find_type(&typelib, res->ptr(), res->length(),
false)))
300 longlong tmp=var->
value->val_int();
301 if (tmp < 0 || tmp >= typelib.count)
309 bool check_update_type(Item_result type)
310 {
return type != INT_RESULT && type != STRING_RESULT; }
331 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
333 const char *values[], uint def_val,
PolyLock *lock=0,
335 on_check_function on_check_func=0,
336 on_update_function on_update_func=0,
337 const char *substitute=0)
339 SHOW_CHAR, values, def_val, lock,
340 binlog_status_arg, on_check_func, on_update_func,
343 option.var_type= GET_ENUM;
344 global_var(ulong)= def_val;
345 DBUG_ASSERT(def_val < typelib.count);
346 DBUG_ASSERT(size ==
sizeof(ulong));
348 bool session_update(THD *thd,
set_var *var)
353 bool global_update(THD *thd,
set_var *var)
363 {
return (uchar*)typelib.type_names[session_var(thd, ulong)]; }
364 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
365 {
return (uchar*)typelib.type_names[global_var(ulong)]; }
378 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
382 on_check_function on_check_func=0,
383 on_update_function on_update_func=0,
384 const char *substitute=0,
385 int parse_flag= PARSE_NORMAL)
387 SHOW_MY_BOOL, bool_values, def_val, lock,
388 binlog_status_arg, on_check_func, on_update_func,
389 substitute, parse_flag)
391 option.var_type= GET_BOOL;
392 global_var(my_bool)= def_val;
393 DBUG_ASSERT(def_val < 2);
394 DBUG_ASSERT(getopt.arg_type == OPT_ARG || getopt.id == -1);
395 DBUG_ASSERT(size ==
sizeof(my_bool));
397 bool session_update(THD *thd,
set_var *var)
402 bool global_update(THD *thd,
set_var *var)
408 { var->save_result.
ulonglong_value= (ulonglong)*(my_bool *)global_value_ptr(thd, 0); }
433 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
435 enum charset_enum is_os_charset_arg,
436 const char *def_val,
PolyLock *lock=0,
438 on_check_function on_check_func=0,
439 on_update_function on_update_func=0,
440 const char *substitute=0,
441 int parse_flag= PARSE_NORMAL)
442 :
sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
443 getopt.arg_type, SHOW_CHAR_PTR, (intptr)def_val,
444 lock, binlog_status_arg, on_check_func, on_update_func,
445 substitute, parse_flag)
453 option.var_type= (
flags & ALLOCATED) ? GET_STR_ALLOC : GET_STR;
454 global_var(
const char*)= def_val;
455 DBUG_ASSERT(scope() == GLOBAL);
456 DBUG_ASSERT(size ==
sizeof(
char *));
460 if (
flags & ALLOCATED)
461 my_free(global_var(
char*));
464 bool do_check(THD *thd,
set_var *var)
466 char buff[STRING_BUFFER_USUAL_SIZE], buff2[STRING_BUFFER_USUAL_SIZE];
467 String str(buff,
sizeof(buff), charset(thd));
468 String str2(buff2,
sizeof(buff2), charset(thd)), *res;
470 if (!(res=var->
value->val_str(&str)))
475 if (String::needs_conversion(res->length(), res->charset(),
476 charset(thd), &unused))
479 str2.copy(res->ptr(), res->length(), res->charset(), charset(thd),
484 var->save_result.
string_value.str= thd->strmake(res->ptr(), res->length());
490 bool session_update(THD *thd,
set_var *var)
495 bool global_update(THD *thd,
set_var *var)
501 new_val= (
char*)my_memdup(ptr, len+1, MYF(MY_WME));
502 if (!new_val)
return true;
507 if (
flags & ALLOCATED)
508 my_free(global_var(
char*));
510 global_var(
char*)= new_val;
514 { DBUG_ASSERT(FALSE); }
517 char *ptr= (
char*)(intptr)
option.def_value;
519 var->save_result.
string_value.length= ptr ? strlen(ptr) : 0;
521 bool check_update_type(Item_result type)
522 {
return type != STRING_RESULT; }
530 const char *comment,
enum charset_enum is_os_charset_arg)
531 :
sys_var(&all_sys_vars, name_arg, comment,
532 sys_var::READONLY+sys_var::ONLY_SESSION, 0, -1,
533 NO_ARG, SHOW_CHAR, 0, NULL, VARIABLE_NOT_IN_BINLOG,
534 NULL, NULL, NULL, PARSE_NORMAL)
539 bool do_check(THD *thd,
set_var *var)
544 bool session_update(THD *thd,
set_var *var)
549 bool global_update(THD *thd,
set_var *var)
555 { DBUG_ASSERT(FALSE); }
557 { DBUG_ASSERT(FALSE); }
558 bool check_update_type(Item_result type)
563 return thd->security_ctx->proxy_user[0] ?
564 (uchar *) &(thd->security_ctx->proxy_user[0]) : NULL;
572 enum charset_enum is_os_charset_arg)
579 return thd->security_ctx->proxy_user[0] ?
580 (uchar *) &(thd->security_ctx->proxy_user[0]) : NULL;
600 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
602 enum charset_enum is_os_charset_arg,
603 const char *def_val,
PolyLock *lock=0,
605 on_check_function on_check_func=0,
606 on_update_function on_update_func=0,
607 const char *substitute=0)
609 getopt, is_os_charset_arg, def_val, lock, binlog_status_arg,
610 on_check_func, on_update_func, substitute)
612 global_var(
LEX_STRING).length= strlen(def_val);
616 bool global_update(THD *thd,
set_var *var)
618 if (Sys_var_charptr::global_update(thd, var))
641 const char *comment,
int flag_args,
643 const char *def_val,
PolyLock *lock=0,
645 on_check_function on_check_func=0,
646 on_update_function on_update_func=0,
647 const char *substitute=0,
648 int parse_flag= PARSE_NORMAL)
649 :
sys_var(&all_sys_vars, name_arg, comment, flag_args, 0, getopt.id,
650 getopt.arg_type, SHOW_CHAR, (intptr)def_val,
651 lock, binlog_status_arg, on_check_func, on_update_func,
652 substitute, parse_flag)
653 {
option.var_type= GET_NO_ARG; }
654 bool do_check(THD *thd,
set_var *var)
656 char buff[STRING_BUFFER_USUAL_SIZE];
657 String str(buff,
sizeof(buff), system_charset_info), *res;
659 if (!(res=var->
value->val_str(&str)))
660 var->save_result.
string_value.str=
const_cast<char*
>(
"");
662 var->save_result.
string_value.str= thd->strmake(res->ptr(), res->length());
665 bool session_update(THD *thd,
set_var *var)
674 bool global_update(THD *thd,
set_var *var)
677 DBUG_SET_INITIAL(val);
684 char *ptr= (
char*)(intptr)
option.def_value;
690 DBUG_EXPLAIN(buf,
sizeof(buf));
691 return (uchar*) thd->strdup(buf);
693 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
696 DBUG_EXPLAIN_INITIAL(buf,
sizeof(buf));
697 return (uchar*) thd->strdup(buf);
699 bool check_update_type(Item_result type)
700 {
return type != STRING_RESULT; }
704 #define KEYCACHE_VAR(X) sys_var::GLOBAL,offsetof(KEY_CACHE, X), sizeof(((KEY_CACHE *)0)->X)
705 #define keycache_var_ptr(KC, OFF) (((uchar*)(KC))+(OFF))
706 #define keycache_var(KC, OFF) (*(ulonglong*)keycache_var_ptr(KC, OFF))
707 typedef bool (*keycache_update_function)(THD *,
KEY_CACHE *, ptrdiff_t, ulonglong);
722 keycache_update_function keycache_update;
725 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
727 ulonglong min_val, ulonglong max_val, ulonglong def_val,
728 ulonglong block_size,
PolyLock *lock,
730 on_check_function on_check_func,
731 keycache_update_function on_update_func,
732 const char *substitute=0)
733 : Sys_var_ulonglong(name_arg, comment, flag_args,
736 getopt, min_val, max_val, def_val,
737 block_size, lock, binlog_status_arg, on_check_func, 0,
739 keycache_update(on_update_func)
742 option.var_type|= GET_ASK_ADDR;
744 keycache_var(dflt_key_cache, off)= def_val;
745 DBUG_ASSERT(scope() == GLOBAL);
751 KEY_CACHE *key_cache;
754 if (!base_name->length)
755 base_name= &default_key_cache_base;
757 key_cache= get_key_cache(base_name);
763 if (!(key_cache= create_key_cache(base_name->str, base_name->length)))
772 if (key_cache->in_init)
775 return keycache_update(thd, key_cache,
offset, new_value);
777 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
779 KEY_CACHE *key_cache= get_key_cache(base);
781 key_cache= &zero_key_cache;
782 return keycache_var_ptr(key_cache,
offset);
797 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
799 double min_val,
double max_val,
double def_val,
PolyLock *lock=0,
801 on_check_function on_check_func=0,
802 on_update_function on_update_func=0,
803 const char *substitute=0,
804 int parse_flag= PARSE_NORMAL)
805 :
sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
806 getopt.arg_type, SHOW_DOUBLE,
807 (longlong) getopt_double2ulonglong(def_val),
808 lock, binlog_status_arg, on_check_func, on_update_func,
809 substitute, parse_flag)
811 option.var_type= GET_DOUBLE;
812 option.min_value= (longlong) getopt_double2ulonglong(min_val);
813 option.max_value= (longlong) getopt_double2ulonglong(max_val);
814 global_var(
double)= (double)
option.def_value;
815 DBUG_ASSERT(min_val <= max_val);
816 DBUG_ASSERT(min_val <= def_val);
817 DBUG_ASSERT(max_val >= def_val);
818 DBUG_ASSERT(size ==
sizeof(
double));
820 bool do_check(THD *thd,
set_var *var)
823 double v= var->
value->val_real();
826 return throw_bounds_warning(thd, name.str, fixed, v);
828 bool session_update(THD *thd,
set_var *var)
830 session_var(thd,
double)= var->save_result.
double_value;
833 bool global_update(THD *thd,
set_var *var)
838 bool check_update_type(Item_result type)
840 return type != INT_RESULT && type != REAL_RESULT && type != DECIMAL_RESULT;
861 my_bool test_flag_value;
865 :
Sys_var_mybool(name_arg, comment, READ_ONLY GLOBAL_VAR(test_flag_value),
866 NO_CMD_LINE, DEFAULT(FALSE))
868 test_flag_mask= mask;
870 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
872 test_flag_value= ((test_flags & test_flag_mask) > 0);
873 return (uchar*) &test_flag_value;
891 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
893 uint min_val, uint max_val, uint def_val,
896 on_check_function on_check_func=0,
897 on_update_function on_update_func=0,
898 const char *substitute=0)
899 : Sys_var_uint(name_arg, comment, SESSION, off, size, getopt,
900 min_val, max_val, def_val, block_size,
901 lock, binlog_status_arg, on_check_func, on_update_func,
906 const USER_CONN *uc= thd->get_user_connect();
907 if (uc && uc->user_resources.user_conn)
908 return (uchar*) &(uc->user_resources.user_conn);
909 return global_value_ptr(thd, base);
914 #define MAX_SET(X) ((((1UL << ((X)-1))-1) << 1) | 1)
934 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
936 const char *values[], ulonglong def_val,
PolyLock *lock=0,
938 on_check_function on_check_func=0,
939 on_update_function on_update_func=0,
940 const char *substitute=0)
942 SHOW_CHAR, values, def_val, lock,
943 binlog_status_arg, on_check_func, on_update_func,
946 option.var_type= GET_FLAGSET;
947 global_var(ulonglong)= def_val;
948 DBUG_ASSERT(typelib.count > 1);
949 DBUG_ASSERT(typelib.count <= 65);
950 DBUG_ASSERT(def_val < MAX_SET(typelib.count));
951 DBUG_ASSERT(strcmp(values[typelib.count-1],
"default") == 0);
952 DBUG_ASSERT(size ==
sizeof(ulonglong));
954 bool do_check(THD *thd,
set_var *var)
956 char buff[STRING_BUFFER_USUAL_SIZE];
957 String str(buff,
sizeof(buff), system_charset_info), *res;
958 ulonglong default_value, current_value;
959 if (var->type == OPT_GLOBAL)
961 default_value=
option.def_value;
962 current_value= global_var(ulonglong);
966 default_value= global_var(ulonglong);
967 current_value= session_var(thd, ulonglong);
970 if (var->
value->result_type() == STRING_RESULT)
972 if (!(res=var->
value->val_str(&str)))
980 find_set_from_flags(&typelib,
984 res->ptr(), res->length(),
989 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.str, err.ptr());
996 longlong tmp=var->
value->val_int();
997 if ((tmp < 0 && ! var->value->unsigned_flag)
998 || (ulonglong)tmp > MAX_SET(typelib.count))
1006 bool session_update(THD *thd,
set_var *var)
1011 bool global_update(THD *thd,
set_var *var)
1022 return (uchar*)flagset_to_string(thd, 0, session_var(thd, ulonglong),
1023 typelib.type_names);
1025 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
1027 return (uchar*)flagset_to_string(thd, 0, global_var(ulonglong),
1028 typelib.type_names);
1045 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
1047 const char *values[], ulonglong def_val,
PolyLock *lock=0,
1049 on_check_function on_check_func=0,
1050 on_update_function on_update_func=0,
1051 const char *substitute=0)
1053 SHOW_CHAR, values, def_val, lock,
1054 binlog_status_arg, on_check_func, on_update_func,
1057 option.var_type= GET_SET;
1058 global_var(ulonglong)= def_val;
1059 DBUG_ASSERT(typelib.count > 0);
1060 DBUG_ASSERT(typelib.count <= 64);
1061 DBUG_ASSERT(def_val < MAX_SET(typelib.count));
1062 DBUG_ASSERT(size ==
sizeof(ulonglong));
1064 bool do_check(THD *thd,
set_var *var)
1066 char buff[STRING_BUFFER_USUAL_SIZE];
1067 String str(buff,
sizeof(buff), system_charset_info), *res;
1069 if (var->
value->result_type() == STRING_RESULT)
1071 if (!(res=var->
value->val_str(&str)))
1080 find_set(&typelib, res->ptr(), res->length(), NULL,
1081 &error, &error_len, ¬_used);
1090 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.str, err.ptr());
1097 longlong tmp=var->
value->val_int();
1098 if ((tmp < 0 && ! var->value->unsigned_flag)
1099 || (ulonglong)tmp > MAX_SET(typelib.count))
1107 bool session_update(THD *thd,
set_var *var)
1112 bool global_update(THD *thd,
set_var *var)
1123 return (uchar*)set_to_string(thd, 0, session_var(thd, ulonglong),
1124 typelib.type_names);
1126 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
1128 return (uchar*)set_to_string(thd, 0, global_var(ulonglong),
1129 typelib.type_names);
1151 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
1153 int plugin_type_arg,
char **def_val,
PolyLock *lock=0,
1155 on_check_function on_check_func=0,
1156 on_update_function on_update_func=0,
1157 const char *substitute=0,
1158 int parse_flag= PARSE_NORMAL)
1159 :
sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
1160 getopt.arg_type, SHOW_CHAR, (intptr)def_val,
1161 lock, binlog_status_arg, on_check_func, on_update_func,
1162 substitute, parse_flag),
1163 plugin_type(plugin_type_arg)
1165 option.var_type= GET_STR;
1167 DBUG_ASSERT(getopt.id == -1);
1169 bool do_check(THD *thd,
set_var *var)
1171 char buff[STRING_BUFFER_USUAL_SIZE];
1172 String str(buff,
sizeof(buff), system_charset_info), *res;
1173 if (!(res=var->
value->val_str(&str)))
1174 var->save_result.
plugin= NULL;
1177 const LEX_STRING pname= {
const_cast<char*
>(res->ptr()), res->length() };
1181 if (plugin_type == MYSQL_STORAGE_ENGINE_PLUGIN)
1184 plugin= my_plugin_lock_by_name(thd, &pname, plugin_type);
1188 if (plugin_type == MYSQL_STORAGE_ENGINE_PLUGIN)
1191 my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), err.ptr());
1195 var->save_result.
plugin= plugin;
1202 if (oldval != newval)
1204 *valptr= my_plugin_lock(NULL, &newval);
1205 plugin_unlock(NULL, oldval);
1208 bool session_update(THD *thd,
set_var *var)
1211 var->save_result.
plugin);
1214 bool global_update(THD *thd,
set_var *var)
1217 var->save_result.
plugin);
1223 var->save_result.
plugin= my_plugin_lock(thd, &plugin);
1228 char **default_value=
reinterpret_cast<char**
>(
option.def_value);
1229 pname.str= *default_value;
1230 pname.length= strlen(pname.str);
1233 if (plugin_type == MYSQL_STORAGE_ENGINE_PLUGIN)
1236 plugin= my_plugin_lock_by_name(thd, &pname, plugin_type);
1237 DBUG_ASSERT(plugin);
1239 var->save_result.
plugin= my_plugin_lock(thd, &plugin);
1241 bool check_update_type(Item_result type)
1242 {
return type != STRING_RESULT; }
1246 return (uchar*)(plugin ? thd->strmake(plugin_name(plugin)->str,
1247 plugin_name(plugin)->length) : 0);
1249 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
1252 return (uchar*)(plugin ? thd->strmake(plugin_name(plugin)->str,
1253 plugin_name(plugin)->length) : 0);
1257 #if defined(ENABLED_DEBUG_SYNC)
1261 class Sys_var_debug_sync :
public sys_var
1264 Sys_var_debug_sync(
const char *name_arg,
1265 const char *comment,
int flag_args,
1267 const char *def_val,
PolyLock *lock=0,
1268 enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
1269 on_check_function on_check_func=0,
1270 on_update_function on_update_func=0,
1271 const char *substitute=0,
1272 int parse_flag= PARSE_NORMAL)
1273 :
sys_var(&all_sys_vars, name_arg, comment, flag_args, 0, getopt.
id,
1274 getopt.arg_type, SHOW_CHAR, (intptr)def_val,
1275 lock, binlog_status_arg, on_check_func, on_update_func,
1276 substitute, parse_flag)
1278 DBUG_ASSERT(scope() == ONLY_SESSION);
1279 option.var_type= GET_NO_ARG;
1281 bool do_check(THD *thd,
set_var *var)
1283 char buff[STRING_BUFFER_USUAL_SIZE];
1284 String str(buff,
sizeof(buff), system_charset_info), *res;
1286 if (!(res=var->
value->val_str(&str)))
1287 var->save_result.
string_value.str=
const_cast<char*
>(
"");
1289 var->save_result.
string_value.str= thd->strmake(res->ptr(), res->length());
1292 bool session_update(THD *thd,
set_var *var)
1294 extern bool debug_sync_update(THD *thd,
char *val_str);
1295 return debug_sync_update(thd, var->save_result.
string_value.str);
1297 bool global_update(THD *thd,
set_var *var)
1302 void session_save_default(THD *thd,
set_var *var)
1304 var->save_result.
string_value.str=
const_cast<char*
>(
"");
1307 void global_save_default(THD *thd,
set_var *var)
1313 extern uchar *debug_sync_value_ptr(THD *thd);
1314 return debug_sync_value_ptr(thd);
1316 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
1321 bool check_update_type(Item_result type)
1322 {
return type != STRING_RESULT; }
1348 bool reverse_semantics;
1349 void set(uchar *ptr, ulonglong value)
1351 if ((value != 0) ^ reverse_semantics)
1352 (*(ulonglong *)ptr)|= bitmask;
1354 (*(ulonglong *)ptr)&= ~bitmask;
1358 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
1360 ulonglong bitmask_arg, my_bool def_val,
PolyLock *lock=0,
1362 on_check_function on_check_func=0,
1363 on_update_function on_update_func=0,
1364 const char *substitute=0)
1366 SHOW_MY_BOOL, bool_values, def_val, lock,
1367 binlog_status_arg, on_check_func, on_update_func,
1370 option.var_type= GET_BOOL;
1371 reverse_semantics= my_count_bits(bitmask_arg) > 1;
1372 bitmask= reverse_semantics ? ~bitmask_arg : bitmask_arg;
1373 set(global_var_ptr(), def_val);
1374 DBUG_ASSERT(def_val < 2);
1375 DBUG_ASSERT(getopt.id == -1);
1376 DBUG_ASSERT(size ==
sizeof(ulonglong));
1378 bool session_update(THD *thd,
set_var *var)
1383 bool global_update(THD *thd,
set_var *var)
1389 { var->save_result.
ulonglong_value= global_var(ulonglong) & bitmask; }
1394 thd->sys_var_tmp.my_bool_value= reverse_semantics ^
1395 ((session_var(thd, ulonglong) & bitmask) != 0);
1396 return (uchar*) &thd->sys_var_tmp.my_bool_value;
1398 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
1400 thd->sys_var_tmp.my_bool_value= reverse_semantics ^
1401 ((global_var(ulonglong) & bitmask) != 0);
1402 return (uchar*) &thd->sys_var_tmp.my_bool_value;
1423 typedef bool (*session_special_update_function)(THD *thd,
set_var *var);
1424 typedef ulonglong (*session_special_read_function)(THD *thd);
1426 session_special_read_function read_func;
1427 session_special_update_function update_func;
1430 const char *comment,
int flag_args,
1432 ulonglong min_val, ulonglong max_val, ulonglong block_size,
1434 on_check_function on_check_func,
1435 session_special_update_function update_func_arg,
1436 session_special_read_function read_func_arg,
1437 const char *substitute=0)
1438 : Sys_var_ulonglong(name_arg, comment, flag_args, 0,
1439 sizeof(ulonglong), getopt, min_val,
1440 max_val, 0, block_size, lock, binlog_status_arg, on_check_func, 0,
1442 read_func(read_func_arg), update_func(update_func_arg)
1444 DBUG_ASSERT(scope() == ONLY_SESSION);
1445 DBUG_ASSERT(getopt.id == -1);
1447 bool session_update(THD *thd,
set_var *var)
1448 {
return update_func(thd, var); }
1449 bool global_update(THD *thd,
set_var *var)
1457 { DBUG_ASSERT(FALSE); }
1460 thd->sys_var_tmp.ulonglong_value= read_func(thd);
1461 return (uchar*) &thd->sys_var_tmp.ulonglong_value;
1463 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
1476 typedef bool (*session_special_update_function)(THD *thd,
set_var *var);
1477 typedef double (*session_special_read_double_function)(THD *thd);
1479 session_special_read_double_function read_func;
1480 session_special_update_function update_func;
1483 const char *comment,
int flag_args,
1485 ulonglong min_val, ulonglong max_val, ulonglong block_size,
1487 on_check_function on_check_func,
1488 session_special_update_function update_func_arg,
1489 session_special_read_double_function read_func_arg,
1490 const char *substitute=0)
1492 sizeof(
double), getopt,
1493 min_val, max_val, 0,
1494 lock, binlog_status_arg, on_check_func, 0,
1496 read_func(read_func_arg), update_func(update_func_arg)
1498 DBUG_ASSERT(scope() == ONLY_SESSION);
1499 DBUG_ASSERT(getopt.id == -1);
1501 bool session_update(THD *thd,
set_var *var)
1502 {
return update_func(thd, var); }
1503 bool global_update(THD *thd,
set_var *var)
1511 { DBUG_ASSERT(FALSE); }
1514 thd->sys_var_tmp.double_value= read_func(thd);
1515 return (uchar *) &thd->sys_var_tmp.double_value;
1517 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
1539 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
1543 on_check_function on_check_func=0,
1544 on_update_function on_update_func=0,
1545 const char *substitute=0,
1546 int parse_flag= PARSE_NORMAL)
1547 :
sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
1548 getopt.arg_type, SHOW_CHAR, 0,
1549 lock, binlog_status_arg, on_check_func, on_update_func,
1550 substitute, parse_flag)
1552 DBUG_ASSERT(scope() == GLOBAL);
1553 DBUG_ASSERT(getopt.id == -1);
1554 DBUG_ASSERT(lock == 0);
1555 DBUG_ASSERT(binlog_status_arg == VARIABLE_NOT_IN_BINLOG);
1556 DBUG_ASSERT(is_readonly());
1557 DBUG_ASSERT(on_update == 0);
1558 DBUG_ASSERT(size ==
sizeof(
enum SHOW_COMP_OPTION));
1560 bool do_check(THD *thd,
set_var *var) {
1564 bool session_update(THD *thd,
set_var *var)
1569 bool global_update(THD *thd,
set_var *var)
1581 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
1583 return (uchar*)show_comp_option_name[global_var(
enum SHOW_COMP_OPTION)];
1585 bool check_update_type(Item_result type) {
return false; }
1605 ptrdiff_t name_offset;
1608 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
1610 ptrdiff_t name_off,
void *def_val,
PolyLock *lock=0,
1612 on_check_function on_check_func=0,
1613 on_update_function on_update_func=0,
1614 const char *substitute=0,
1615 int parse_flag= PARSE_NORMAL)
1616 :
sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
1617 getopt.arg_type, SHOW_CHAR, (intptr)def_val,
1618 lock, binlog_status_arg, on_check_func, on_update_func,
1619 substitute, parse_flag),
1620 name_offset(name_off)
1622 option.var_type= GET_STR;
1631 DBUG_ASSERT(getopt.id == -1);
1632 DBUG_ASSERT(size ==
sizeof(
void *));
1634 bool do_check(THD *thd,
set_var *var)
1636 bool session_update(THD *thd,
set_var *var)
1638 session_var(thd,
const void*)= var->save_result.
ptr;
1641 bool global_update(THD *thd,
set_var *var)
1643 global_var(
const void*)= var->save_result.
ptr;
1647 { var->save_result.
ptr= global_var(
void*); }
1650 void **default_value=
reinterpret_cast<void**
>(
option.def_value);
1651 var->save_result.
ptr= *default_value;
1653 bool check_update_type(Item_result type)
1654 {
return type != INT_RESULT && type != STRING_RESULT; }
1657 uchar *ptr= session_var(thd, uchar*);
1658 return ptr ? *(uchar**)(ptr+name_offset) : 0;
1660 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
1662 uchar *ptr= global_var(uchar*);
1663 return ptr ? *(uchar**)(ptr+name_offset) : 0;
1681 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
1685 on_check_function on_check_func=0,
1686 on_update_function on_update_func=0,
1687 const char *substitute=0,
1688 int parse_flag= PARSE_NORMAL)
1689 :
sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
1690 getopt.arg_type, SHOW_CHAR, (intptr)def_val,
1691 lock, binlog_status_arg, on_check_func, on_update_func,
1692 substitute, parse_flag)
1694 DBUG_ASSERT(getopt.id == -1);
1695 DBUG_ASSERT(size ==
sizeof(
Time_zone *));
1697 bool do_check(THD *thd,
set_var *var)
1700 String str(buff,
sizeof(buff), &my_charset_latin1);
1706 if (!(var->save_result.
time_zone= my_tz_find(thd, res)))
1709 my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), err.ptr());
1714 bool session_update(THD *thd,
set_var *var)
1719 bool global_update(THD *thd,
set_var *var)
1743 thd->time_zone_used= 1;
1744 return (uchar *)(session_var(thd,
Time_zone*)->get_name()->ptr());
1746 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
1748 return (uchar *)(global_var(
Time_zone*)->get_name()->ptr());
1750 bool check_update_type(Item_result type)
1751 {
return type != STRING_RESULT; }
1759 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
1761 const char *values[], uint def_val,
PolyLock *lock,
1763 on_check_function on_check_func)
1764 :
Sys_var_enum(name_arg, comment, flag_args, off, size, getopt,
1765 values, def_val, lock, binlog_status_arg, on_check_func)
1767 virtual bool session_update(THD *thd,
set_var *var);
1784 ptrdiff_t off,
size_t size,
CMD_LINE getopt,
1787 on_check_function on_check_func)
1789 def_val, lock, binlog_status_arg, on_check_func)
1791 virtual bool session_update(THD *thd,
set_var *var);
1803 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
1805 const char *values[], uint def_val,
PolyLock *lock,
1807 :
Sys_var_enum(name_arg, comment, flag_args, off, size, getopt,
1808 values, def_val, lock, binlog_status_arg, NULL)
1810 virtual bool global_update(THD *thd,
set_var *var);
1821 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
1823 const char *def_val,
1826 on_check_function on_check_func=0,
1827 on_update_function on_update_func=0,
1828 const char *substitute=0,
1829 int parse_flag= PARSE_NORMAL)
1830 :
sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
1831 getopt.arg_type, SHOW_CHAR, (intptr)def_val,
1832 lock, binlog_status_arg, on_check_func, on_update_func,
1833 substitute, parse_flag)
1837 bool session_update(THD *thd,
set_var *var)
1839 DBUG_ENTER(
"Sys_var_gtid::session_update");
1840 global_sid_lock->
rdlock();
1842 parse(global_sid_map,
1844 global_sid_lock->
unlock();
1847 bool global_update(THD *thd,
set_var *var)
1848 { DBUG_ASSERT(FALSE);
return true; }
1851 DBUG_ENTER(
"Sys_var_gtid::session_save_default");
1852 char *ptr= (
char*)(intptr)
option.def_value;
1854 var->save_result.
string_value.length= ptr ? strlen(ptr) : 0;
1858 { DBUG_ASSERT(FALSE); }
1859 bool do_check(THD *thd,
set_var *var)
1861 DBUG_ENTER(
"Sys_var_gtid::do_check");
1862 char buf[Gtid_specification::MAX_TEXT_LENGTH + 1];
1863 String str(buf,
sizeof(buf), &my_charset_latin1);
1867 var->save_result.
string_value.str= thd->strmake(res->c_ptr_safe(), res->length());
1870 my_error(ER_OUT_OF_RESOURCES, MYF(0));
1875 DBUG_PRINT(
"info", (
"ret=%d", ret));
1878 bool check_update_type(Item_result type)
1879 {
return type != STRING_RESULT; }
1882 DBUG_ENTER(
"Sys_var_gtid::session_value_ptr");
1883 char buf[Gtid_specification::MAX_TEXT_LENGTH + 1];
1884 global_sid_lock->
rdlock();
1886 to_string(global_sid_map, buf);
1887 global_sid_lock->
unlock();
1888 char *ret= thd->strdup(buf);
1889 DBUG_RETURN((uchar *)ret);
1891 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
1892 { DBUG_ASSERT(FALSE);
return NULL; }
1895 #ifdef HAVE_GTID_NEXT_LIST
1903 class Sys_var_gtid_set:
public sys_var
1906 Sys_var_gtid_set(
const char *name_arg,
1907 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
1909 const char *def_val,
1911 enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
1912 on_check_function on_check_func=0,
1913 on_update_function on_update_func=0,
1914 const char *substitute=0,
1915 int parse_flag= PARSE_NORMAL)
1916 :
sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.
id,
1917 getopt.arg_type, SHOW_CHAR, (intptr)def_val,
1918 lock, binlog_status_arg, on_check_func, on_update_func,
1919 substitute, parse_flag)
1923 bool session_update(THD *thd,
set_var *var)
1925 DBUG_ENTER(
"Sys_var_gtid_set::session_update");
1936 my_error(ER_OUT_OF_RESOURCES, MYF(0));
1943 while (isspace(*value))
1950 global_sid_lock->
rdlock();
1952 global_sid_lock->
unlock();
1953 if (ret != RETURN_STATUS_OK)
1961 bool global_update(THD *thd,
set_var *var)
1962 { DBUG_ASSERT(FALSE);
return true; }
1963 void session_save_default(THD *thd,
set_var *var)
1965 DBUG_ENTER(
"Sys_var_gtid_set::session_save_default");
1966 char *ptr= (
char*)(intptr)
option.def_value;
1968 var->save_result.
string_value.length= ptr ? strlen(ptr) : 0;
1971 void global_save_default(THD *thd,
set_var *var)
1972 { DBUG_ASSERT(FALSE); }
1973 bool do_check(THD *thd,
set_var *var)
1975 DBUG_ENTER(
"Sys_var_gtid_set::do_check");
1983 DBUG_ASSERT(res->ptr() != NULL);
1984 var->save_result.
string_value.str= thd->strmake(res->ptr(), res->length());
1987 my_error(ER_OUT_OF_RESOURCES, MYF(0));
1994 bool check_update_type(Item_result type)
1995 {
return type != STRING_RESULT; }
1998 DBUG_ENTER(
"Sys_var_gtid_set::session_value_ptr");
2004 global_sid_lock->
rdlock();
2009 my_error(ER_OUT_OF_RESOURCES, MYF(0));
2010 global_sid_lock->
unlock();
2011 DBUG_RETURN((uchar *)buf);
2013 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
2014 { DBUG_ASSERT(FALSE);
return NULL; }
2030 :
sys_var(&all_sys_vars, name_arg, comment, READ_ONLY flag_arg,
2031 0, NO_CMD_LINE.id, NO_CMD_LINE.arg_type,
2032 SHOW_CHAR, (intptr)0,
2033 NULL, VARIABLE_NOT_IN_BINLOG,
2037 DBUG_ASSERT(flag_arg == sys_var::GLOBAL || flag_arg == sys_var::SESSION ||
2038 flag_arg == sys_var::ONLY_SESSION);
2040 bool session_update(THD *thd,
set_var *var)
2041 { DBUG_ASSERT(FALSE);
return true; }
2042 bool global_update(THD *thd,
set_var *var)
2043 { DBUG_ASSERT(FALSE);
return true; }
2046 bool do_check(THD *thd,
set_var *var) { DBUG_ASSERT(FALSE);
return true; }
2047 bool check_update_type(Item_result type) { DBUG_ASSERT(FALSE);
return true; }
2049 { DBUG_ASSERT(FALSE);
return NULL; }
2050 virtual uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
2051 { DBUG_ASSERT(FALSE);
return NULL; }
2068 typedef enum_return_status (*Gtid_set_getter)(THD *,
Gtid_set *);
2070 static uchar *get_string_from_gtid_set(THD *thd,
2071 Gtid_set_getter get_gtid_set)
2073 DBUG_ENTER(
"Sys_var_gtid_ended_groups::session_value_ptr");
2080 global_sid_lock->
wrlock();
2081 if (get_gtid_set(thd, &gs) != RETURN_STATUS_OK)
2087 my_error(ER_OUT_OF_RESOURCES, MYF(0));
2091 global_sid_lock->
unlock();
2092 DBUG_RETURN((uchar *)buf);
2094 global_sid_lock->
unlock();
2109 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
2111 DBUG_ENTER(
"Sys_var_gtid_executed::global_value_ptr");
2112 global_sid_lock->
wrlock();
2116 my_error(ER_OUT_OF_RESOURCES, MYF(0));
2119 global_sid_lock->
unlock();
2120 DBUG_RETURN((uchar *)buf);
2124 static enum_return_status get_groups_from_trx_cache(THD *thd,
Gtid_set *gs)
2126 DBUG_ENTER(
"Sys_var_gtid_executed::get_groups_from_trx_cache");
2129 thd->binlog_setup_trx_data();
2130 PROPAGATE_REPORTED_ERROR(thd->get_group_cache(
true)->get_gtids(gs));
2136 uchar *session_value_ptr(THD *thd,
LEX_STRING *base)
2138 return get_string_from_gtid_set(thd, get_groups_from_trx_cache);
2150 const char *comment,
int flag_args, ptrdiff_t off,
size_t size,
2152 const char *def_val,
2155 on_check_function on_check_func=0,
2156 on_update_function on_update_func=0,
2157 const char *substitute=0,
2158 int parse_flag= PARSE_NORMAL)
2159 :
sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
2160 getopt.arg_type, SHOW_CHAR, (intptr)def_val,
2161 lock, binlog_status_arg, on_check_func, on_update_func,
2162 substitute, parse_flag)
2165 bool session_update(THD *thd,
set_var *var)
2172 { DBUG_ASSERT(FALSE); }
2174 bool global_update(THD *thd,
set_var *var)
2176 DBUG_ENTER(
"Sys_var_gtid_purged::global_update");
2177 #ifdef HAVE_REPLICATION
2181 global_sid_lock->
wrlock();
2187 global_sid_lock->
unlock();
2188 if (RETURN_STATUS_OK != ret)
2195 sql_print_information(ER(ER_GTID_PURGED_WAS_CHANGED),
2196 previous_gtid_lost, current_gtid_lost);
2197 sql_print_information(ER(ER_GTID_EXECUTED_WAS_CHANGED),
2198 previous_gtid_logged, current_gtid_logged);
2209 my_free(previous_gtid_logged);
2210 my_free(previous_gtid_lost);
2211 my_free(current_gtid_logged);
2212 my_free(current_gtid_lost);
2222 my_error(ER_NO_DEFAULT, MYF(0), var->
var->name.str);
2225 bool do_check(THD *thd,
set_var *var)
2227 DBUG_ENTER(
"Sys_var_gtid_purged::do_check");
2229 String str(buf,
sizeof(buf), system_charset_info);
2233 var->save_result.
string_value.str= thd->strmake(res->c_ptr_safe(),
2237 my_error(ER_OUT_OF_RESOURCES, MYF(0));
2242 DBUG_PRINT(
"info", (
"ret=%d", ret));
2246 bool check_update_type(Item_result type)
2247 {
return type != STRING_RESULT; }
2249 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
2251 DBUG_ENTER(
"Sys_var_gtid_purged::global_value_ptr");
2252 global_sid_lock->
wrlock();
2256 my_error(ER_OUT_OF_RESOURCES, MYF(0));
2259 global_sid_lock->
unlock();
2260 DBUG_RETURN((uchar *)buf);
2264 { DBUG_ASSERT(0);
return NULL; }
2275 uchar *session_value_ptr(THD *thd,
LEX_STRING *base)
2277 DBUG_ENTER(
"Sys_var_gtid_owned::session_value_ptr");
2279 if (thd->owned_gtid.sidno == 0)
2280 DBUG_RETURN((uchar *)thd->strdup(
""));
2281 if (thd->owned_gtid.sidno == -1)
2283 #ifdef HAVE_GTID_NEXT_LIST
2284 buf= (
char *)thd->alloc(thd->owned_gtid_set.get_string_length() + 1);
2287 global_sid_lock->
rdlock();
2288 thd->owned_gtid_set.to_string(buf);
2289 global_sid_lock->
unlock();
2292 my_error(ER_OUT_OF_RESOURCES, MYF(0));
2302 global_sid_lock->
rdlock();
2303 thd->owned_gtid.to_string(global_sid_map, buf);
2304 global_sid_lock->
unlock();
2307 my_error(ER_OUT_OF_RESOURCES, MYF(0));
2309 DBUG_RETURN((uchar *)buf);
2312 uchar *global_value_ptr(THD *thd,
LEX_STRING *base)
2314 DBUG_ENTER(
"Sys_var_gtid_owned::global_value_ptr");
2316 global_sid_lock->
wrlock();
2321 my_error(ER_OUT_OF_RESOURCES, MYF(0));
2322 global_sid_lock->
unlock();
2323 DBUG_RETURN((uchar *)buf);