sys_vars.ic 74.5 KB
Newer Older
Sergei Golubchik's avatar
Sergei Golubchik committed
1 2
/* Copyright (c) 2002, 2011, Oracle and/or its affiliates.
   Copyright (c) 2010, 2013, Monty Program Ab.
3 4 5 6 7 8 9 10 11 12 13 14

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
15
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
16 17 18 19 20 21 22 23 24 25 26 27 28 29

/**
  @file
  "private" interface to sys_var - server configuration variables.

  This header is included only by the file that contains declarations
  of sys_var variables (sys_vars.cc).
*/

#include "sys_vars_shared.h"
#include <my_getopt.h>
#include <my_bit.h>
#include <my_dir.h>
#include "keycaches.h"
30 31
#include "strfunc.h"
#include "tztime.h"     // my_tz_find, my_tz_SYSTEM, struct Time_zone
32
#include "rpl_mi.h" // For Multi-Source Replication
33 34 35 36 37 38 39 40 41 42 43

/*
  a set of mostly trivial (as in f(X)=X) defines below to make system variable
  declarations more readable
*/
#define VALID_RANGE(X,Y) X,Y
#define DEFAULT(X) X
#define BLOCK_SIZE(X) X
#define GLOBAL_VAR(X) sys_var::GLOBAL, (((char*)&(X))-(char*)&global_system_variables), sizeof(X)
#define SESSION_VAR(X) sys_var::SESSION, offsetof(SV, X), sizeof(((SV *)0)->X)
#define SESSION_ONLY(X) sys_var::ONLY_SESSION, offsetof(SV, X), sizeof(((SV *)0)->X)
44 45
#define NO_CMD_LINE CMD_LINE(NO_ARG, sys_var::NO_GETOPT)
#define CMD_LINE_HELP_ONLY CMD_LINE(NO_ARG, sys_var::GETOPT_ONLY_HELP)
46 47 48 49 50 51 52 53 54 55 56 57 58
/*
  the define below means that there's no *second* mutex guard,
  LOCK_global_system_variables always guards all system variables
*/
#define NO_MUTEX_GUARD ((PolyLock*)0)
#define IN_BINLOG sys_var::SESSION_VARIABLE_IN_BINLOG
#define NOT_IN_BINLOG sys_var::VARIABLE_NOT_IN_BINLOG
#define ON_READ(X) X
#define ON_CHECK(X) X
#define ON_UPDATE(X) X
#define READ_ONLY sys_var::READONLY+
// this means that Sys_var_charptr initial value was malloc()ed
#define PREALLOCATED sys_var::ALLOCATED+
59
#define PARSED_EARLY sys_var::PARSE_EARLY+
60
#define NO_SET_STMT sys_var::NO_SET_STATEMENT+
61

62 63 64 65 66
/*
  Sys_var_bit meaning is reversed, like in
  @@foreign_key_checks <-> OPTION_NO_FOREIGN_KEY_CHECKS
*/
#define REVERSE(X) ~(X)
67
#define DEPRECATED(X) X
68 69 70 71 72 73 74 75 76 77

#define session_var(THD, TYPE) (*(TYPE*)session_var_ptr(THD))
#define global_var(TYPE) (*(TYPE*)global_var_ptr())

#if SIZEOF_OFF_T > 4 && defined(BIG_TABLES)
#define GET_HA_ROWS GET_ULL
#else
#define GET_HA_ROWS GET_ULONG
#endif

Sergei Golubchik's avatar
Sergei Golubchik committed
78 79 80 81 82 83 84 85 86 87
/*
  special assert for sysvars. Tells the name of the variable,
  and fails even in non-debug builds.

  It is supposed to be used *only* in Sys_var* constructors,
  and has name_arg hard-coded to prevent incorrect usage.
*/
#define SYSVAR_ASSERT(X)                                                \
    while(!(X))                                                         \
    {                                                                   \
88 89
      fprintf(stderr, "Sysvar '%s' failed '%s'\n", name_arg, #X);       \
      DBUG_ABORT();                                                     \
Sergei Golubchik's avatar
Sergei Golubchik committed
90 91 92
      exit(255);                                                        \
    }

93 94 95 96
enum charset_enum {IN_SYSTEM_CHARSET, IN_FS_CHARSET};

static const char *bool_values[3]= {"OFF", "ON", 0};
TYPELIB bool_typelib={ array_elements(bool_values)-1, "", bool_values, 0 };
Monty's avatar
Monty committed
97
extern const char *encrypt_algorithm_names[];
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

/**
  A small wrapper class to pass getopt arguments as a pair
  to the Sys_var_* constructors. It improves type safety and helps
  to catch errors in the argument order.
*/
struct CMD_LINE
{
  int id;
  enum get_opt_arg_type arg_type;
  CMD_LINE(enum get_opt_arg_type getopt_arg_type, int getopt_id=0)
    : id(getopt_id), arg_type(getopt_arg_type) {}
};

/**
113 114 115 116
  Sys_var_integer template is used to generate Sys_var_* classes
  for variables that represent the value as an integer number.
  They are Sys_var_uint, Sys_var_ulong, Sys_var_harows, Sys_var_ulonglong,
  Sys_var_int.
117 118 119 120 121

  An integer variable has a minimal and maximal values, and a "block_size"
  (any valid value of the variable must be divisible by the block_size).

  Class specific constructor arguments: min, max, block_size
122
  Backing store: int, uint, ulong, ha_rows, ulonglong, depending on the class
123 124
*/
template <typename T, ulong ARGT, enum enum_mysql_show_type SHOWT>
125
class Sys_var_integer: public sys_var
126 127
{
public:
128
  Sys_var_integer(const char *name_arg,
129 130 131 132 133 134
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
          T min_val, T max_val, T def_val, uint block_size, PolyLock *lock=0,
          enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
          on_check_function on_check_func=0,
          on_update_function on_update_func=0,
Sergei Golubchik's avatar
Sergei Golubchik committed
135
          const char *substitute=0)
136 137
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
              getopt.arg_type, SHOWT, def_val, lock, binlog_status_arg,
Sergei Golubchik's avatar
Sergei Golubchik committed
138
              on_check_func, on_update_func, substitute)
139 140 141 142 143 144 145 146
  {
    option.var_type= ARGT;
    option.min_value= min_val;
    option.max_value= max_val;
    option.block_size= block_size;
    option.u_max_value= (uchar**)max_var_ptr();
    if (max_var_ptr())
      *max_var_ptr()= max_val;
147

148
    global_var(T)= def_val;
Sergei Golubchik's avatar
Sergei Golubchik committed
149 150 151 152 153 154
    SYSVAR_ASSERT(size == sizeof(T));
    SYSVAR_ASSERT(min_val < max_val);
    SYSVAR_ASSERT(min_val <= def_val);
    SYSVAR_ASSERT(max_val >= def_val);
    SYSVAR_ASSERT(block_size > 0);
    SYSVAR_ASSERT(def_val % block_size == 0);
155 156 157
  }
  bool do_check(THD *thd, set_var *var)
  {
158 159
    my_bool fixed= FALSE, unused;
    longlong v= var->value->val_int();
160

161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
    if ((ARGT == GET_HA_ROWS) || (ARGT == GET_UINT) ||
        (ARGT == GET_ULONG)   || (ARGT == GET_ULL))
    {
      ulonglong uv;

      /*
        if the value is signed and negative,
        and a variable is unsigned, it is set to zero
      */
      if ((fixed= (!var->value->unsigned_flag && v < 0)))
        uv= 0;
      else
        uv= v;

      var->save_result.ulonglong_value=
        getopt_ull_limit_value(uv, &option, &unused);

      if (max_var_ptr() && (T)var->save_result.ulonglong_value > *max_var_ptr())
        var->save_result.ulonglong_value= *max_var_ptr();

      fixed= fixed || var->save_result.ulonglong_value != uv;
    }
183
    else
184 185 186 187 188 189 190
    {
      /*
        if the value is unsigned and has the highest bit set
        and a variable is signed, it is set to max signed value
      */
      if ((fixed= (var->value->unsigned_flag && v < 0)))
        v= LONGLONG_MAX;
191

192 193
      var->save_result.longlong_value=
        getopt_ll_limit_value(v, &option, &unused);
194

195 196
      if (max_var_ptr() && (T)var->save_result.longlong_value > *max_var_ptr())
        var->save_result.longlong_value= *max_var_ptr();
197

198 199 200
      fixed= fixed || var->save_result.longlong_value != v;
    }
    return throw_bounds_warning(thd, name.str, fixed,
201 202 203 204
                                var->value->unsigned_flag, v);
  }
  bool session_update(THD *thd, set_var *var)
  {
205
    session_var(thd, T)= static_cast<T>(var->save_result.ulonglong_value);
206 207 208 209
    return false;
  }
  bool global_update(THD *thd, set_var *var)
  {
210
    global_var(T)= static_cast<T>(var->save_result.ulonglong_value);
211 212 213 214 215 216 217 218 219 220 221 222
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
  { var->save_result.ulonglong_value= (ulonglong)*(T*)global_value_ptr(thd, 0); }
  void global_save_default(THD *thd, set_var *var)
  { var->save_result.ulonglong_value= option.def_value; }
  private:
  T *max_var_ptr()
  {
    return scope() == SESSION ? (T*)(((uchar*)&max_system_variables) + offset)
                              : 0;
  }
223
  uchar *default_value_ptr(THD *thd) { return (uchar*) &option.def_value; }
224 225
};

226 227 228 229 230
typedef Sys_var_integer<int, GET_INT, SHOW_SINT> Sys_var_int;
typedef Sys_var_integer<uint, GET_UINT, SHOW_UINT> Sys_var_uint;
typedef Sys_var_integer<ulong, GET_ULONG, SHOW_ULONG> Sys_var_ulong;
typedef Sys_var_integer<ha_rows, GET_HA_ROWS, SHOW_HA_ROWS> Sys_var_harows;
typedef Sys_var_integer<ulonglong, GET_ULL, SHOW_ULONGLONG> Sys_var_ulonglong;
231
typedef Sys_var_integer<long, GET_LONG, SHOW_SLONG> Sys_var_long;
232

233

234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
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;
}


259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
/**
  Helper class for variables that take values from a TYPELIB
*/
class Sys_var_typelib: public sys_var
{
protected:
  TYPELIB typelib;
public:
  Sys_var_typelib(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off,
          CMD_LINE getopt,
          SHOW_TYPE show_val_type_arg, const char *values[],
          ulonglong def_val, PolyLock *lock,
          enum binlog_status_enum binlog_status_arg,
          on_check_function on_check_func, on_update_function on_update_func,
Sergei Golubchik's avatar
Sergei Golubchik committed
274
          const char *substitute)
275 276 277
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
              getopt.arg_type, show_val_type_arg, def_val, lock,
              binlog_status_arg, on_check_func,
Sergei Golubchik's avatar
Sergei Golubchik committed
278
              on_update_func, substitute)
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
  {
    for (typelib.count= 0; values[typelib.count]; typelib.count++) /*no-op */;
    typelib.name="";
    typelib.type_names= values;
    typelib.type_lengths= 0;    // only used by Fields_enum and Field_set
    option.typelib= &typelib;
  }
  bool do_check(THD *thd, set_var *var) // works for enums and my_bool
  {
    char buff[STRING_BUFFER_USUAL_SIZE];
    String str(buff, sizeof(buff), system_charset_info), *res;

    if (var->value->result_type() == STRING_RESULT)
    {
      if (!(res=var->value->val_str(&str)))
        return true;
      else
      if (!(var->save_result.ulonglong_value=
            find_type(&typelib, res->ptr(), res->length(), false)))
        return true;
      else
        var->save_result.ulonglong_value--;
    }
    else
    {
      longlong tmp=var->value->val_int();
      if (tmp < 0 || tmp >= typelib.count)
        return true;
      else
        var->save_result.ulonglong_value= tmp;
    }

    return false;
  }
};

/**
  The class for ENUM variables - variables that take one value from a fixed
  list of values. 

  Class specific constructor arguments:
    char* values[]    - 0-terminated list of strings of valid values

  Backing store: uint

  @note
  Do *not* use "enum FOO" variables as a backing store, there is no
  guarantee that sizeof(enum FOO) == sizeof(uint), there is no guarantee
  even that sizeof(enum FOO) == sizeof(enum BAR)
*/
class Sys_var_enum: public Sys_var_typelib
{
public:
  Sys_var_enum(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
          const char *values[], uint def_val, PolyLock *lock=0,
          enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
          on_check_function on_check_func=0,
          on_update_function on_update_func=0,
339
          const char *substitute=0)
340 341 342
    : Sys_var_typelib(name_arg, comment, flag_args, off, getopt,
                      SHOW_CHAR, values, def_val, lock,
                      binlog_status_arg, on_check_func, on_update_func,
343
                      substitute)
344 345
  {
    option.var_type= GET_ENUM;
Georgi Kodinov's avatar
merge  
Georgi Kodinov committed
346
    global_var(ulong)= def_val;
Sergei Golubchik's avatar
Sergei Golubchik committed
347 348
    SYSVAR_ASSERT(def_val < typelib.count);
    SYSVAR_ASSERT(size == sizeof(ulong));
349 350 351
  }
  bool session_update(THD *thd, set_var *var)
  {
352
    session_var(thd, ulong)= static_cast<ulong>(var->save_result.ulonglong_value);
353 354 355 356
    return false;
  }
  bool global_update(THD *thd, set_var *var)
  {
357
    global_var(ulong)= static_cast<ulong>(var->save_result.ulonglong_value);
358 359 360
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
Georgi Kodinov's avatar
merge  
Georgi Kodinov committed
361
  { var->save_result.ulonglong_value= global_var(ulong); }
362 363
  void global_save_default(THD *thd, set_var *var)
  { var->save_result.ulonglong_value= option.def_value; }
364 365
  uchar *valptr(THD *thd, ulong val)
  { return (uchar*)typelib.type_names[val]; }
366
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
367
  { return valptr(thd, session_var(thd, ulong)); }
368
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
369 370 371
  { return valptr(thd, global_var(ulong)); }
  uchar *default_value_ptr(THD *thd)
  { return valptr(thd, option.def_value); }
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
};

/**
  The class for boolean variables - a variant of ENUM variables
  with the fixed list of values of { OFF , ON }

  Backing store: my_bool
*/
class Sys_var_mybool: public Sys_var_typelib
{
public:
  Sys_var_mybool(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
          my_bool def_val, PolyLock *lock=0,
          enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
          on_check_function on_check_func=0,
          on_update_function on_update_func=0,
Sergei Golubchik's avatar
Sergei Golubchik committed
390
          const char *substitute=0)
391 392 393
    : Sys_var_typelib(name_arg, comment, flag_args, off, getopt,
                      SHOW_MY_BOOL, bool_values, def_val, lock,
                      binlog_status_arg, on_check_func, on_update_func,
Sergei Golubchik's avatar
Sergei Golubchik committed
394
                      substitute)
395 396 397
  {
    option.var_type= GET_BOOL;
    global_var(my_bool)= def_val;
Sergei Golubchik's avatar
Sergei Golubchik committed
398
    SYSVAR_ASSERT(def_val < 2);
399
    SYSVAR_ASSERT(getopt.arg_type == OPT_ARG || getopt.id < 0);
Sergei Golubchik's avatar
Sergei Golubchik committed
400
    SYSVAR_ASSERT(size == sizeof(my_bool));
401 402 403
  }
  bool session_update(THD *thd, set_var *var)
  {
404
    session_var(thd, my_bool)= var->save_result.ulonglong_value != 0;
405 406 407 408
    return false;
  }
  bool global_update(THD *thd, set_var *var)
  {
409
    global_var(my_bool)= var->save_result.ulonglong_value != 0;
410 411 412 413 414 415
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
  { 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; }
416 417 418 419 420
  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;
  }
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
};

/**
  The class for string variables. The string can be in character_set_filesystem
  or in character_set_system. The string can be allocated with my_malloc()
  or not. The state of the initial value is specified in the constructor,
  after that it's managed automatically. The value of NULL is supported.

  Class specific constructor arguments:
    enum charset_enum is_os_charset_arg

  Backing store: char*

  @note
  This class supports only GLOBAL variables, because THD on destruction
  does not destroy individual members of SV, there's no way to free
  allocated string variables for every thread.
*/
class Sys_var_charptr: public sys_var
{
public:
  Sys_var_charptr(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
          enum charset_enum is_os_charset_arg,
          const char *def_val, PolyLock *lock=0,
          enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
          on_check_function on_check_func=0,
          on_update_function on_update_func=0,
Sergei Golubchik's avatar
Sergei Golubchik committed
450
          const char *substitute=0)
451 452 453
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
              getopt.arg_type, SHOW_CHAR_PTR, (intptr)def_val,
              lock, binlog_status_arg, on_check_func, on_update_func,
Sergei Golubchik's avatar
Sergei Golubchik committed
454
              substitute)
455 456 457 458 459 460 461 462 463
  {
    is_os_charset= is_os_charset_arg == IN_FS_CHARSET;
    /*
     use GET_STR_ALLOC - if ALLOCATED it must be *always* allocated,
     otherwise (GET_STR) you'll never know whether to free it or not.
     (think of an exit because of an error right after my_getopt)
    */
    option.var_type= (flags & ALLOCATED) ? GET_STR_ALLOC : GET_STR;
    global_var(const char*)= def_val;
Sergei Golubchik's avatar
Sergei Golubchik committed
464 465
    SYSVAR_ASSERT(scope() == GLOBAL);
    SYSVAR_ASSERT(size == sizeof(char *));
466
  }
467
  void cleanup()
468 469
  {
    if (flags & ALLOCATED)
470
    {
471
      my_free(global_var(char*));
472 473
      global_var(char *)= NULL;
    }
474 475
    flags&= ~ALLOCATED;
  }
476
  static bool do_string_check(THD *thd, set_var *var, CHARSET_INFO *charset)
477 478
  {
    char buff[STRING_BUFFER_USUAL_SIZE], buff2[STRING_BUFFER_USUAL_SIZE];
479 480
    String str(buff, sizeof(buff), charset);
    String str2(buff2, sizeof(buff2), charset), *res;
481 482 483 484 485 486 487

    if (!(res=var->value->val_str(&str)))
      var->save_result.string_value.str= 0;
    else
    {
      uint32 unused;
      if (String::needs_conversion(res->length(), res->charset(),
488
                                   charset, &unused))
489 490
      {
        uint errors;
491
        str2.copy(res->ptr(), res->length(), res->charset(), charset,
492 493 494 495 496 497 498 499 500 501
                  &errors);
        res=&str2;

      }
      var->save_result.string_value.str= thd->strmake(res->ptr(), res->length());
      var->save_result.string_value.length= res->length();
    }

    return false;
  }
502 503
  bool do_check(THD *thd, set_var *var)
  { return do_string_check(thd, var, charset(thd)); }
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
  bool session_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(FALSE);
    return true;
  }
  bool global_update(THD *thd, set_var *var)
  {
    char *new_val, *ptr= var->save_result.string_value.str;
    size_t len=var->save_result.string_value.length;
    if (ptr)
    {
      new_val= (char*)my_memdup(ptr, len+1, MYF(MY_WME));
      if (!new_val) return true;
      new_val[len]=0;
    }
    else
      new_val= 0;
    if (flags & ALLOCATED)
522
      my_free(global_var(char*));
523 524 525 526 527 528 529 530 531 532 533 534 535 536
    flags|= ALLOCATED;
    global_var(char*)= new_val;
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
  { DBUG_ASSERT(FALSE); }
  void global_save_default(THD *thd, set_var *var)
  {
    char *ptr= (char*)(intptr)option.def_value;
    var->save_result.string_value.str= ptr;
    var->save_result.string_value.length= ptr ? strlen(ptr) : 0;
  }
};

537 538 539 540 541 542

class Sys_var_proxy_user: public sys_var
{
public:
  Sys_var_proxy_user(const char *name_arg,
          const char *comment, enum charset_enum is_os_charset_arg)
543
    : sys_var(&all_sys_vars, name_arg, comment,
544
              sys_var::READONLY+sys_var::ONLY_SESSION, 0, NO_GETOPT,
545
              NO_ARG, SHOW_CHAR, 0, NULL, VARIABLE_NOT_IN_BINLOG,
Sergei Golubchik's avatar
Sergei Golubchik committed
546
              NULL, NULL, NULL)
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
  {
    is_os_charset= is_os_charset_arg == IN_FS_CHARSET;
    option.var_type= GET_STR;
  }
  bool do_check(THD *thd, set_var *var)
  {
    DBUG_ASSERT(FALSE);
    return true;
  }
  bool session_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(FALSE);
    return true;
  }
  bool global_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(FALSE);
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
  { DBUG_ASSERT(FALSE); }
  void global_save_default(THD *thd, set_var *var)
  { DBUG_ASSERT(FALSE); }
protected:
571
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
  {
    return thd->security_ctx->proxy_user[0] ?
      (uchar *) &(thd->security_ctx->proxy_user[0]) : NULL;
  }
};

class Sys_var_external_user : public Sys_var_proxy_user
{
public:
  Sys_var_external_user(const char *name_arg, const char *comment_arg, 
          enum charset_enum is_os_charset_arg) 
    : Sys_var_proxy_user (name_arg, comment_arg, is_os_charset_arg)
  {}

protected:
587
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
588
  {
589
    return (uchar*)thd->security_ctx->external_user;
590 591 592
  }
};

unknown's avatar
unknown committed
593
class Master_info;
594 595 596 597 598 599 600
class Sys_var_rpl_filter: public sys_var
{
private:
  int opt_id;

public:
  Sys_var_rpl_filter(const char *name, int getopt_id, const char *comment)
601
    : sys_var(&all_sys_vars, name, comment, sys_var::GLOBAL, 0, NO_GETOPT,
602
              NO_ARG, SHOW_CHAR, 0, NULL, VARIABLE_NOT_IN_BINLOG,
Sergei Golubchik's avatar
Sergei Golubchik committed
603
              NULL, NULL, NULL), opt_id(getopt_id)
604
  {
605
    option.var_type= GET_STR | GET_ASK_ADDR;
606 607
  }

608 609 610 611
  bool do_check(THD *thd, set_var *var)
  {
    return Sys_var_charptr::do_string_check(thd, var, charset(thd));
  }
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
  void session_save_default(THD *thd, set_var *var)
  { DBUG_ASSERT(FALSE); }

  void global_save_default(THD *thd, set_var *var)
  { DBUG_ASSERT(FALSE); }

  bool session_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(FALSE);
    return true;
  }

  bool global_update(THD *thd, set_var *var);

protected:
627
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base);
628
  bool set_filter_value(const char *value, Master_info *mi);
629 630
};

631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
/**
  The class for string variables. Useful for strings that aren't necessarily
  \0-terminated. Otherwise the same as Sys_var_charptr.

  Class specific constructor arguments:
    enum charset_enum is_os_charset_arg

  Backing store: LEX_STRING

  @note
  Behaves exactly as Sys_var_charptr, only the backing store is different.
*/
class Sys_var_lexstring: public Sys_var_charptr
{
public:
  Sys_var_lexstring(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
          enum charset_enum is_os_charset_arg,
          const char *def_val, PolyLock *lock=0,
          enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
          on_check_function on_check_func=0,
          on_update_function on_update_func=0,
654
          const char *substitute=0)
655 656
    : Sys_var_charptr(name_arg, comment, flag_args, off, sizeof(char*),
              getopt, is_os_charset_arg, def_val, lock, binlog_status_arg,
657
              on_check_func, on_update_func, substitute)
658 659
  {
    global_var(LEX_STRING).length= strlen(def_val);
Sergei Golubchik's avatar
Sergei Golubchik committed
660
    SYSVAR_ASSERT(size == sizeof(LEX_STRING));
661 662 663 664 665 666 667 668 669 670 671
    *const_cast<SHOW_TYPE*>(&show_val_type)= SHOW_LEX_STRING;
  }
  bool global_update(THD *thd, set_var *var)
  {
    if (Sys_var_charptr::global_update(thd, var))
      return true;
    global_var(LEX_STRING).length= var->save_result.string_value.length;
    return false;
  }
};

672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691

/*
  A LEX_STRING stored only in thd->variables
  Only to be used for small buffers
*/

class Sys_var_session_lexstring: public sys_var
{
  size_t max_length;
public:
  Sys_var_session_lexstring(const char *name_arg,
                            const char *comment, int flag_args,
                            ptrdiff_t off, size_t size, CMD_LINE getopt,
                            enum charset_enum is_os_charset_arg,
                            const char *def_val, size_t max_length_arg,
                            on_check_function on_check_func=0,
                            on_update_function on_update_func=0)
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
              getopt.arg_type, SHOW_CHAR, (intptr)def_val,
              0, VARIABLE_NOT_IN_BINLOG, on_check_func, on_update_func,
Sergei Golubchik's avatar
Sergei Golubchik committed
692
              0),max_length(max_length_arg)
693
  {
694
    option.var_type= GET_STR;
695 696 697 698 699 700 701 702 703
    SYSVAR_ASSERT(scope() == ONLY_SESSION)
    *const_cast<SHOW_TYPE*>(&show_val_type)= SHOW_LEX_STRING;
  }
  bool do_check(THD *thd, set_var *var)
  {
    char buff[STRING_BUFFER_USUAL_SIZE];
    String str(buff, sizeof(buff), system_charset_info), *res;

    if (!(res=var->value->val_str(&str)))
704 705 706 707
    {
      var->save_result.string_value.str= 0;     /* NULL */
      var->save_result.string_value.length= 0;
    }
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
    else
    {
      if (res->length() > max_length)
      {
        my_error(ER_WRONG_STRING_LENGTH, MYF(0),
                 res->ptr(), name.str, (int) max_length);
        return true;
      }
      var->save_result.string_value.str= thd->strmake(res->ptr(),
                                                      res->length());
      var->save_result.string_value.length= res->length();
    }
    return false;
  }
  bool session_update(THD *thd, set_var *var)
  {
    LEX_STRING *tmp= &session_var(thd, LEX_STRING);
    tmp->length= var->save_result.string_value.length;
    /* Store as \0 terminated string (just to be safe) */
    strmake(tmp->str, var->save_result.string_value.str, tmp->length);
    return false;
  }
  bool global_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(FALSE);
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
  {
    char *ptr= (char*)(intptr)option.def_value;
    var->save_result.string_value.str= ptr;
739
    var->save_result.string_value.length= strlen(ptr);
740 741 742 743 744
  }
  void global_save_default(THD *thd, set_var *var)
  {
    DBUG_ASSERT(FALSE);
  }
745
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
746 747
  {
    DBUG_ASSERT(FALSE);
748
    return NULL;
749 750 751 752
  }
};


753 754
#ifndef DBUG_OFF
/**
755
  @@session.debug_dbug and @@global.debug_dbug variables.
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774

  @@dbug variable differs from other variables in one aspect:
  if its value is not assigned in the session, it "points" to the global
  value, and so when the global value is changed, the change
  immediately takes effect in the session.

  This semantics is intentional, to be able to debug one session from
  another.
*/
class Sys_var_dbug: public sys_var
{
public:
  Sys_var_dbug(const char *name_arg,
               const char *comment, int flag_args,
               CMD_LINE getopt,
               const char *def_val, PolyLock *lock=0,
               enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
               on_check_function on_check_func=0,
               on_update_function on_update_func=0,
Sergei Golubchik's avatar
Sergei Golubchik committed
775
               const char *substitute=0)
776
    : sys_var(&all_sys_vars, name_arg, comment, flag_args,
777
              (char*)&current_dbug_option-(char*)&global_system_variables, getopt.id,
778 779
              getopt.arg_type, SHOW_CHAR, (intptr)def_val,
              lock, binlog_status_arg, on_check_func, on_update_func,
Sergei Golubchik's avatar
Sergei Golubchik committed
780
              substitute)
781
  { option.var_type= GET_STR; }
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
  bool do_check(THD *thd, set_var *var)
  {
    char buff[STRING_BUFFER_USUAL_SIZE];
    String str(buff, sizeof(buff), system_charset_info), *res;

    if (!(res=var->value->val_str(&str)))
      var->save_result.string_value.str= const_cast<char*>("");
    else
      var->save_result.string_value.str= thd->strmake(res->ptr(), res->length());
    return false;
  }
  bool session_update(THD *thd, set_var *var)
  {
    const char *val= var->save_result.string_value.str;
    if (!var->value)
      DBUG_POP();
    else
      DBUG_SET(val);
    return false;
  }
  bool global_update(THD *thd, set_var *var)
  {
    const char *val= var->save_result.string_value.str;
    DBUG_SET_INITIAL(val);
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
  { }
  void global_save_default(THD *thd, set_var *var)
  {
    char *ptr= (char*)(intptr)option.def_value;
    var->save_result.string_value.str= ptr;
  }
815
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
816 817 818 819 820
  {
    char buf[256];
    DBUG_EXPLAIN(buf, sizeof(buf));
    return (uchar*) thd->strdup(buf);
  }
821
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
822 823 824 825 826
  {
    char buf[256];
    DBUG_EXPLAIN_INITIAL(buf, sizeof(buf));
    return (uchar*) thd->strdup(buf);
  }
827 828
  uchar *default_value_ptr(THD *thd)
  { return (uchar*)""; }
829 830 831
};
#endif

832
#define KEYCACHE_VAR(X) GLOBAL_VAR(dflt_key_cache_var.X)
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
#define keycache_var_ptr(KC, OFF) (((uchar*)(KC))+(OFF))
#define keycache_var(KC, OFF) (*(ulonglong*)keycache_var_ptr(KC, OFF))
typedef bool (*keycache_update_function)(THD *, KEY_CACHE *, ptrdiff_t, ulonglong);

/**
  The class for keycache_* variables. Supports structured names,
  keycache_name.variable_name.

  Class specific constructor arguments:
    everything derived from Sys_var_ulonglong

  Backing store: ulonglong

  @note these variables can be only GLOBAL
*/
class Sys_var_keycache: public Sys_var_ulonglong
{
  keycache_update_function keycache_update;
public:
  Sys_var_keycache(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
          ulonglong min_val, ulonglong max_val, ulonglong def_val,
856
          uint block_size, PolyLock *lock,
857 858 859
          enum binlog_status_enum binlog_status_arg,
          on_check_function on_check_func,
          keycache_update_function on_update_func,
860
          const char *substitute=0)
861 862 863
    : Sys_var_ulonglong(name_arg, comment, flag_args, off, size,
              getopt, min_val, max_val, def_val,
              block_size, lock, binlog_status_arg, on_check_func, 0,
864
              substitute),
865 866 867 868
    keycache_update(on_update_func)
  {
    option.var_type|= GET_ASK_ADDR;
    option.value= (uchar**)1; // crash me, please
869 870
    // fix an offset from global_system_variables to be an offset in KEY_CACHE
    offset= global_var_ptr() - (uchar*)dflt_key_cache;
Sergei Golubchik's avatar
Sergei Golubchik committed
871
    SYSVAR_ASSERT(scope() == GLOBAL);
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902
  }
  bool global_update(THD *thd, set_var *var)
  {
    ulonglong new_value= var->save_result.ulonglong_value;
    LEX_STRING *base_name= &var->base;
    KEY_CACHE *key_cache;

    /* If no basename, assume it's for the key cache named 'default' */
    if (!base_name->length)
      base_name= &default_key_cache_base;

    key_cache= get_key_cache(base_name);

    if (!key_cache)
    {                                           // Key cache didn't exists */
      if (!new_value)                           // Tried to delete cache
        return false;                           // Ok, nothing to do
      if (!(key_cache= create_key_cache(base_name->str, base_name->length)))
        return true;
    }

    /**
      Abort if some other thread is changing the key cache
      @todo This should be changed so that we wait until the previous
      assignment is done and then do the new assign
    */
    if (key_cache->in_init)
      return true;

    return keycache_update(thd, key_cache, offset, new_value);
  }
903
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
  {
    KEY_CACHE *key_cache= get_key_cache(base);
    if (!key_cache)
      key_cache= &zero_key_cache;
    return keycache_var_ptr(key_cache, offset);
  }
};

static bool update_buffer_size(THD *thd, KEY_CACHE *key_cache,
                               ptrdiff_t offset, ulonglong new_value)
{
  bool error= false;
  DBUG_ASSERT(offset == offsetof(KEY_CACHE, param_buff_size));

  if (new_value == 0)
  {
    if (key_cache == dflt_key_cache)
    {
      my_error(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE, MYF(0));
      return true;
    }

    if (key_cache->key_cache_inited)            // If initied
    {
      /*
        Move tables using this key cache to the default key cache
        and clear the old key cache.
      */
      key_cache->in_init= 1;
Marc Alff's avatar
Marc Alff committed
933
      mysql_mutex_unlock(&LOCK_global_system_variables);
934 935 936 937 938 939 940
      key_cache->param_buff_size= 0;
      ha_resize_key_cache(key_cache);
      ha_change_key_cache(key_cache, dflt_key_cache);
      /*
        We don't delete the key cache as some running threads my still be in
        the key cache code with a pointer to the deleted (empty) key cache
      */
Marc Alff's avatar
Marc Alff committed
941
      mysql_mutex_lock(&LOCK_global_system_variables);
942 943 944 945 946 947 948 949 950
      key_cache->in_init= 0;
    }
    return error;
  }

  key_cache->param_buff_size= new_value;

  /* If key cache didn't exist initialize it, else resize it */
  key_cache->in_init= 1;
Marc Alff's avatar
Marc Alff committed
951
  mysql_mutex_unlock(&LOCK_global_system_variables);
952 953

  if (!key_cache->key_cache_inited)
954
    error= ha_init_key_cache(0, key_cache, 0);
955 956 957
  else
    error= ha_resize_key_cache(key_cache);

Marc Alff's avatar
Marc Alff committed
958
  mysql_mutex_lock(&LOCK_global_system_variables);
959 960 961 962 963
  key_cache->in_init= 0;

  return error;
}

964 965
static bool update_keycache(THD *thd, KEY_CACHE *key_cache,
                            ptrdiff_t offset, ulonglong new_value,
966
                            int (*func)(KEY_CACHE *))
967 968 969 970 971 972 973
{
  bool error= false;
  DBUG_ASSERT(offset != offsetof(KEY_CACHE, param_buff_size));

  keycache_var(key_cache, offset)= new_value;

  key_cache->in_init= 1;
Marc Alff's avatar
Marc Alff committed
974
  mysql_mutex_unlock(&LOCK_global_system_variables);
975
  error= func(key_cache);
Marc Alff's avatar
Marc Alff committed
976
  mysql_mutex_lock(&LOCK_global_system_variables);
977 978 979 980 981
  key_cache->in_init= 0;

  return error;
}

982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
static bool resize_keycache(THD *thd, KEY_CACHE *key_cache,
                            ptrdiff_t offset, ulonglong new_value)
{
  return update_keycache(thd, key_cache, offset, new_value,
                         ha_resize_key_cache);
}

static bool change_keycache_param(THD *thd, KEY_CACHE *key_cache,
                                  ptrdiff_t offset, ulonglong new_value)
{
  return update_keycache(thd, key_cache, offset, new_value,
                         ha_change_key_cache_param);
}

static bool repartition_keycache(THD *thd, KEY_CACHE *key_cache,
                                 ptrdiff_t offset, ulonglong new_value)
{
  return update_keycache(thd, key_cache, offset, new_value,
                         ha_repartition_key_cache);
}


1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
/**
  The class for floating point variables

  Class specific constructor arguments: min, max

  Backing store: double
*/
class Sys_var_double: public sys_var
{
public:
  Sys_var_double(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
          double min_val, double max_val, double def_val, PolyLock *lock=0,
          enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
          on_check_function on_check_func=0,
          on_update_function on_update_func=0,
Sergei Golubchik's avatar
Sergei Golubchik committed
1021
          const char *substitute=0)
1022
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
1023 1024
              getopt.arg_type, SHOW_DOUBLE,
              (longlong) getopt_double2ulonglong(def_val),
1025
              lock, binlog_status_arg, on_check_func, on_update_func,
Sergei Golubchik's avatar
Sergei Golubchik committed
1026
              substitute)
1027 1028
  {
    option.var_type= GET_DOUBLE;
1029 1030
    option.min_value= (longlong) getopt_double2ulonglong(min_val);
    option.max_value= (longlong) getopt_double2ulonglong(max_val);
1031
    global_var(double)= (double)option.def_value;
Sergei Golubchik's avatar
Sergei Golubchik committed
1032 1033 1034 1035
    SYSVAR_ASSERT(min_val < max_val);
    SYSVAR_ASSERT(min_val <= def_val);
    SYSVAR_ASSERT(max_val >= def_val);
    SYSVAR_ASSERT(size == sizeof(double));
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
  }
  bool do_check(THD *thd, set_var *var)
  {
    my_bool fixed;
    double v= var->value->val_real();
    var->save_result.double_value= getopt_double_limit_value(v, &option, &fixed);

    return throw_bounds_warning(thd, name.str, fixed, v);
  }
  bool session_update(THD *thd, set_var *var)
  {
    session_var(thd, double)= var->save_result.double_value;
    return false;
  }
  bool global_update(THD *thd, set_var *var)
  {
    global_var(double)= var->save_result.double_value;
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
  { var->save_result.double_value= global_var(double); }
  void global_save_default(THD *thd, set_var *var)
1058
  { var->save_result.double_value= getopt_ulonglong2double(option.def_value); }
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
};

/**
  The class for the @max_user_connections.
  It's derived from Sys_var_uint, but non-standard session value
  requires a new class.

  Class specific constructor arguments:
    everything derived from Sys_var_uint

  Backing store: uint
*/
1071
class Sys_var_max_user_conn: public Sys_var_int
1072 1073 1074 1075 1076
{
public:
  Sys_var_max_user_conn(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
Michael Widenius's avatar
Michael Widenius committed
1077
          int min_val, int max_val, int def_val,
1078 1079 1080 1081
          uint block_size, PolyLock *lock=0,
          enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
          on_check_function on_check_func=0,
          on_update_function on_update_func=0,
1082
          const char *substitute=0)
1083
    : Sys_var_int(name_arg, comment, SESSION, off, size, getopt,
1084 1085
              min_val, max_val, def_val, block_size,
              lock, binlog_status_arg, on_check_func, on_update_func,
1086
              substitute)
1087
  { }
1088
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
  {
    if (thd->user_connect && thd->user_connect->user_resources.user_conn)
      return (uchar*) &(thd->user_connect->user_resources.user_conn);
    return global_value_ptr(thd, base);
  }
};

// overflow-safe (1 << X)-1
#define MAX_SET(X) ((((1UL << ((X)-1))-1) << 1) | 1)

/**
  The class for flagset variables - a variant of SET that allows in-place
  editing (turning on/off individual bits). String representations looks like
  a "flag=val,flag=val,...". Example: @@optimizer_switch

  Class specific constructor arguments:
    char* values[]    - 0-terminated list of strings of valid values

  Backing store: ulonglong

  @note
  the last value in the values[] array should
  *always* be the string "default".
*/
class Sys_var_flagset: public Sys_var_typelib
{
public:
  Sys_var_flagset(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
          const char *values[], ulonglong def_val, PolyLock *lock=0,
          enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
          on_check_function on_check_func=0,
          on_update_function on_update_func=0,
1123
          const char *substitute=0)
1124 1125 1126
    : Sys_var_typelib(name_arg, comment, flag_args, off, getopt,
                      SHOW_CHAR, values, def_val, lock,
                      binlog_status_arg, on_check_func, on_update_func,
1127
                      substitute)
1128 1129 1130
  {
    option.var_type= GET_FLAGSET;
    global_var(ulonglong)= def_val;
Sergei Golubchik's avatar
Sergei Golubchik committed
1131 1132 1133 1134 1135
    SYSVAR_ASSERT(typelib.count > 1);
    SYSVAR_ASSERT(typelib.count <= 65);
    SYSVAR_ASSERT(def_val < MAX_SET(typelib.count));
    SYSVAR_ASSERT(strcmp(values[typelib.count-1], "default") == 0);
    SYSVAR_ASSERT(size == sizeof(ulonglong));
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
  }
  bool do_check(THD *thd, set_var *var)
  {
    char buff[STRING_BUFFER_USUAL_SIZE];
    String str(buff, sizeof(buff), system_charset_info), *res;
    ulonglong default_value, current_value;
    if (var->type == OPT_GLOBAL)
    {
      default_value= option.def_value;
      current_value= global_var(ulonglong);
    }
    else
    {
      default_value= global_var(ulonglong);
      current_value= session_var(thd, ulonglong);
    }

    if (var->value->result_type() == STRING_RESULT)
    {
      if (!(res=var->value->val_str(&str)))
        return true;
      else
      {
        char *error;
        uint error_len;

        var->save_result.ulonglong_value=
              find_set_from_flags(&typelib,
                                  typelib.count,
                                  current_value,
                                  default_value,
                                  res->ptr(), res->length(),
                                  &error, &error_len);
        if (error)
        {
          ErrConvString err(error, error_len, res->charset());
          my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.str, err.ptr());
          return true;
        }
      }
    }
    else
    {
      longlong tmp=var->value->val_int();
      if ((tmp < 0 && ! var->value->unsigned_flag)
          || (ulonglong)tmp > MAX_SET(typelib.count))
        return true;
      else
        var->save_result.ulonglong_value= tmp;
    }

    return false;
  }
  bool session_update(THD *thd, set_var *var)
  {
    session_var(thd, ulonglong)= var->save_result.ulonglong_value;
    return false;
  }
  bool global_update(THD *thd, set_var *var)
  {
    global_var(ulonglong)= var->save_result.ulonglong_value;
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
  { var->save_result.ulonglong_value= global_var(ulonglong); }
  void global_save_default(THD *thd, set_var *var)
  { var->save_result.ulonglong_value= option.def_value; }
1203 1204
  uchar *valptr(THD *thd, ulonglong val)
  { return (uchar*)flagset_to_string(thd, 0, val, typelib.type_names); }
1205
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
1206
  { return valptr(thd, session_var(thd, ulonglong)); }
1207
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
1208 1209 1210
  { return valptr(thd, global_var(ulonglong)); }
  uchar *default_value_ptr(THD *thd)
  { return valptr(thd, option.def_value); }
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
};

/**
  The class for SET variables - variables taking zero or more values
  from the given list. Example: @@sql_mode

  Class specific constructor arguments:
    char* values[]    - 0-terminated list of strings of valid values

  Backing store: ulonglong
*/
class Sys_var_set: public Sys_var_typelib
{
public:
  Sys_var_set(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
          const char *values[], ulonglong def_val, PolyLock *lock=0,
          enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
          on_check_function on_check_func=0,
          on_update_function on_update_func=0,
1232
          const char *substitute=0)
1233 1234 1235
    : Sys_var_typelib(name_arg, comment, flag_args, off, getopt,
                      SHOW_CHAR, values, def_val, lock,
                      binlog_status_arg, on_check_func, on_update_func,
1236
                      substitute)
1237 1238 1239
  {
    option.var_type= GET_SET;
    global_var(ulonglong)= def_val;
Sergei Golubchik's avatar
Sergei Golubchik committed
1240 1241 1242 1243
    SYSVAR_ASSERT(typelib.count > 0);
    SYSVAR_ASSERT(typelib.count <= 64);
    SYSVAR_ASSERT(def_val <= MAX_SET(typelib.count));
    SYSVAR_ASSERT(size == sizeof(ulonglong));
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
  }
  bool do_check(THD *thd, set_var *var)
  {
    char buff[STRING_BUFFER_USUAL_SIZE];
    String str(buff, sizeof(buff), system_charset_info), *res;

    if (var->value->result_type() == STRING_RESULT)
    {
      if (!(res=var->value->val_str(&str)))
        return true;
      else
      {
        char *error;
        uint error_len;
        bool not_used;

        var->save_result.ulonglong_value=
              find_set(&typelib, res->ptr(), res->length(), NULL,
                      &error, &error_len, &not_used);
        /*
          note, we only issue an error if error_len > 0.
          That is even while empty (zero-length) values are considered
          errors by find_set(), these errors are ignored here
        */
        if (error_len)
        {
          ErrConvString err(error, error_len, res->charset());
          my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.str, err.ptr());
          return true;
        }
      }
    }
    else
    {
      longlong tmp=var->value->val_int();
      if ((tmp < 0 && ! var->value->unsigned_flag)
          || (ulonglong)tmp > MAX_SET(typelib.count))
        return true;
      else
        var->save_result.ulonglong_value= tmp;
    }

    return false;
  }
  bool session_update(THD *thd, set_var *var)
  {
    session_var(thd, ulonglong)= var->save_result.ulonglong_value;
    return false;
  }
  bool global_update(THD *thd, set_var *var)
  {
    global_var(ulonglong)= var->save_result.ulonglong_value;
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
  { var->save_result.ulonglong_value= global_var(ulonglong); }
  void global_save_default(THD *thd, set_var *var)
  { var->save_result.ulonglong_value= option.def_value; }
1302 1303
  uchar *valptr(THD *thd, ulonglong val)
  { return (uchar*)set_to_string(thd, 0, val, typelib.type_names); }
1304
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
1305
  { return valptr(thd, session_var(thd, ulonglong)); }
1306
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
1307 1308 1309
  { return valptr(thd, global_var(ulonglong)); }
  uchar *default_value_ptr(THD *thd)
  { return valptr(thd, option.def_value); }
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
};

/**
  The class for variables which value is a plugin.
  Example: @@default_storage_engine

  Class specific constructor arguments:
    int plugin_type_arg (for example MYSQL_STORAGE_ENGINE_PLUGIN)

  Backing store: plugin_ref

  @note
  these variables don't support command-line equivalents, any such
  command-line options should be added manually to my_long_options in mysqld.cc
*/
class Sys_var_plugin: public sys_var
{
  int plugin_type;
public:
  Sys_var_plugin(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
          int plugin_type_arg, char **def_val, PolyLock *lock=0,
          enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
          on_check_function on_check_func=0,
          on_update_function on_update_func=0,
Sergei Golubchik's avatar
Sergei Golubchik committed
1336
          const char *substitute=0)
1337 1338 1339
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
              getopt.arg_type, SHOW_CHAR, (intptr)def_val,
              lock, binlog_status_arg, on_check_func, on_update_func,
Sergei Golubchik's avatar
Sergei Golubchik committed
1340
              substitute),
1341 1342 1343
    plugin_type(plugin_type_arg)
  {
    option.var_type= GET_STR;
Sergei Golubchik's avatar
Sergei Golubchik committed
1344
    SYSVAR_ASSERT(size == sizeof(plugin_ref));
1345
    SYSVAR_ASSERT(getopt.id < 0); // force NO_CMD_LINE
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359
  }
  bool do_check(THD *thd, set_var *var)
  {
    char buff[STRING_BUFFER_USUAL_SIZE];
    String str(buff,sizeof(buff), system_charset_info), *res;
    if (!(res=var->value->val_str(&str)))
      var->save_result.plugin= NULL;
    else
    {
      const LEX_STRING pname= { const_cast<char*>(res->ptr()), res->length() };
      plugin_ref plugin;

      // special code for storage engines (e.g. to handle historical aliases)
      if (plugin_type == MYSQL_STORAGE_ENGINE_PLUGIN)
1360
        plugin= ha_resolve_by_name(thd, &pname, false);
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
      else
        plugin= my_plugin_lock_by_name(thd, &pname, plugin_type);
      if (!plugin)
      {
        // historically different error code
        if (plugin_type == MYSQL_STORAGE_ENGINE_PLUGIN)
        {
          ErrConvString err(res);
          my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), err.ptr());
        }
        return true;
      }
      var->save_result.plugin= plugin;
    }
    return false;
  }
  void do_update(plugin_ref *valptr, plugin_ref newval)
  {
    plugin_ref oldval= *valptr;
    if (oldval != newval)
    {
1382
      *valptr= newval ? my_plugin_lock(NULL, newval) : 0;
1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400
      plugin_unlock(NULL, oldval);
    }
  }
  bool session_update(THD *thd, set_var *var)
  {
    do_update((plugin_ref*)session_var_ptr(thd),
              var->save_result.plugin);
    return false;
  }
  bool global_update(THD *thd, set_var *var)
  {
    do_update((plugin_ref*)global_var_ptr(),
              var->save_result.plugin);
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
  {
    plugin_ref plugin= global_var(plugin_ref);
1401
    var->save_result.plugin= plugin ? my_plugin_lock(thd, plugin) : 0;
1402
  }
1403
  plugin_ref get_default(THD *thd)
1404
  {
1405 1406
    char *default_value= *reinterpret_cast<char**>(option.def_value);
    if (!default_value)
1407
      return 0;
1408

1409 1410
    LEX_STRING pname= { default_value, strlen(pname.str) };
    plugin_ref plugin;
1411

1412 1413 1414 1415 1416 1417
    if (plugin_type == MYSQL_STORAGE_ENGINE_PLUGIN)
      plugin= ha_resolve_by_name(thd, &pname, false);
    else
      plugin= my_plugin_lock_by_name(thd, &pname, plugin_type);
    DBUG_ASSERT(plugin);
    return my_plugin_lock(thd, plugin);
1418
  }
1419 1420

  void global_save_default(THD *thd, set_var *var)
1421
  {
1422
    var->save_result.plugin= get_default(thd);
1423
  }
1424 1425

  uchar *valptr(THD *thd, plugin_ref plugin)
1426 1427 1428 1429
  {
    return (uchar*)(plugin ? thd->strmake(plugin_name(plugin)->str,
                                          plugin_name(plugin)->length) : 0);
  }
1430 1431 1432 1433 1434 1435
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
  { return valptr(thd, session_var(thd, plugin_ref)); }
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
  { return valptr(thd, global_var(plugin_ref)); }
  uchar *default_value_ptr(THD *thd)
  { return valptr(thd, get_default(thd)); }
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451
};

#if defined(ENABLED_DEBUG_SYNC)
/**
  The class for @@debug_sync session-only variable
*/
class Sys_var_debug_sync :public sys_var
{
public:
  Sys_var_debug_sync(const char *name_arg,
               const char *comment, int flag_args,
               CMD_LINE getopt,
               const char *def_val, PolyLock *lock=0,
               enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
               on_check_function on_check_func=0,
               on_update_function on_update_func=0,
Sergei Golubchik's avatar
Sergei Golubchik committed
1452
               const char *substitute=0)
1453 1454 1455
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, 0, getopt.id,
              getopt.arg_type, SHOW_CHAR, (intptr)def_val,
              lock, binlog_status_arg, on_check_func, on_update_func,
Sergei Golubchik's avatar
Sergei Golubchik committed
1456
              substitute)
1457
  {
Sergei Golubchik's avatar
Sergei Golubchik committed
1458
    SYSVAR_ASSERT(scope() == ONLY_SESSION);
1459
    option.var_type= GET_STR;
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
  }
  bool do_check(THD *thd, set_var *var)
  {
    char buff[STRING_BUFFER_USUAL_SIZE];
    String str(buff, sizeof(buff), system_charset_info), *res;

    if (!(res=var->value->val_str(&str)))
      var->save_result.string_value.str= const_cast<char*>("");
    else
      var->save_result.string_value.str= thd->strmake(res->ptr(), res->length());
    return false;
  }
  bool session_update(THD *thd, set_var *var)
  {
    extern bool debug_sync_update(THD *thd, char *val_str);
    return debug_sync_update(thd, var->save_result.string_value.str);
  }
  bool global_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(FALSE);
    return true;
  }
  void session_save_default(THD *thd, set_var *var)
  {
    var->save_result.string_value.str= const_cast<char*>("");
    var->save_result.string_value.length= 0;
  }
  void global_save_default(THD *thd, set_var *var)
  {
    DBUG_ASSERT(FALSE);
  }
1491
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
1492 1493 1494 1495
  {
    extern uchar *debug_sync_value_ptr(THD *thd);
    return debug_sync_value_ptr(thd);
  }
1496
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
1497 1498 1499 1500
  {
    DBUG_ASSERT(FALSE);
    return 0;
  }
1501 1502
  uchar *default_value_ptr(THD *thd)
  { return (uchar*)""; }
1503 1504 1505
};
#endif /* defined(ENABLED_DEBUG_SYNC) */

1506

1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544
/**
  The class for bit variables - a variant of boolean that stores the value
  in a bit.

  Class specific constructor arguments:
    ulonglong bitmask_arg - the mask for the bit to set in the ulonglong
                            backing store

  Backing store: ulonglong

  @note
  This class supports the "reverse" semantics, when the value of the bit
  being 0 corresponds to the value of variable being set. To activate it
  use REVERSE(bitmask) instead of simply bitmask in the constructor.

  @note
  variables of this class cannot be set from the command line as
  my_getopt does not support bits.
*/
class Sys_var_bit: public Sys_var_typelib
{
  ulonglong bitmask;
  bool reverse_semantics;
  void set(uchar *ptr, ulonglong value)
  {
    if ((value != 0) ^ reverse_semantics)
      (*(ulonglong *)ptr)|= bitmask;
    else
      (*(ulonglong *)ptr)&= ~bitmask;
  }
public:
  Sys_var_bit(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
          ulonglong bitmask_arg, my_bool def_val, PolyLock *lock=0,
          enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
          on_check_function on_check_func=0,
          on_update_function on_update_func=0,
1545
          const char *substitute=0)
1546 1547 1548
    : Sys_var_typelib(name_arg, comment, flag_args, off, getopt,
                      SHOW_MY_BOOL, bool_values, def_val, lock,
                      binlog_status_arg, on_check_func, on_update_func,
1549
                      substitute)
1550 1551 1552 1553 1554
  {
    option.var_type= GET_BOOL;
    reverse_semantics= my_count_bits(bitmask_arg) > 1;
    bitmask= reverse_semantics ? ~bitmask_arg : bitmask_arg;
    set(global_var_ptr(), def_val);
Sergei Golubchik's avatar
Sergei Golubchik committed
1555
    SYSVAR_ASSERT(def_val < 2);
1556
    SYSVAR_ASSERT(getopt.id < 0); // force NO_CMD_LINE
Sergei Golubchik's avatar
Sergei Golubchik committed
1557
    SYSVAR_ASSERT(size == sizeof(ulonglong));
1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572
  }
  bool session_update(THD *thd, set_var *var)
  {
    set(session_var_ptr(thd), var->save_result.ulonglong_value);
    return false;
  }
  bool global_update(THD *thd, set_var *var)
  {
    set(global_var_ptr(), var->save_result.ulonglong_value);
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
  { var->save_result.ulonglong_value= global_var(ulonglong) & bitmask; }
  void global_save_default(THD *thd, set_var *var)
  { var->save_result.ulonglong_value= option.def_value; }
1573 1574

  uchar *valptr(THD *thd, ulonglong val)
1575
  {
1576
    thd->sys_var_tmp.my_bool_value= reverse_semantics ^ ((val & bitmask) != 0);
1577 1578
    return (uchar*) &thd->sys_var_tmp.my_bool_value;
  }
1579 1580
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
  { return valptr(thd, session_var(thd, ulonglong)); }
1581
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
1582 1583
  { return valptr(thd, global_var(ulonglong)); }
  uchar *default_value_ptr(THD *thd)
1584
  {
1585
    thd->sys_var_tmp.my_bool_value= option.def_value != 0;
1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615
    return (uchar*) &thd->sys_var_tmp.my_bool_value;
  }
};

/**
  The class for variables that have a special meaning for a session,
  such as @@timestamp or @@rnd_seed1, their values typically cannot be read
  from SV structure, and a special "read" callback is provided.

  Class specific constructor arguments:
    everything derived from Sys_var_ulonglong
    session_special_read_function read_func_arg

  Backing store: ulonglong

  @note
  These variables are session-only, global or command-line equivalents
  are not supported as they're generally meaningless.
*/
class Sys_var_session_special: public Sys_var_ulonglong
{
  typedef bool (*session_special_update_function)(THD *thd, set_var *var);
  typedef ulonglong (*session_special_read_function)(THD *thd);

  session_special_read_function read_func;
  session_special_update_function update_func;
public:
  Sys_var_session_special(const char *name_arg,
               const char *comment, int flag_args,
               CMD_LINE getopt,
1616
               ulonglong min_val, ulonglong max_val, uint block_size,
1617 1618 1619 1620
               PolyLock *lock, enum binlog_status_enum binlog_status_arg,
               on_check_function on_check_func,
               session_special_update_function update_func_arg,
               session_special_read_function read_func_arg,
1621
               const char *substitute=0)
1622 1623 1624
    : Sys_var_ulonglong(name_arg, comment, flag_args, 0,
              sizeof(ulonglong), getopt, min_val,
              max_val, 0, block_size, lock, binlog_status_arg, on_check_func, 0,
1625
              substitute),
1626 1627
      read_func(read_func_arg), update_func(update_func_arg)
  {
Sergei Golubchik's avatar
Sergei Golubchik committed
1628
    SYSVAR_ASSERT(scope() == ONLY_SESSION);
1629
    SYSVAR_ASSERT(getopt.id < 0); // NO_CMD_LINE, because the offset is fake
1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
  }
  bool session_update(THD *thd, set_var *var)
  { return update_func(thd, var); }
  bool global_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(FALSE);
    return true;
  }
  void session_save_default(THD *thd, set_var *var)
  { var->value= 0; }
  void global_save_default(THD *thd, set_var *var)
  { DBUG_ASSERT(FALSE); }
1642
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
1643 1644 1645 1646
  {
    thd->sys_var_tmp.ulonglong_value= read_func(thd);
    return (uchar*) &thd->sys_var_tmp.ulonglong_value;
  }
1647
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
1648 1649 1650 1651
  {
    DBUG_ASSERT(FALSE);
    return 0;
  }
1652 1653 1654 1655 1656
  uchar *default_value_ptr(THD *thd)
  {
    thd->sys_var_tmp.ulonglong_value= 0;
    return (uchar*) &thd->sys_var_tmp.ulonglong_value;
  }
1657 1658
};

Sergei Golubchik's avatar
Sergei Golubchik committed
1659

1660 1661 1662
/*
  Dedicated class because of a weird behavior of a default value.
  Assigning timestamp to itself
Sergei Golubchik's avatar
Sergei Golubchik committed
1663

1664 1665 1666 1667 1668 1669
    SET @@timestamp = @@timestamp

  make it non-default and stops the time flow.
*/
class Sys_var_timestamp: public Sys_var_double
{
Sergei Golubchik's avatar
Sergei Golubchik committed
1670
public:
1671
  Sys_var_timestamp(const char *name_arg,
Sergei Golubchik's avatar
Sergei Golubchik committed
1672 1673 1674
               const char *comment, int flag_args,
               CMD_LINE getopt,
               double min_val, double max_val,
1675
               PolyLock *lock, enum binlog_status_enum binlog_status_arg)
Sergei Golubchik's avatar
Sergei Golubchik committed
1676 1677
    : Sys_var_double(name_arg, comment, flag_args, 0,
              sizeof(double), getopt, min_val,
1678
              max_val, 0, lock, binlog_status_arg)
Sergei Golubchik's avatar
Sergei Golubchik committed
1679
  {
Sergei Golubchik's avatar
Sergei Golubchik committed
1680
    SYSVAR_ASSERT(scope() == ONLY_SESSION);
1681
    SYSVAR_ASSERT(getopt.id < 0); // NO_CMD_LINE, because the offset is fake
Sergei Golubchik's avatar
Sergei Golubchik committed
1682 1683
  }
  bool session_update(THD *thd, set_var *var)
1684 1685 1686 1687 1688 1689 1690 1691 1692 1693
  {
    if (var->value)
    {
      my_hrtime_t hrtime = { hrtime_from_time(var->save_result.double_value) };
      thd->set_time(hrtime);
    }
    else // SET timestamp=DEFAULT
      thd->user_time.val= 0;
    return false;
  }
Sergei Golubchik's avatar
Sergei Golubchik committed
1694 1695 1696 1697 1698
  bool global_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(FALSE);
    return true;
  }
1699 1700 1701 1702
  bool session_is_default(THD *thd)
  {
    return thd->user_time.val == 0;
  }
Sergei Golubchik's avatar
Sergei Golubchik committed
1703 1704 1705 1706
  void session_save_default(THD *thd, set_var *var)
  { var->value= 0; }
  void global_save_default(THD *thd, set_var *var)
  { DBUG_ASSERT(FALSE); }
1707
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
Sergei Golubchik's avatar
Sergei Golubchik committed
1708
  {
1709 1710
    thd->sys_var_tmp.double_value= thd->start_time +
          thd->start_time_sec_part/(double)TIME_SECOND_PART_FACTOR;
Sergei Golubchik's avatar
Sergei Golubchik committed
1711 1712
    return (uchar*) &thd->sys_var_tmp.double_value;
  }
1713
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
Sergei Golubchik's avatar
Sergei Golubchik committed
1714 1715 1716 1717
  {
    DBUG_ASSERT(FALSE);
    return 0;
  }
1718 1719 1720 1721 1722
  uchar *default_value_ptr(THD *thd)
  {
    thd->sys_var_tmp.double_value= 0;
    return (uchar*) &thd->sys_var_tmp.double_value;
  }
Sergei Golubchik's avatar
Sergei Golubchik committed
1723 1724 1725
};


1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745
/**
  The class for read-only variables that show whether a particular
  feature is supported by the server. Example: have_compression

  Backing store: enum SHOW_COMP_OPTION

  @note
  These variables are necessarily read-only, only global, and have no
  command-line equivalent.
*/
class Sys_var_have: public sys_var
{
public:
  Sys_var_have(const char *name_arg,
               const char *comment, int flag_args, ptrdiff_t off, size_t size,
               CMD_LINE getopt,
               PolyLock *lock=0,
               enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
               on_check_function on_check_func=0,
               on_update_function on_update_func=0,
Sergei Golubchik's avatar
Sergei Golubchik committed
1746
               const char *substitute=0)
1747 1748 1749
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
              getopt.arg_type, SHOW_CHAR, 0,
              lock, binlog_status_arg, on_check_func, on_update_func,
Sergei Golubchik's avatar
Sergei Golubchik committed
1750
              substitute)
1751
  {
Sergei Golubchik's avatar
Sergei Golubchik committed
1752
    SYSVAR_ASSERT(scope() == GLOBAL);
1753
    SYSVAR_ASSERT(getopt.id < 0);
Sergei Golubchik's avatar
Sergei Golubchik committed
1754 1755 1756 1757 1758
    SYSVAR_ASSERT(lock == 0);
    SYSVAR_ASSERT(binlog_status_arg == VARIABLE_NOT_IN_BINLOG);
    SYSVAR_ASSERT(is_readonly());
    SYSVAR_ASSERT(on_update == 0);
    SYSVAR_ASSERT(size == sizeof(enum SHOW_COMP_OPTION));
1759
    option.var_type= GET_STR;
1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776
  }
  bool do_check(THD *thd, set_var *var) {
    DBUG_ASSERT(FALSE);
    return true;
  }
  bool session_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(FALSE);
    return true;
  }
  bool global_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(FALSE);
    return true;
  }
  void session_save_default(THD *thd, set_var *var) { }
  void global_save_default(THD *thd, set_var *var) { }
1777
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
1778 1779 1780 1781
  {
    DBUG_ASSERT(FALSE);
    return 0;
  }
1782
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813
  {
    return (uchar*)show_comp_option_name[global_var(enum SHOW_COMP_OPTION)];
  }
};

/**
  Generic class for variables for storing entities that are internally
  represented as structures, have names, and possibly can be referred to by
  numbers.  Examples: character sets, collations, locales,

  Class specific constructor arguments:
    ptrdiff_t name_offset  - offset of the 'name' field in the structure

  Backing store: void*

  @note
  As every such a structure requires special treatment from my_getopt,
  these variables don't support command-line equivalents, any such
  command-line options should be added manually to my_long_options in mysqld.cc
*/
class Sys_var_struct: public sys_var
{
  ptrdiff_t name_offset; // offset to the 'name' property in the structure
public:
  Sys_var_struct(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
          ptrdiff_t name_off, void *def_val, PolyLock *lock=0,
          enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
          on_check_function on_check_func=0,
          on_update_function on_update_func=0,
Sergei Golubchik's avatar
Sergei Golubchik committed
1814
          const char *substitute=0)
1815 1816 1817
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
              getopt.arg_type, SHOW_CHAR, (intptr)def_val,
              lock, binlog_status_arg, on_check_func, on_update_func,
Sergei Golubchik's avatar
Sergei Golubchik committed
1818
              substitute),
Marc Alff's avatar
Marc Alff committed
1819
      name_offset(name_off)
1820
  {
1821
    option.var_type= GET_ENUM; // because we accept INT and STRING here
1822 1823 1824 1825 1826 1827 1828 1829
    /*
      struct variables are special on the command line - often (e.g. for
      charsets) the name cannot be immediately resolved, but only after all
      options (in particular, basedir) are parsed.

      thus all struct command-line options should be added manually
      to my_long_options in mysqld.cc
    */
1830
    SYSVAR_ASSERT(getopt.id < 0);
Sergei Golubchik's avatar
Sergei Golubchik committed
1831
    SYSVAR_ASSERT(size == sizeof(void *));
1832 1833 1834 1835 1836
  }
  bool do_check(THD *thd, set_var *var)
  { return false; }
  bool session_update(THD *thd, set_var *var)
  {
1837
    session_var(thd, const void*)= var->save_result.ptr;
1838 1839 1840 1841
    return false;
  }
  bool global_update(THD *thd, set_var *var)
  {
1842
    global_var(const void*)= var->save_result.ptr;
1843 1844 1845 1846 1847
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
  { var->save_result.ptr= global_var(void*); }
  void global_save_default(THD *thd, set_var *var)
1848 1849 1850 1851
  {
    void **default_value= reinterpret_cast<void**>(option.def_value);
    var->save_result.ptr= *default_value;
  }
1852 1853
  uchar *valptr(THD *thd, uchar *val)
  { return val ? *(uchar**)(val+name_offset) : 0; }
1854
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
1855
  { return valptr(thd, session_var(thd, uchar*)); }
1856
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
1857 1858 1859
  { return valptr(thd, global_var(uchar*)); }
  uchar *default_value_ptr(THD *thd)
  { return valptr(thd, *(uchar**)option.def_value); }
1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881
};

/**
  The class for variables that store time zones

  Backing store: Time_zone*

  @note
  Time zones cannot be supported directly by my_getopt, thus
  these variables don't support command-line equivalents, any such
  command-line options should be added manually to my_long_options in mysqld.cc
*/
class Sys_var_tz: public sys_var
{
public:
  Sys_var_tz(const char *name_arg,
             const char *comment, int flag_args, ptrdiff_t off, size_t size,
             CMD_LINE getopt,
             Time_zone **def_val, PolyLock *lock=0,
             enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,
             on_check_function on_check_func=0,
             on_update_function on_update_func=0,
Sergei Golubchik's avatar
Sergei Golubchik committed
1882
             const char *substitute=0)
1883 1884 1885
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
              getopt.arg_type, SHOW_CHAR, (intptr)def_val,
              lock, binlog_status_arg, on_check_func, on_update_func,
Sergei Golubchik's avatar
Sergei Golubchik committed
1886
              substitute)
1887
  {
1888
    SYSVAR_ASSERT(getopt.id < 0);
Sergei Golubchik's avatar
Sergei Golubchik committed
1889
    SYSVAR_ASSERT(size == sizeof(Time_zone *));
1890
    option.var_type= GET_STR;
1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927
  }
  bool do_check(THD *thd, set_var *var)
  {
    char buff[MAX_TIME_ZONE_NAME_LENGTH];
    String str(buff, sizeof(buff), &my_charset_latin1);
    String *res= var->value->val_str(&str);

    if (!res)
      return true;

    if (!(var->save_result.time_zone= my_tz_find(thd, res)))
    {
      ErrConvString err(res);
      my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), err.ptr());
      return true;
    }
    return false;
  }
  bool session_update(THD *thd, set_var *var)
  {
    session_var(thd, Time_zone*)= var->save_result.time_zone;
    return false;
  }
  bool global_update(THD *thd, set_var *var)
  {
    global_var(Time_zone*)= var->save_result.time_zone;
    return false;
  }
  void session_save_default(THD *thd, set_var *var)
  {
    var->save_result.time_zone= global_var(Time_zone*);
  }
  void global_save_default(THD *thd, set_var *var)
  {
    var->save_result.time_zone=
      *(Time_zone**)(intptr)option.def_value;
  }
1928 1929
  uchar *valptr(THD *thd, Time_zone *val)
  { return (uchar *)(val->get_name()->ptr()); }
1930
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
1931 1932 1933 1934 1935 1936 1937 1938 1939 1940
  {
    /*
      This is an ugly fix for replication: we don't replicate properly queries
      invoking system variables' values to update tables; but
      CONVERT_TZ(,,@@session.time_zone) is so popular that we make it
      replicable (i.e. we tell the binlog code to store the session
      timezone). If it's the global value which was used we can't replicate
      (binlog code stores session value only).
    */
    thd->time_zone_used= 1;
1941
    return valptr(thd, session_var(thd, Time_zone *));
1942
  }
1943
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
1944 1945 1946
  { return valptr(thd, global_var(Time_zone*)); }
  uchar *default_value_ptr(THD *thd)
  { return valptr(thd, *(Time_zone**)option.def_value); }
1947 1948
};

1949 1950 1951 1952 1953 1954 1955
/**
  Special implementation for transaction isolation, that
  distingushes between

  SET GLOBAL TRANSACTION ISOLATION (stored in global_system_variables)
  SET SESSION TRANSACTION ISOLATION (stored in thd->variables)
  SET TRANSACTION ISOLATION (stored in thd->tx_isolation)
1956

1957 1958
  where the last statement sets isolation level for the next transaction only
*/
1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970
class Sys_var_tx_isolation: public Sys_var_enum
{
public:
  Sys_var_tx_isolation(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
          const char *values[], uint def_val, PolyLock *lock,
          enum binlog_status_enum binlog_status_arg,
          on_check_function on_check_func)
    :Sys_var_enum(name_arg, comment, flag_args, off, size, getopt,
                  values, def_val, lock, binlog_status_arg, on_check_func)
  {}
1971 1972 1973 1974 1975 1976 1977 1978
  bool session_update(THD *thd, set_var *var)
  {
    if (var->type == OPT_SESSION && Sys_var_enum::session_update(thd, var))
      return TRUE;
    if (var->type == OPT_DEFAULT || !thd->in_active_multi_stmt_transaction())
      thd->tx_isolation= (enum_tx_isolation) var->save_result.ulonglong_value;
    return FALSE;
  }
1979 1980
};

1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004

/**
  Class representing the tx_read_only system variable for setting
  default transaction access mode.

  Note that there is a special syntax - SET TRANSACTION READ ONLY
  (or READ WRITE) that sets the access mode for the next transaction
  only.
*/

class Sys_var_tx_read_only: public Sys_var_mybool
{
public:
  Sys_var_tx_read_only(const char *name_arg, const char *comment, int flag_args,
                       ptrdiff_t off, size_t size, CMD_LINE getopt,
                       my_bool def_val, PolyLock *lock,
                       enum binlog_status_enum binlog_status_arg,
                       on_check_function on_check_func)
    :Sys_var_mybool(name_arg, comment, flag_args, off, size, getopt,
                    def_val, lock, binlog_status_arg, on_check_func)
  {}
  virtual bool session_update(THD *thd, set_var *var);
};

2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015
/*
  Class for replicate_events_marked_for_skip.
  We need a custom update function that ensures the slave is stopped when
  the update is happening.
*/
class Sys_var_replicate_events_marked_for_skip: public Sys_var_enum
{
public:
  Sys_var_replicate_events_marked_for_skip(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt,
2016 2017
          const char *values[], uint def_val, PolyLock *lock= 0,
          enum binlog_status_enum binlog_status_arg= VARIABLE_NOT_IN_BINLOG)
2018
    :Sys_var_enum(name_arg, comment, flag_args, off, size, getopt,
2019
                  values, def_val, lock, binlog_status_arg)
2020 2021 2022 2023
  {}
  bool global_update(THD *thd, set_var *var);
};

2024 2025 2026 2027 2028 2029 2030 2031 2032
/*
  Class for handing multi-source replication variables
  Variable values are store in Master_info, but to make it possible to
  access variable without locks we also store it thd->variables.
  These can be used as GLOBAL or SESSION, but both points to the same
  variable.  This is to make things compatible with MySQL 5.5 where variables
  like sql_slave_skip_counter are GLOBAL.
*/

2033 2034
#define MASTER_INFO_VAR(X) my_offsetof(Master_info, X), sizeof(((Master_info *)0x10)->X)
class Sys_var_multi_source_ulonglong;
2035 2036 2037 2038 2039 2040 2041 2042
class Master_info;

typedef bool (*on_multi_source_update_function)(sys_var *self, THD *thd,
                                                Master_info *mi);
bool update_multi_source_variable(sys_var *self,
                                  THD *thd, enum_var_type type);


2043
class Sys_var_multi_source_ulonglong :public Sys_var_ulonglong
2044 2045
{ 
  ptrdiff_t master_info_offset;
2046
  on_multi_source_update_function update_multi_source_variable_func;
2047
public:
2048
  Sys_var_multi_source_ulonglong(const char *name_arg,
2049 2050 2051 2052
                             const char *comment, int flag_args,
                             ptrdiff_t off, size_t size,
                             CMD_LINE getopt,
                             ptrdiff_t master_info_offset_arg,
2053 2054 2055
                             size_t master_info_arg_size,
                             ulonglong min_val, ulonglong max_val,
                             ulonglong def_val, uint block_size,
2056
                             on_multi_source_update_function on_update_func)
2057 2058 2059
    :Sys_var_ulonglong(name_arg, comment, flag_args, off, size,
                       getopt, min_val, max_val, def_val, block_size,
                       0, VARIABLE_NOT_IN_BINLOG, 0, update_multi_source_variable),
2060 2061 2062
    master_info_offset(master_info_offset_arg),
    update_multi_source_variable_func(on_update_func)
  {
2063
    SYSVAR_ASSERT(master_info_arg_size == size);
2064 2065 2066 2067 2068 2069 2070 2071 2072 2073
  }
  bool global_update(THD *thd, set_var *var)
  {
    return session_update(thd, var);
  }
  void session_save_default(THD *thd, set_var *var)
  {
    /* Use value given in variable declaration */
    global_save_default(thd, var);
  }
2074
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
2075
  {
2076 2077 2078
    ulonglong *tmp, res;
    tmp= (ulonglong*) (((uchar*)&(thd->variables)) + offset);
    res= get_master_info_ulonglong_value(thd, master_info_offset);
2079 2080 2081
    *tmp= res;
    return (uchar*) tmp;
  }
2082
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
2083 2084 2085
  {
    return session_value_ptr(thd, base);
  }
2086
  ulonglong get_master_info_ulonglong_value(THD *thd, ptrdiff_t offset);
2087 2088 2089 2090
  bool update_variable(THD *thd, Master_info *mi)
  {
    return update_multi_source_variable_func(this, thd, mi);
  }
2091 2092
};

unknown's avatar
unknown committed
2093 2094

/**
unknown's avatar
unknown committed
2095
  Class for @@global.gtid_current_pos.
unknown's avatar
unknown committed
2096
*/
unknown's avatar
unknown committed
2097
class Sys_var_gtid_current_pos: public sys_var
unknown's avatar
unknown committed
2098 2099
{
public:
unknown's avatar
unknown committed
2100 2101 2102 2103 2104 2105 2106
  Sys_var_gtid_current_pos(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt)
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
              getopt.arg_type, SHOW_CHAR, 0, NULL, VARIABLE_NOT_IN_BINLOG,
              NULL, NULL, NULL)
  {
2107 2108
    SYSVAR_ASSERT(getopt.id < 0);
    SYSVAR_ASSERT(is_readonly());
unknown's avatar
unknown committed
2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133
    option.var_type= GET_STR;
  }
  bool do_check(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
    return true;
  }
  bool session_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
    return true;
  }
  bool global_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
    return true;
  }
  void session_save_default(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
  }
  void global_save_default(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
  }
2134
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
unknown's avatar
unknown committed
2135 2136 2137 2138
  {
    DBUG_ASSERT(false);
    return NULL;
  }
2139
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base);
unknown's avatar
unknown committed
2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155
};


/**
  Class for @@global.gtid_binlog_pos.
*/
class Sys_var_gtid_binlog_pos: public sys_var
{
public:
  Sys_var_gtid_binlog_pos(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt)
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
              getopt.arg_type, SHOW_CHAR, 0, NULL, VARIABLE_NOT_IN_BINLOG,
              NULL, NULL, NULL)
  {
2156 2157
    SYSVAR_ASSERT(getopt.id < 0);
    SYSVAR_ASSERT(is_readonly());
unknown's avatar
unknown committed
2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182
    option.var_type= GET_STR;
  }
  bool do_check(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
    return true;
  }
  bool session_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
    return true;
  }
  bool global_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
    return true;
  }
  void session_save_default(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
  }
  void global_save_default(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
  }
2183
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
unknown's avatar
unknown committed
2184 2185 2186 2187
  {
    DBUG_ASSERT(false);
    return NULL;
  }
2188
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base);
unknown's avatar
unknown committed
2189 2190 2191 2192 2193 2194 2195 2196 2197 2198
};


/**
  Class for @@global.gtid_slave_pos.
*/
class Sys_var_gtid_slave_pos: public sys_var
{
public:
  Sys_var_gtid_slave_pos(const char *name_arg,
unknown's avatar
unknown committed
2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt)
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
              getopt.arg_type, SHOW_CHAR, 0, NULL, VARIABLE_NOT_IN_BINLOG,
              NULL, NULL, NULL)
  {
    option.var_type= GET_STR;
  }
  bool do_check(THD *thd, set_var *var);
  bool session_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
    return true;
  }
  bool global_update(THD *thd, set_var *var);
  void session_save_default(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
  }
  void global_save_default(THD *thd, set_var *var)
  {
    /* Record the attempt to use default so we can error. */
    var->value= 0;
  }
2223
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
unknown's avatar
unknown committed
2224 2225 2226 2227
  {
    DBUG_ASSERT(false);
    return NULL;
  }
2228
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base);
2229 2230
  uchar *default_value_ptr(THD *thd)
  { return 0; }
unknown's avatar
unknown committed
2231
};
unknown's avatar
unknown committed
2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264


/**
  Class for @@global.gtid_binlog_state.
*/
class Sys_var_gtid_binlog_state: public sys_var
{
public:
  Sys_var_gtid_binlog_state(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
          CMD_LINE getopt)
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
              getopt.arg_type, SHOW_CHAR, 0, NULL, VARIABLE_NOT_IN_BINLOG,
              NULL, NULL, NULL)
  {
    option.var_type= GET_STR;
  }
  bool do_check(THD *thd, set_var *var);
  bool session_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
    return true;
  }
  bool global_update(THD *thd, set_var *var);
  void session_save_default(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
  }
  void global_save_default(THD *thd, set_var *var)
  {
    /* Record the attempt to use default so we can error. */
    var->value= 0;
  }
2265
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base)
unknown's avatar
unknown committed
2266 2267 2268 2269
  {
    DBUG_ASSERT(false);
    return NULL;
  }
2270
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base);
2271 2272
  uchar *default_value_ptr(THD *thd)
  { return 0; }
unknown's avatar
unknown committed
2273
};
2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287


/**
  Class for @@session.last_gtid.
*/
class Sys_var_last_gtid: public sys_var
{
public:
  Sys_var_last_gtid(const char *name_arg,
          const char *comment, int flag_args, CMD_LINE getopt)
    : sys_var(&all_sys_vars, name_arg, comment, flag_args, 0, getopt.id,
              getopt.arg_type, SHOW_CHAR, 0, NULL, VARIABLE_NOT_IN_BINLOG,
              NULL, NULL, NULL)
  {
2288 2289
    SYSVAR_ASSERT(getopt.id < 0);
    SYSVAR_ASSERT(is_readonly());
2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314
    option.var_type= GET_STR;
  }
  bool do_check(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
    return true;
  }
  bool session_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
    return true;
  }
  bool global_update(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
    return true;
  }
  void session_save_default(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
  }
  void global_save_default(THD *thd, set_var *var)
  {
    DBUG_ASSERT(false);
  }
2315 2316
  uchar *session_value_ptr(THD *thd, const LEX_STRING *base);
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base)
2317 2318 2319 2320 2321
  {
    DBUG_ASSERT(false);
    return NULL;
  }
};
2322 2323 2324 2325 2326


/**
   Class for connection_name.slave_parallel_mode.
*/
2327
class Sys_var_slave_parallel_mode: public Sys_var_enum
2328 2329 2330 2331
{
public:
  Sys_var_slave_parallel_mode(const char *name_arg,
          const char *comment, int flag_args, ptrdiff_t off, size_t size,
2332 2333 2334 2335
          CMD_LINE getopt, const char *values[],
          enum_slave_parallel_mode def_val)
    : Sys_var_enum(name_arg, comment, flag_args, off, size,
                   getopt, values, def_val)
2336 2337 2338 2339 2340 2341 2342 2343
  {
    option.var_type|= GET_ASK_ADDR;
    option.value= (uchar**)1; // crash me, please
    SYSVAR_ASSERT(scope() == GLOBAL);
  }
  bool global_update(THD *thd, set_var *var);
  uchar *global_value_ptr(THD *thd, const LEX_STRING *base);
};