MySQL  8.0.27
Source Code Documentation
sys_vars.h
Go to the documentation of this file.
1 #ifndef SYS_VARS_H_INCLUDED
2 #define SYS_VARS_H_INCLUDED
3 /* Copyright (c) 2002, 2021, Oracle and/or its affiliates.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License, version 2.0,
7  as published by the Free Software Foundation.
8 
9  This program is also distributed with certain software (including
10  but not limited to OpenSSL) that is licensed under separate terms,
11  as designated in a particular file or component or in included license
12  documentation. The authors of MySQL hereby grant you an additional
13  permission to link the program and your derivative works with the
14  separately licensed software that they have included with MySQL.
15 
16  This program is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License, version 2.0, for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
24 
25 /**
26  @file
27  "private" interface to sys_var - server configuration variables.
28 
29  This header is included only by the file that contains declarations
30  of sys_var variables (sys_vars.cc).
31 */
32 
33 #include "my_config.h"
34 
35 #include <stddef.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <sys/types.h>
39 #include <time.h>
40 
41 #include "keycache.h" // dflt_key_cache
42 #include "lex_string.h"
43 #include "m_ctype.h"
44 #include "my_base.h"
45 #include "my_bit.h" // my_count_bits
46 #include "my_compiler.h"
47 #include "my_dbug.h"
48 #include "my_getopt.h"
49 #include "my_inttypes.h"
50 #include "my_sys.h"
51 #include "mysql/plugin.h"
53 #include "mysql/status_var.h"
55 #include "mysqld_error.h"
57 #include "sql/debug_sync.h" // debug_sync_update
58 #include "sql/handler.h"
59 #include "sql/item.h" // Item
60 #include "sql/keycaches.h" // default_key_cache_base
61 #include "sql/mysqld.h" // max_system_variables
62 #include "sql/rpl_gtid.h"
63 #include "sql/set_var.h" // sys_var_chain
64 #include "sql/sql_class.h" // THD
65 #include "sql/sql_connect.h"
66 #include "sql/sql_const.h"
67 #include "sql/sql_error.h"
68 #include "sql/sql_plugin.h" // my_plugin_lock_by_name
69 #include "sql/sql_plugin_ref.h"
70 #include "sql/strfunc.h" // find_type
72 #include "sql/sys_vars_shared.h" // throw_bounds_warning
73 #include "sql/tztime.h" // Time_zone
74 #include "sql_string.h"
75 #include "typelib.h"
76 
77 class Sys_var_bit;
78 class Sys_var_bool;
79 class Sys_var_charptr;
80 class Sys_var_double;
82 class Sys_var_enum;
83 class Sys_var_flagset;
84 class Sys_var_gtid_mode;
85 class Sys_var_have;
86 class Sys_var_lexstring;
87 class Sys_var_multi_enum;
88 class Sys_var_plugin;
89 class Sys_var_set;
90 class Sys_var_tz;
91 struct CMD_LINE;
92 struct System_variables;
93 template <typename Struct_type, typename Name_getter>
94 class Sys_var_struct;
95 template <typename T, ulong ARGT, enum enum_mysql_show_type SHOWT, bool SIGNED>
96 class Sys_var_integer;
97 
98 /*
99  a set of mostly trivial (as in f(X)=X) defines below to make system variable
100  declarations more readable
101 */
102 #define VALID_RANGE(X, Y) X, Y
103 #define DEFAULT(X) X
104 #define BLOCK_SIZE(X) X
105 #define GLOBAL_VAR(X) \
106  sys_var::GLOBAL, (((const char *)&(X)) - (char *)&global_system_variables), \
107  sizeof(X)
108 #define SESSION_VAR(X) \
109  sys_var::SESSION, offsetof(System_variables, X), \
110  sizeof(((System_variables *)0)->X)
111 #define SESSION_ONLY(X) \
112  sys_var::ONLY_SESSION, offsetof(System_variables, X), \
113  sizeof(((System_variables *)0)->X)
114 #define NO_CMD_LINE CMD_LINE(NO_ARG, -1)
115 /*
116  the define below means that there's no *second* mutex guard,
117  LOCK_global_system_variables always guards all system variables
118 */
119 #define NO_MUTEX_GUARD ((PolyLock *)0)
120 #define IN_BINLOG sys_var::SESSION_VARIABLE_IN_BINLOG
121 #define NOT_IN_BINLOG sys_var::VARIABLE_NOT_IN_BINLOG
122 #define ON_READ(X) X
123 #define ON_CHECK(X) X
124 #define PRE_UPDATE(X) X
125 #define ON_UPDATE(X) X
126 #define READ_ONLY sys_var::READONLY +
127 #define NOT_VISIBLE sys_var::INVISIBLE +
128 #define UNTRACKED_DEFAULT sys_var::TRI_LEVEL +
129 #define HINT_UPDATEABLE sys_var::HINT_UPDATEABLE +
130 // this means that Sys_var_charptr initial value was malloc()ed
131 #define PREALLOCATED sys_var::ALLOCATED +
132 #define NON_PERSIST sys_var::NOTPERSIST +
133 #define PERSIST_AS_READONLY sys_var::PERSIST_AS_READ_ONLY +
134 
135 /*
136  Sys_var_bit meaning is reversed, like in
137  @@foreign_key_checks <-> OPTION_NO_FOREIGN_KEY_CHECKS
138 */
139 #define REVERSE(X) ~(X)
140 #define DEPRECATED_VAR(X) X
141 
142 #define session_var(THD, TYPE) (*(TYPE *)session_var_ptr(THD))
143 #define global_var(TYPE) (*(TYPE *)global_var_ptr())
144 
145 #define GET_HA_ROWS GET_ULL
146 
148 
150 
151 static const char *bool_values[3] = {"OFF", "ON", nullptr};
152 
153 const char *fixup_enforce_gtid_consistency_command_line(char *value_arg);
154 
155 /**
156  A small wrapper class to pass getopt arguments as a pair
157  to the Sys_var_* constructors. It improves type safety and helps
158  to catch errors in the argument order.
159 */
160 struct CMD_LINE {
161  int id;
163  CMD_LINE(enum get_opt_arg_type getopt_arg_type, int getopt_id = 0)
164  : id(getopt_id), arg_type(getopt_arg_type) {}
165 };
166 
167 /**
168  Sys_var_integer template is used to generate Sys_var_* classes
169  for variables that represent the value as a signed or unsigned integer.
170  They are Sys_var_uint, Sys_var_ulong, Sys_var_harows, Sys_var_ulonglong,
171  and Sys_var_long.
172 
173  An integer variable has a minimal and maximal values, and a "block_size"
174  (any valid value of the variable must be divisible by the block_size).
175 
176  Class specific constructor arguments: min, max, block_size
177  Backing store: uint, ulong, ha_rows, ulonglong, long, depending on the
178  Sys_var_*
179 */
180 // clang-format off
181 template <typename T, ulong ARGT, enum enum_mysql_show_type SHOWT, bool SIGNED>
182 class Sys_var_integer : public sys_var {
183  public:
185  const char *name_arg, const char *comment, int flag_args,
186  ptrdiff_t off, size_t size [[maybe_unused]], CMD_LINE getopt,
187  T min_val, T max_val, T def_val, uint block_size,
188  PolyLock *lock = nullptr,
189  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
190  on_check_function on_check_func = nullptr,
191  on_update_function on_update_func = nullptr,
192  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
193  : sys_var(&all_sys_vars, name_arg, comment, flag_args, off,
194  getopt.id, getopt.arg_type, SHOWT, def_val, lock,
195  binlog_status_arg, on_check_func, on_update_func,
196  substitute, parse_flag) {
197  option.var_type = ARGT;
198  if ((min_val % block_size) != 0)
199  min_val += block_size - (min_val % block_size);
200  option.min_value = min_val;
201  option.max_value = max_val - (max_val % block_size);
202  option.block_size = block_size;
204  if (max_var_ptr()) * max_var_ptr() = max_val;
205 
206  // Do not set global_var for Sys_var_keycache objects
207  if (offset >= 0) global_var(T) = def_val;
208 
209  assert(size == sizeof(T));
210  assert(min_val <= def_val);
211  assert(def_val <= max_val);
212  assert(block_size > 0);
213  assert(option.min_value % block_size == 0);
214  assert(def_val % block_size == 0);
215  assert(option.max_value % block_size == 0);
216  }
217  bool do_check(THD *thd, set_var *var) override {
218  bool fixed = false;
219  longlong v;
220  ulonglong uv;
221 
222  v = var->value->val_int();
223  if (SIGNED) { /* target variable has signed type */
224  if (var->value->unsigned_flag) {
225  /*
226  Input value is such a large positive number that MySQL used
227  an unsigned item to hold it. When cast to a signed longlong,
228  if the result is negative there is "cycling" and this is
229  incorrect (large positive input value should not end up as a
230  large negative value in the session signed variable to be
231  set); instead, we need to pick the allowed number closest to
232  the positive input value, i.e. pick the biggest allowed
233  positive integer.
234  */
235  if (v < 0)
236  uv = max_of_int_range(ARGT);
237  else /* no cycling, longlong can hold true value */
238  uv = (ulonglong)v;
239  } else
240  uv = v;
241  /* This will further restrict with VALID_RANGE, BLOCK_SIZE */
243  getopt_ll_limit_value(uv, &option, &fixed);
244  } else {
245  if (var->value->unsigned_flag) {
246  /* Guaranteed positive input value, ulonglong can hold it */
247  uv = (ulonglong)v;
248  } else {
249  /*
250  Maybe negative input value; in this case, cast to ulonglong
251  makes it positive, which is wrong. Pick the closest allowed
252  value i.e. 0.
253  */
254  uv = (ulonglong)(v < 0 ? 0 : v);
255  }
257  getopt_ull_limit_value(uv, &option, &fixed);
258  }
259 
260  if (max_var_ptr()) {
261  /* check constraint set with --maximum-...=X */
262  if (SIGNED) {
263  longlong max_val = *max_var_ptr();
264  if (((longlong)(var->save_result.ulonglong_value)) > max_val)
265  var->save_result.ulonglong_value = max_val;
266  /*
267  Signed variable probably has some kind of symmetry. Then
268  it's good to limit negative values just as we limit positive
269  values.
270  */
271  max_val = -max_val;
272  if (((longlong)(var->save_result.ulonglong_value)) < max_val)
273  var->save_result.ulonglong_value = max_val;
274  } else {
275  ulonglong max_val = *max_var_ptr();
276  if (var->save_result.ulonglong_value > max_val)
277  var->save_result.ulonglong_value = max_val;
278  }
279  }
280 
281  return throw_bounds_warning(
282  thd, name.str, var->save_result.ulonglong_value != (ulonglong)v,
283  var->value->unsigned_flag, v);
284  }
285  bool session_update(THD *thd, set_var *var) override {
286  session_var(thd, T) = static_cast<T>(var->save_result.ulonglong_value);
287  return false;
288  }
289  bool global_update(THD *, set_var *var) override {
290  global_var(T) = static_cast<T>(var->save_result.ulonglong_value);
291  return false;
292  }
294  return type != INT_RESULT;
295  }
296  void session_save_default(THD *thd, set_var *var) override {
297  var->save_result.ulonglong_value = static_cast<ulonglong>(
298  *pointer_cast<const T *>(global_value_ptr(thd, nullptr)));
299  }
300  void global_save_default(THD *, set_var *var) override {
302  }
303  void saved_value_to_string(THD *, set_var *var, char *def_val) override {
304  if (SIGNED)
306  def_val, -10);
307  else
309  def_val, 10);
310  }
311 
312  private:
313  T *max_var_ptr() {
314  return scope() == SESSION
315  ? (T *)(((uchar *)&max_system_variables) + offset)
316  : nullptr;
317  }
318 };
319 // clang-format on
320 
329 
330 /**
331  A sys_var that is an alias for another sys_var.
332 
333  The two variables effectively share (almost) all members, so
334  whenever you change one of them, it affects both.
335 
336  Usually you want to use Sys_var_deprecated_alias instead.
337 */
338 class Sys_var_alias : public sys_var {
339  private:
341 
342  protected:
343  /**
344  Special constructor used to implement Sys_var_deprecated alias.
345 
346  @param name_arg The name of this sys_var.
347 
348  @param base_var The "parent" sys_var that this sys_var is an alias
349  for.
350 
351  @param deprecation_substitute_arg The deprecation_substitute to
352  use for this variable. While other fields in the created variable
353  are inherited from real_var, the deprecation_substitute can be set
354  using this parameter.
355 
356  @param persisted_alias When this variable is persisted, it will
357  duplicate the entry in the persisted variables file: It will be
358  stored both using the variable name name_arg, and the name of
359  persisted_alias.
360 
361  @param is_persisted_deprecated If true, this variable is
362  deprecated when appearing in the persisted variables file.
363  */
364  Sys_var_alias(const char *name_arg, sys_var &base_var,
365  const char *deprecation_substitute_arg,
366  sys_var *persisted_alias, bool is_persisted_deprecated)
367  : sys_var(&all_sys_vars, name_arg, base_var.option.comment,
368  base_var.flags, base_var.offset, base_var.option.id,
369  base_var.option.arg_type, base_var.show_val_type,
370  base_var.option.def_value, base_var.guard,
371  base_var.binlog_status, base_var.on_check, base_var.on_update,
372  deprecation_substitute_arg, base_var.m_parse_flag,
373  persisted_alias, is_persisted_deprecated),
374  m_base_var(base_var) {
375  option = base_var.option;
376  option.name = name_arg;
377  }
378 
379  public:
380  Sys_var_alias(const char *name_arg, sys_var &base_var)
381  : Sys_var_alias(name_arg, base_var, base_var.deprecation_substitute,
382  nullptr, false) {}
383 
385 
386  virtual void cleanup() override { m_base_var.cleanup(); }
387  virtual sys_var_pluginvar *cast_pluginvar() override {
388  return m_base_var.cast_pluginvar();
389  }
390  virtual void update_default(longlong new_def_value) override {
391  m_base_var.update_default(new_def_value);
392  }
393  virtual longlong get_default() override { return m_base_var.get_default(); }
394  virtual longlong get_min_value() override {
395  return m_base_var.get_min_value();
396  }
397  virtual ulonglong get_max_value() override {
398  return m_base_var.get_max_value();
399  }
400  virtual ulong get_var_type() override { return m_base_var.get_var_type(); }
401  virtual void set_arg_source(get_opt_arg_source *arg_source) override {
402  m_base_var.set_arg_source(arg_source);
403  }
404  virtual void set_is_plugin(bool is_plugin) override {
405  m_base_var.set_is_plugin(is_plugin);
406  }
407  virtual bool is_non_persistent() override {
408  return m_base_var.is_non_persistent();
409  }
410  virtual void saved_value_to_string(THD *thd, set_var *var,
411  char *def_val) override {
412  return m_base_var.saved_value_to_string(thd, var, def_val);
413  }
414  virtual bool check_update_type(Item_result type) override {
416  }
417  virtual enum_variable_source get_source() override {
418  return m_base_var.get_source();
419  }
420  virtual const char *get_source_name() override {
421  return m_base_var.get_source_name();
422  }
423  virtual void set_source(enum_variable_source src) override {
424  m_base_var.set_source(src);
425  }
426  virtual bool set_source_name(const char *path) override {
428  }
429  virtual bool set_user(const char *usr) override {
430  return m_base_var.set_user(usr);
431  }
432  virtual const char *get_user() override { return m_base_var.get_user(); }
433  virtual const char *get_host() override { return m_base_var.get_host(); }
434  virtual bool set_host(const char *hst) override {
435  return m_base_var.set_host(hst);
436  }
437  virtual ulonglong get_timestamp() const override {
438  return m_base_var.get_timestamp();
439  }
440  virtual void set_user_host(THD *thd) override {
442  }
443  virtual void set_timestamp() override { m_base_var.set_timestamp(); }
444  virtual void set_timestamp(ulonglong ts) override {
446  }
447 
448  private:
449  virtual bool do_check(THD *thd, set_var *var) override {
450  return m_base_var.do_check(thd, var);
451  }
452  virtual void session_save_default(THD *thd, set_var *var) override {
453  return m_base_var.session_save_default(thd, var);
454  }
455  virtual void global_save_default(THD *thd, set_var *var) override {
456  return m_base_var.global_save_default(thd, var);
457  }
458  virtual bool session_update(THD *thd, set_var *var) override {
459  return m_base_var.session_update(thd, var);
460  }
461  virtual bool global_update(THD *thd, set_var *var) override {
462  return m_base_var.global_update(thd, var);
463  }
464 
465  protected:
466  virtual const uchar *session_value_ptr(THD *running_thd, THD *target_thd,
467  LEX_STRING *base) override {
468  return m_base_var.session_value_ptr(running_thd, target_thd, base);
469  }
470  virtual const uchar *global_value_ptr(THD *thd, LEX_STRING *base) override {
471  return m_base_var.global_value_ptr(thd, base);
472  }
473 };
474 
475 /**
476  A deprecated alias for a variable.
477 
478  This tool allows us to rename system variables without breaking
479  backward compatibility.
480 
481  Procedure for a developer to create a new name for a variable in
482  version X and remove the old name in version X+1:
483 
484  - In version X:
485 
486  - Change the string passed to the Sys_var constructor for the
487  variable the new new name. All existing code for this should
488  remain as it is.
489 
490  - Create a Sys_var_deprecated_alias taking the old name as the
491  first argument and the Sys_var object having the new name as the
492  second argument.
493 
494  - In version X+1:
495 
496  - Remove the Sys_var_deprecated_alias.
497 
498  This has the following effects in version X:
499 
500  - Both variables coexist. They are both visible in
501  performance_schema tables and accessible in SET statements and
502  SELECT @@variable statements. Both variables always have the same
503  values.
504 
505  - A SET statement using either the old name or the new name changes
506  the value of both variables.
507 
508  - A SET statement using the old name generates a deprecation
509  warning.
510 
511  - The procedure that loads persisted variables from file accepts
512  either the old name, or the new name, or both. It generates a
513  deprecation warning in case only the old name exists in the file.
514  A SET PERSIST statement writes both variables to the file.
515 
516  The procedures for a user to upgrade or downgrade are:
517 
518  - After upgrade from version X-1 to X, all persisted variables
519  retain their persisted values. User will see deprecation warnings
520  when loading the persisted variables file, with instructions to
521  run a SET PERSIST statement any time before the next upgrade to
522  X+1.
523 
524  - While on version X, user needs to run a SET PERSIST statement any
525  time before upgrading to X+1. Due to the logic described above, it
526  will write both variables to the file.
527 
528  - While on version X, user needs to change their cnf files,
529  command-line arguments, and @@variables accessed through
530  application logic, to use the new names, before upgrading to X+1.
531  The deprecation warnings will help identify the relevant places to
532  update.
533 
534  - After upgrade from X to X+1, the server will read the old
535  variables from the file. Since this version does not know about
536  the old variables, it will ignore them and print a warning. The
537  user can remove the unknown variable from the persisted variable
538  file, and get rid of the warning, using RESET PERSIST
539  OLD_VARIABLE_NAME.
540 
541  - After downgrade from verson X+1 to version X, all persisted
542  variables retain their values. User will not see deprecation
543  warnings. If user needs to further downgrade to version X-1, user
544  needs to first run SET PERSIST for some variable in order to
545  rewrite the file so that the old variable names exist in the file.
546 
547  - After downgrade from version X to version X-1, all persisted
548  variables retain their values. If the new variable names exist in
549  the persisted variables file, a warning will be printed stating
550  that the variable is not known and will be ignored. User can get
551  rid of the warning by running RESET PERSIST NEW_VARIABLE_NAME.
552 */
554  private:
555  std::string m_comment;
556 
557  public:
558  Sys_var_deprecated_alias(const char *name_arg, sys_var &base_var)
559  : Sys_var_alias{name_arg, base_var, base_var.name.str, &base_var, true} {
560  m_comment = std::string("This option is deprecated. Use ") +
561  base_var.get_option()->name + " instead.";
562  option.comment = m_comment.c_str();
563  }
564 };
565 
566 /**
567  Helper class for variables that take values from a TYPELIB
568 */
569 class Sys_var_typelib : public sys_var {
570  protected:
572 
573  public:
574  Sys_var_typelib(const char *name_arg, const char *comment, int flag_args,
575  ptrdiff_t off, CMD_LINE getopt, SHOW_TYPE show_val_type_arg,
576  const char *values[], ulonglong def_val, PolyLock *lock,
577  enum binlog_status_enum binlog_status_arg,
578  on_check_function on_check_func,
579  on_update_function on_update_func, const char *substitute,
580  int parse_flag = PARSE_NORMAL)
581  : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
582  getopt.arg_type, show_val_type_arg, def_val, lock,
583  binlog_status_arg, on_check_func, on_update_func, substitute,
584  parse_flag) {
585  for (typelib.count = 0; values[typelib.count]; typelib.count++) /*no-op */
586  ;
587  typelib.name = "";
588  typelib.type_names = values;
589  typelib.type_lengths = nullptr; // only used by Fields_enum and Field_set
591  }
592  bool do_check(THD *, set_var *var) override // works for enums and bool
593  {
594  char buff[STRING_BUFFER_USUAL_SIZE];
595  String str(buff, sizeof(buff), system_charset_info), *res;
596 
597  if (var->value->result_type() == STRING_RESULT) {
598  if (!(res = var->value->val_str(&str)))
599  return true;
600  else if (!(var->save_result.ulonglong_value =
601  find_type(&typelib, res->ptr(), res->length(), false)))
602  return true;
603  else
604  var->save_result.ulonglong_value--;
605  } else {
606  longlong tmp = var->value->val_int();
607  if (tmp < 0 || tmp >= static_cast<longlong>(typelib.count))
608  return true;
609  else
610  var->save_result.ulonglong_value = tmp;
611  }
612 
613  return false;
614  }
616  return type != INT_RESULT && type != STRING_RESULT;
617  }
618 };
619 
620 /**
621  The class for ENUM variables - variables that take one value from a fixed
622  list of values.
623 
624  Class specific constructor arguments:
625  char* values[] - 0-terminated list of strings of valid values
626 
627  Backing store: uint
628 
629  @note
630  Do *not* use "enum FOO" variables as a backing store, there is no
631  guarantee that sizeof(enum FOO) == sizeof(uint), there is no guarantee
632  even that sizeof(enum FOO) == sizeof(enum BAR)
633 */
635  public:
637  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
638  size_t size [[maybe_unused]], CMD_LINE getopt, const char *values[],
639  uint def_val, PolyLock *lock = nullptr,
640  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
641  on_check_function on_check_func = nullptr,
642  on_update_function on_update_func = nullptr,
643  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
644  : Sys_var_typelib(name_arg, comment, flag_args, off, getopt, SHOW_CHAR,
645  values, def_val, lock, binlog_status_arg, on_check_func,
646  on_update_func, substitute, parse_flag) {
648  global_var(ulong) = def_val;
649  assert(def_val < typelib.count);
650  assert(size == sizeof(ulong));
651  }
652  bool session_update(THD *thd, set_var *var) override {
653  session_var(thd, ulong) =
654  static_cast<ulong>(var->save_result.ulonglong_value);
655  return false;
656  }
657  bool global_update(THD *, set_var *var) override {
658  global_var(ulong) = static_cast<ulong>(var->save_result.ulonglong_value);
659  return false;
660  }
661  void session_save_default(THD *, set_var *var) override {
662  var->save_result.ulonglong_value = global_var(ulong);
663  }
664  void global_save_default(THD *, set_var *var) override {
666  }
667  void saved_value_to_string(THD *, set_var *var, char *def_val) override {
668  // Copy the symbolic name, not the numeric value.
669  strcpy(def_val, typelib.type_names[var->save_result.ulonglong_value]);
670  }
671  const uchar *session_value_ptr(THD *, THD *target_thd,
672  LEX_STRING *) override {
673  return pointer_cast<const uchar *>(
674  typelib.type_names[session_var(target_thd, ulong)]);
675  }
676  const uchar *global_value_ptr(THD *, LEX_STRING *) override {
677  return pointer_cast<const uchar *>(typelib.type_names[global_var(ulong)]);
678  }
679 };
680 
681 /**
682  The class for boolean variables - a variant of ENUM variables
683  with the fixed list of values of { OFF , ON }
684 
685  Backing store: bool
686 */
688  public:
690  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
691  size_t size [[maybe_unused]], CMD_LINE getopt, bool def_val,
692  PolyLock *lock = nullptr,
693  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
694  on_check_function on_check_func = nullptr,
695  on_update_function on_update_func = nullptr,
696  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
697  : Sys_var_typelib(name_arg, comment, flag_args, off, getopt, SHOW_MY_BOOL,
698  bool_values, def_val, lock, binlog_status_arg,
699  on_check_func, on_update_func, substitute, parse_flag) {
701  global_var(bool) = def_val;
702  assert(getopt.arg_type == OPT_ARG || getopt.id == -1);
703  assert(size == sizeof(bool));
704  }
705  bool session_update(THD *thd, set_var *var) override {
706  session_var(thd, bool) =
707  static_cast<bool>(var->save_result.ulonglong_value);
708  return false;
709  }
710  bool global_update(THD *, set_var *var) override {
711  global_var(bool) = static_cast<bool>(var->save_result.ulonglong_value);
712  return false;
713  }
714  void session_save_default(THD *thd, set_var *var) override {
715  var->save_result.ulonglong_value = static_cast<ulonglong>(
716  *pointer_cast<const bool *>(global_value_ptr(thd, nullptr)));
717  }
718  void global_save_default(THD *, set_var *var) override {
720  }
721  void saved_value_to_string(THD *, set_var *var, char *def_val) override {
723  }
724 };
725 
726 /**
727  A variant of enum where:
728  - Each value may have multiple enum-like aliases.
729  - Instances of the class can specify different default values for
730  the cases:
731  - User specifies the command-line option without a value (i.e.,
732  --option, not --option=value).
733  - User does not specify a command-line option at all.
734 
735  This exists mainly to allow extending a variable that once was
736  boolean in a GA version, into an enumeration type. Booleans accept
737  multiple aliases (0=off=false, 1=on=true), but Sys_var_enum does
738  not, so we could not use Sys_var_enum without breaking backward
739  compatibility. Moreover, booleans default to false if option is not
740  given, and true if option is given without value.
741 
742  This is *incompatible* with boolean in the following sense:
743  'SELECT @@variable' returns 0 or 1 for a boolean, whereas this class
744  (similar to enum) returns the textual form. (Note that both boolean,
745  enum, and this class return the textual form in SHOW VARIABLES and
746  SELECT * FROM information_schema.variables).
747 
748  See enforce_gtid_consistency for an example of how this can be used.
749 */
750 class Sys_var_multi_enum : public sys_var {
751  public:
752  struct ALIAS {
753  const char *alias;
755  };
756 
757  /**
758  Enumerated type system variable.
759 
760  @param name_arg See sys_var::sys_var()
761 
762  @param comment See sys_var::sys_var()
763 
764  @param flag_args See sys_var::sys_var()
765 
766  @param off See sys_var::sys_var()
767 
768  @param size See sys_var::sys_var()
769 
770  @param getopt See sys_var::sys_var()
771 
772  @param aliases_arg Array of ALIASes, indicating which textual
773  values map to which number. Should be terminated with an ALIAS
774  having member variable alias set to NULL. The first
775  `value_count_arg' elements must map to 0, 1, etc; these will be
776  used when the value is displayed. Remaining elements may appear
777  in arbitrary order.
778 
779  @param value_count_arg The number of allowed integer values.
780 
781  @param def_val The default value if no command line option is
782  given. This must be a valid index into the aliases_arg array, but
783  it does not have to be less than value_count. The corresponding
784  alias will be used in mysqld --help to show the default value.
785 
786  @param command_line_no_value_arg The default value if a command line
787  option is given without a value ('--command-line-option' without
788  '=VALUE'). This must be less than value_count_arg.
789 
790  @param lock See sys_var::sys_var()
791 
792  @param binlog_status_arg See sys_var::sys_var()
793 
794  @param on_check_func See sys_var::sys_var()
795 
796  @param on_update_func See sys_var::sys_var()
797 
798  @param substitute See sys_var::sys_var()
799 
800  @param parse_flag See sys_var::sys_var()
801  */
803  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
804  size_t size [[maybe_unused]], CMD_LINE getopt, const ALIAS aliases_arg[],
805  uint value_count_arg, uint def_val, uint command_line_no_value_arg,
806  PolyLock *lock = nullptr,
807  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
808  on_check_function on_check_func = nullptr,
809  on_update_function on_update_func = nullptr,
810  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
811  : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
812  getopt.arg_type, SHOW_CHAR, def_val, lock, binlog_status_arg,
813  on_check_func, on_update_func, substitute, parse_flag),
814  value_count(value_count_arg),
815  aliases(aliases_arg),
816  command_line_no_value(command_line_no_value_arg) {
818  assert(aliases[alias_count].number < value_count);
819  assert(def_val < alias_count);
820 
823  option.def_value = (intptr)aliases[def_val].alias;
824 
825  global_var(ulong) = aliases[def_val].number;
826 
827  assert(getopt.arg_type == OPT_ARG || getopt.id == -1);
828  assert(size == sizeof(ulong));
829  }
830 
831  /**
832  Return the numeric value for a given alias string, or -1 if the
833  string is not a valid alias.
834  */
835  int find_value(const char *text) {
836  for (uint i = 0; aliases[i].alias != nullptr; i++)
837  if (my_strcasecmp(system_charset_info, aliases[i].alias, text) == 0)
838  return aliases[i].number;
839  return -1;
840  }
841 
842  /**
843  Because of limitations in the command-line parsing library, the
844  value given on the command-line cannot be automatically copied to
845  the global value. Instead, inheritants of this class should call
846  this function from mysqld.cc:mysqld_get_one_option.
847 
848  @param value_str Pointer to the value specified on the command
849  line (as in --option=VALUE).
850 
851  @retval NULL Success.
852 
853  @retval non-NULL Pointer to the invalid string that was used as
854  argument.
855  */
856  const char *fixup_command_line(const char *value_str) {
857  DBUG_TRACE;
858  char *end = nullptr;
859  long value;
860 
861  // User passed --option (not --option=value).
862  if (value_str == nullptr) {
864  goto end;
865  }
866 
867  // Get textual value.
868  value = find_value(value_str);
869  if (value != -1) goto end;
870 
871  // Get numeric value.
872  value = strtol(value_str, &end, 10);
873  // found a number and nothing else?
874  if (end > value_str && *end == '\0')
875  // value is in range?
876  if (value >= 0 && (longlong)value < (longlong)value_count) goto end;
877 
878  // Not a valid value.
879  return value_str;
880 
881  end:
882  global_var(ulong) = value;
883  return nullptr;
884  }
885 
886  bool do_check(THD *, set_var *var) override {
887  DBUG_TRACE;
888  char buff[STRING_BUFFER_USUAL_SIZE];
889  String str(buff, sizeof(buff), system_charset_info), *res;
890  if (var->value->result_type() == STRING_RESULT) {
891  res = var->value->val_str(&str);
892  if (!res) return true;
893 
894  /* Check if the value is a valid string. */
895  size_t valid_len;
896  bool len_error;
897  if (validate_string(system_charset_info, res->ptr(), res->length(),
898  &valid_len, &len_error))
899  return true;
900 
901  int value = find_value(res->ptr());
902  if (value == -1) return true;
904  } else {
905  longlong value = var->value->val_int();
906  if (value < 0 || value >= (longlong)value_count)
907  return true;
908  else
910  }
911 
912  return false;
913  }
915  return type != INT_RESULT && type != STRING_RESULT;
916  }
917  bool session_update(THD *, set_var *) override {
918  DBUG_TRACE;
919  assert(0);
920  /*
921  Currently not used: uncomment if this class is used as a base for
922  a session variable.
923 
924  session_var(thd, ulong)=
925  static_cast<ulong>(var->save_result.ulonglong_value);
926  */
927  return false;
928  }
929  bool global_update(THD *, set_var *) override {
930  DBUG_TRACE;
931  assert(0);
932  /*
933  Currently not used: uncomment if this some inheriting class does
934  not override..
935 
936  ulong val=
937  static_cast<ulong>(var->save_result.ulonglong_value);
938  global_var(ulong)= val;
939  */
940  return false;
941  }
942  void session_save_default(THD *, set_var *) override {
943  DBUG_TRACE;
944  assert(0);
945  /*
946  Currently not used: uncomment if this class is used as a base for
947  a session variable.
948 
949  int value= find_value((char *)option.def_value);
950  assert(value != -1);
951  var->save_result.ulonglong_value= value;
952  */
953  return;
954  }
955  void global_save_default(THD *, set_var *var) override {
956  DBUG_TRACE;
957  int value = find_value((char *)option.def_value);
958  assert(value != -1);
960  return;
961  }
962  void saved_value_to_string(THD *, set_var *var, char *def_val) override {
964  }
965 
966  const uchar *session_value_ptr(THD *, THD *, LEX_STRING *) override {
967  DBUG_TRACE;
968  assert(0);
969  /*
970  Currently not used: uncomment if this class is used as a base for
971  a session variable.
972 
973  return (uchar*)aliases[session_var(target_thd, ulong)].alias;
974  */
975  return nullptr;
976  }
977  const uchar *global_value_ptr(THD *, LEX_STRING *) override {
978  DBUG_TRACE;
979  return pointer_cast<const uchar *>(aliases[global_var(ulong)].alias);
980  }
981 
982  private:
983  /// The number of allowed numeric values.
985  /// Array of all textual aliases.
986  const ALIAS *aliases;
987  /// The number of elements of aliases (computed in the constructor).
989 
990  /**
991  Pointer to the value set by the command line (set by the command
992  line parser, copied to the global value in fixup_command_line()).
993  */
994  const char *command_line_value;
996 };
997 
998 /**
999  The class for string variables. The string can be in character_set_filesystem
1000  or in character_set_system. The string can be allocated with my_malloc()
1001  or not. The state of the initial value is specified in the constructor,
1002  after that it's managed automatically. The value of NULL is supported.
1003 
1004  Class specific constructor arguments:
1005  enum charset_enum is_os_charset_arg
1006 
1007  Backing store: char*
1008 
1009 */
1010 class Sys_var_charptr : public sys_var {
1011  public:
1013  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
1014  size_t size [[maybe_unused]], CMD_LINE getopt,
1015  enum charset_enum is_os_charset_arg, const char *def_val,
1016  PolyLock *lock = nullptr,
1017  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
1018  on_check_function on_check_func = nullptr,
1019  on_update_function on_update_func = nullptr,
1020  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
1021  : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
1022  getopt.arg_type, SHOW_CHAR_PTR, (intptr)def_val, lock,
1023  binlog_status_arg, on_check_func, on_update_func, substitute,
1024  parse_flag) {
1025  is_os_charset = is_os_charset_arg == IN_FS_CHARSET;
1027  global_var(const char *) = def_val;
1028  assert(size == sizeof(char *));
1029  }
1030 
1031  void cleanup() override {
1032  if (flags & ALLOCATED) my_free(global_var(char *));
1033  flags &= ~ALLOCATED;
1034  }
1035 
1036  bool do_check(THD *thd, set_var *var) override {
1038  String str(buff, sizeof(buff), charset(thd));
1039  String str2(buff2, sizeof(buff2), charset(thd)), *res;
1040 
1041  if (!(res = var->value->val_str(&str)))
1042  var->save_result.string_value.str = nullptr;
1043  else {
1044  size_t unused;
1045  if (String::needs_conversion(res->length(), res->charset(), charset(thd),
1046  &unused)) {
1047  uint errors;
1048  str2.copy(res->ptr(), res->length(), res->charset(), charset(thd),
1049  &errors);
1050  res = &str2;
1051  }
1053  thd->strmake(res->ptr(), res->length());
1054  var->save_result.string_value.length = res->length();
1055  }
1056 
1057  return false;
1058  }
1059 
1060  bool session_update(THD *thd, set_var *var) override {
1061  char *new_val = var->save_result.string_value.str;
1062  size_t new_val_len = var->save_result.string_value.length;
1063  char *ptr = ((char *)&thd->variables + offset);
1064 
1065  return thd->session_sysvar_res_mgr.update((char **)ptr, new_val,
1066  new_val_len);
1067  }
1068 
1069  bool global_update(THD *thd, set_var *var) override;
1070 
1071  void session_save_default(THD *, set_var *var) override {
1072  char *ptr = (char *)(intptr)option.def_value;
1073  var->save_result.string_value.str = ptr;
1074  var->save_result.string_value.length = ptr ? strlen(ptr) : 0;
1075  }
1076 
1077  void global_save_default(THD *, set_var *var) override {
1078  char *ptr = (char *)(intptr)option.def_value;
1079  /*
1080  TODO: default values should not be null. Fix all and turn this into an
1081  assert.
1082  Do that only for NON_PERSIST READ_ONLY variables since the rest use
1083  the NULL value as a flag that SET .. = DEFAULT was issued and hence
1084  it should not be alterned.
1085  */
1087  ptr || ((sys_var::READONLY | sys_var::NOTPERSIST) !=
1089  ? ptr
1090  : const_cast<char *>("");
1091  var->save_result.string_value.length = ptr ? strlen(ptr) : 0;
1092  }
1093  void saved_value_to_string(THD *, set_var *var, char *def_val) override {
1094  memcpy(def_val, var->save_result.string_value.str,
1096  }
1098  return type != STRING_RESULT;
1099  }
1100 };
1101 
1103  public:
1104  Sys_var_version(const char *name_arg, const char *comment, int flag_args,
1105  ptrdiff_t off, size_t size, CMD_LINE getopt,
1106  enum charset_enum is_os_charset_arg, const char *def_val)
1107  : Sys_var_charptr(name_arg, comment, flag_args, off, size, getopt,
1108  is_os_charset_arg, def_val) {}
1109 
1110  ~Sys_var_version() override = default;
1111 
1112  const uchar *global_value_ptr(THD *thd, LEX_STRING *base) override {
1113  const uchar *value = Sys_var_charptr::global_value_ptr(thd, base);
1114 
1115  DBUG_EXECUTE_IF("alter_server_version_str", {
1116  static const char *altered_value = "some-other-version";
1117  const uchar *altered_value_ptr = pointer_cast<uchar *>(&altered_value);
1118  value = altered_value_ptr;
1119  });
1120 
1121  return value;
1122  }
1123 };
1124 
1125 class Sys_var_proxy_user : public sys_var {
1126  public:
1127  Sys_var_proxy_user(const char *name_arg, const char *comment,
1128  enum charset_enum is_os_charset_arg)
1129  : sys_var(&all_sys_vars, name_arg, comment,
1132  nullptr, PARSE_NORMAL) {
1133  is_os_charset = is_os_charset_arg == IN_FS_CHARSET;
1135  }
1136  bool do_check(THD *, set_var *) override {
1137  assert(false);
1138  return true;
1139  }
1140  bool session_update(THD *, set_var *) override {
1141  assert(false);
1142  return true;
1143  }
1144  bool global_update(THD *, set_var *) override {
1145  assert(false);
1146  return false;
1147  }
1148  void session_save_default(THD *, set_var *) override { assert(false); }
1149  void global_save_default(THD *, set_var *) override { assert(false); }
1150  void saved_value_to_string(THD *, set_var *, char *) override {
1151  assert(false);
1152  }
1153  bool check_update_type(Item_result) override { return true; }
1154 
1155  protected:
1156  const uchar *session_value_ptr(THD *, THD *target_thd,
1157  LEX_STRING *) override {
1158  const char *proxy_user = target_thd->security_context()->proxy_user().str;
1159  return proxy_user[0] ? pointer_cast<const uchar *>(proxy_user) : nullptr;
1160  }
1161 };
1162 
1164  public:
1165  Sys_var_external_user(const char *name_arg, const char *comment_arg,
1166  enum charset_enum is_os_charset_arg)
1167  : Sys_var_proxy_user(name_arg, comment_arg, is_os_charset_arg) {}
1168 
1169  protected:
1170  const uchar *session_value_ptr(THD *, THD *target_thd,
1171  LEX_STRING *) override {
1172  LEX_CSTRING external_user = target_thd->security_context()->external_user();
1173  return external_user.length ? pointer_cast<const uchar *>(external_user.str)
1174  : nullptr;
1175  }
1176 };
1177 
1178 /**
1179  The class for string variables. Useful for strings that aren't necessarily
1180  \0-terminated. Otherwise the same as Sys_var_charptr.
1181 
1182  Class specific constructor arguments:
1183  enum charset_enum is_os_charset_arg
1184 
1185  Backing store: LEX_STRING
1186 
1187  @note
1188  Behaves exactly as Sys_var_charptr, only the backing store is different.
1189 */
1191  public:
1193  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
1194  size_t size [[maybe_unused]], CMD_LINE getopt,
1195  enum charset_enum is_os_charset_arg, const char *def_val,
1196  PolyLock *lock = nullptr,
1197  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
1198  on_check_function on_check_func = nullptr,
1199  on_update_function on_update_func = nullptr,
1200  const char *substitute = nullptr)
1201  : Sys_var_charptr(name_arg, comment, flag_args, off, sizeof(char *),
1202  getopt, is_os_charset_arg, def_val, lock,
1203  binlog_status_arg, on_check_func, on_update_func,
1204  substitute) {
1205  global_var(LEX_STRING).length = strlen(def_val);
1206  assert(size == sizeof(LEX_STRING));
1207  *const_cast<SHOW_TYPE *>(&show_val_type) = SHOW_LEX_STRING;
1208  }
1209  bool global_update(THD *thd, set_var *var) override {
1210  if (Sys_var_charptr::global_update(thd, var)) return true;
1212  return false;
1213  }
1214 };
1215 
1216 #ifndef NDEBUG
1217 /**
1218  @@session.dbug and @@global.dbug variables.
1219 
1220  @@dbug variable differs from other variables in one aspect:
1221  if its value is not assigned in the session, it "points" to the global
1222  value, and so when the global value is changed, the change
1223  immediately takes effect in the session.
1224 
1225  This semantics is intentional, to be able to debug one session from
1226  another.
1227 */
1228 class Sys_var_dbug : public sys_var {
1229  public:
1231  const char *name_arg, const char *comment, int flag_args, CMD_LINE getopt,
1232  const char *def_val, PolyLock *lock = nullptr,
1233  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
1234  on_check_function on_check_func = nullptr,
1235  on_update_function on_update_func = nullptr,
1236  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
1237  : sys_var(&all_sys_vars, name_arg, comment, flag_args, 0, getopt.id,
1238  getopt.arg_type, SHOW_CHAR, (intptr)def_val, lock,
1239  binlog_status_arg, on_check_func, on_update_func, substitute,
1240  parse_flag) {
1242  }
1243  bool do_check(THD *thd, set_var *var) override {
1244  char buff[STRING_BUFFER_USUAL_SIZE];
1245  String str(buff, sizeof(buff), system_charset_info), *res;
1246 
1247  if (!(res = var->value->val_str(&str)))
1248  var->save_result.string_value.str = const_cast<char *>("");
1249  else
1251  thd->strmake(res->ptr(), res->length());
1252  return false;
1253  }
1254  bool session_update(THD *, set_var *var) override {
1255  const char *val = var->save_result.string_value.str;
1256  if (!var->value)
1257  DBUG_POP();
1258  else
1259  DBUG_SET(val);
1260  return false;
1261  }
1262  bool global_update(THD *, set_var *var) override {
1263  const char *val = var->save_result.string_value.str;
1264  DBUG_SET_INITIAL(val);
1265  return false;
1266  }
1267  void session_save_default(THD *, set_var *) override {}
1268  void global_save_default(THD *, set_var *var) override {
1269  char *ptr = (char *)(intptr)option.def_value;
1270  var->save_result.string_value.str = ptr;
1271  }
1272  void saved_value_to_string(THD *, set_var *var, char *def_val) override {
1273  memcpy(def_val, var->save_result.string_value.str,
1275  }
1276  const uchar *session_value_ptr(THD *running_thd, THD *,
1277  LEX_STRING *) override {
1278  char buf[512];
1279  DBUG_EXPLAIN(buf, sizeof(buf));
1280  return (uchar *)running_thd->mem_strdup(buf);
1281  }
1282  const uchar *global_value_ptr(THD *thd, LEX_STRING *) override {
1283  char buf[512];
1284  DBUG_EXPLAIN_INITIAL(buf, sizeof(buf));
1285  return (uchar *)thd->mem_strdup(buf);
1286  }
1288  return type != STRING_RESULT;
1289  }
1290 };
1291 #endif
1292 
1293 #define KEYCACHE_VAR(X) \
1294  sys_var::GLOBAL, offsetof(KEY_CACHE, X), sizeof(((KEY_CACHE *)0)->X)
1295 #define keycache_var_ptr(KC, OFF) (((uchar *)(KC)) + (OFF))
1296 #define keycache_var(KC, OFF) (*(ulonglong *)keycache_var_ptr(KC, OFF))
1297 typedef bool (*keycache_update_function)(THD *, KEY_CACHE *, ptrdiff_t,
1298  ulonglong);
1299 
1300 /**
1301  The class for keycache_* variables. Supports structured names,
1302  keycache_name.variable_name.
1303 
1304  Class specific constructor arguments:
1305  everything derived from Sys_var_ulonglong
1306 
1307  Backing store: ulonglong
1308 
1309  @note these variables can be only GLOBAL
1310 */
1313 
1314  public:
1315  Sys_var_keycache(const char *name_arg, const char *comment, int flag_args,
1316  ptrdiff_t off, size_t size, CMD_LINE getopt,
1317  ulonglong min_val, ulonglong max_val, ulonglong def_val,
1318  uint block_size, PolyLock *lock,
1319  enum binlog_status_enum binlog_status_arg,
1320  on_check_function on_check_func,
1321  keycache_update_function on_update_func,
1322  const char *substitute = nullptr)
1324  name_arg, comment, flag_args, -1, /* offset, see base class CTOR */
1325  size, getopt, min_val, max_val, def_val, block_size, lock,
1326  binlog_status_arg, on_check_func, nullptr, substitute),
1327  keycache_update(on_update_func) {
1328  offset = off; /* Remember offset in KEY_CACHE */
1330  option.value = (uchar **)1; // crash me, please
1331  keycache_var(dflt_key_cache, off) = def_val;
1332  assert(scope() == GLOBAL);
1333  }
1334  bool global_update(THD *thd, set_var *var) override {
1335  ulonglong new_value = var->save_result.ulonglong_value;
1336 
1337  if (var->base.str)
1339  ER_WARN_DEPRECATED_SYNTAX,
1340  "%s.%s syntax "
1341  "is deprecated and will be removed in a "
1342  "future release",
1343  var->base.str, name.str);
1344 
1345  LEX_CSTRING base_name = var->base;
1346  /* If no basename, assume it's for the key cache named 'default' */
1348 
1349  KEY_CACHE *key_cache = get_key_cache(&base_name);
1350 
1351  if (!key_cache) { // Key cache didn't exists */
1352  if (!new_value) // Tried to delete cache
1353  return false; // Ok, nothing to do
1354  if (!(key_cache = create_key_cache(base_name.str, base_name.length)))
1355  return true;
1356  }
1357 
1358  /**
1359  Abort if some other thread is changing the key cache
1360  @todo This should be changed so that we wait until the previous
1361  assignment is done and then do the new assign
1362  */
1363  if (key_cache->in_init) return true;
1364 
1365  return keycache_update(thd, key_cache, offset, new_value);
1366  }
1367  const uchar *global_value_ptr(THD *thd, LEX_STRING *base) override {
1368  if (base != nullptr && base->str)
1370  ER_WARN_DEPRECATED_SYNTAX,
1371  "@@global.%s.%s syntax "
1372  "is deprecated and will be removed in a "
1373  "future release",
1374  base->str, name.str);
1375 
1376  LEX_CSTRING cstr = to_lex_cstring(*base);
1377  KEY_CACHE *key_cache = get_key_cache(&cstr);
1378  if (!key_cache) key_cache = &zero_key_cache;
1379  return keycache_var_ptr(key_cache, offset);
1380  }
1381 };
1382 
1383 /**
1384  The class for floating point variables
1385 
1386  Class specific constructor arguments: min, max
1387 
1388  Backing store: double
1389 */
1390 class Sys_var_double : public sys_var {
1391  public:
1393  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
1394  size_t size [[maybe_unused]], CMD_LINE getopt, double min_val,
1395  double max_val, double def_val, PolyLock *lock = nullptr,
1396  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
1397  on_check_function on_check_func = nullptr,
1398  on_update_function on_update_func = nullptr,
1399  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
1400  : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
1401  getopt.arg_type, SHOW_DOUBLE,
1403  binlog_status_arg, on_check_func, on_update_func, substitute,
1404  parse_flag) {
1409  assert(min_val <= max_val);
1410  assert(min_val <= def_val);
1411  assert(max_val >= def_val);
1412  assert(size == sizeof(double));
1413  }
1414  bool do_check(THD *thd, set_var *var) override {
1415  bool fixed;
1416  double v = var->value->val_real();
1417  var->save_result.double_value =
1418  getopt_double_limit_value(v, &option, &fixed);
1419 
1420  return throw_bounds_warning(thd, name.str, fixed, v);
1421  }
1422  bool session_update(THD *thd, set_var *var) override {
1423  session_var(thd, double) = var->save_result.double_value;
1424  return false;
1425  }
1426  bool global_update(THD *, set_var *var) override {
1427  global_var(double) = var->save_result.double_value;
1428  return false;
1429  }
1431  return type != INT_RESULT && type != REAL_RESULT && type != DECIMAL_RESULT;
1432  }
1433  void session_save_default(THD *, set_var *var) override {
1434  var->save_result.double_value = global_var(double);
1435  }
1436  void global_save_default(THD *, set_var *var) override {
1438  }
1439  void saved_value_to_string(THD *, set_var *var, char *def_val) override {
1440  my_fcvt(var->save_result.double_value, 6, def_val, nullptr);
1441  }
1442 };
1443 
1444 /**
1445  The class for @c test_flags (core_file for now).
1446  It's derived from Sys_var_bool.
1447 
1448  Class specific constructor arguments:
1449  Caller need not pass in a variable as we make up the value on the
1450  fly, that is, we derive it from the global test_flags bit vector.
1451 
1452  Backing store: bool
1453 */
1455  private:
1458 
1459  public:
1460  Sys_var_test_flag(const char *name_arg, const char *comment, uint mask)
1461  : Sys_var_bool(name_arg, comment,
1463  NO_CMD_LINE, DEFAULT(false)) {
1464  test_flag_mask = mask;
1465  }
1466  const uchar *global_value_ptr(THD *, LEX_STRING *) override {
1468  return (uchar *)&test_flag_value;
1469  }
1470 };
1471 
1472 /**
1473  The class for the @c max_user_connections.
1474  It's derived from Sys_var_uint, but non-standard session value
1475  requires a new class.
1476 
1477  Class specific constructor arguments:
1478  everything derived from Sys_var_uint
1479 
1480  Backing store: uint
1481 */
1483  public:
1485  const char *name_arg, const char *comment, int, ptrdiff_t off,
1486  size_t size, CMD_LINE getopt, uint min_val, uint max_val, uint def_val,
1487  uint block_size, PolyLock *lock = nullptr,
1488  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
1489  on_check_function on_check_func = nullptr,
1490  on_update_function on_update_func = nullptr,
1491  const char *substitute = nullptr)
1492  : Sys_var_uint(name_arg, comment, SESSION, off, size, getopt, min_val,
1493  max_val, def_val, block_size, lock, binlog_status_arg,
1494  on_check_func, on_update_func, substitute) {}
1495  const uchar *session_value_ptr(THD *running_thd, THD *target_thd,
1496  LEX_STRING *base) override {
1497  const USER_CONN *uc = target_thd->get_user_connect();
1498  if (uc && uc->user_resources.user_conn)
1499  return pointer_cast<const uchar *>(&(uc->user_resources.user_conn));
1500  return global_value_ptr(running_thd, base);
1501  }
1502 };
1503 
1504 // overflow-safe (1 << X)-1
1505 #define MAX_SET(X) ((((1ULL << ((X)-1)) - 1) << 1) | 1)
1506 
1507 /**
1508  The class for flagset variables - a variant of SET that allows in-place
1509  editing (turning on/off individual bits). String representations looks like
1510  a "flag=val,flag=val,...". Example: @@optimizer_switch
1511 
1512  Class specific constructor arguments:
1513  char* values[] - 0-terminated list of strings of valid values
1514 
1515  Backing store: ulonglong
1516 
1517  @note
1518  the last value in the values[] array should
1519  *always* be the string "default".
1520 */
1522  public:
1524  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
1525  size_t size [[maybe_unused]], CMD_LINE getopt, const char *values[],
1526  ulonglong def_val, PolyLock *lock = nullptr,
1527  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
1528  on_check_function on_check_func = nullptr,
1529  on_update_function on_update_func = nullptr,
1530  const char *substitute = nullptr)
1531  : Sys_var_typelib(name_arg, comment, flag_args, off, getopt, SHOW_CHAR,
1532  values, def_val, lock, binlog_status_arg, on_check_func,
1533  on_update_func, substitute) {
1535  global_var(ulonglong) = def_val;
1536  assert(typelib.count > 1);
1537  assert(typelib.count <= 65);
1538  assert(def_val < MAX_SET(typelib.count));
1539  assert(strcmp(values[typelib.count - 1], "default") == 0);
1540  assert(size == sizeof(ulonglong));
1541  }
1542  bool do_check(THD *thd, set_var *var) override {
1543  char buff[STRING_BUFFER_USUAL_SIZE];
1544  String str(buff, sizeof(buff), system_charset_info), *res;
1545  ulonglong default_value, current_value;
1546  if (var->type == OPT_GLOBAL) {
1547  default_value = option.def_value;
1548  current_value = global_var(ulonglong);
1549  } else {
1550  default_value = global_var(ulonglong);
1551  current_value = session_var(thd, ulonglong);
1552  }
1553 
1554  if (var->value->result_type() == STRING_RESULT) {
1555  if (!(res = var->value->val_str(&str)))
1556  return true;
1557  else {
1558  const char *error;
1559  uint error_len;
1560 
1562  &typelib, typelib.count, current_value, default_value, res->ptr(),
1563  static_cast<uint>(res->length()), &error, &error_len);
1564  if (error) {
1565  ErrConvString err(error, error_len, res->charset());
1566  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.str, err.ptr());
1567  return true;
1568  }
1569  }
1570  } else {
1571  longlong tmp = var->value->val_int();
1572  if ((tmp < 0 && !var->value->unsigned_flag) ||
1573  (ulonglong)tmp > MAX_SET(typelib.count))
1574  return true;
1575  else
1576  var->save_result.ulonglong_value = tmp;
1577  }
1578 
1579  return false;
1580  }
1581  bool session_update(THD *thd, set_var *var) override {
1583  return false;
1584  }
1585  bool global_update(THD *, set_var *var) override {
1587  return false;
1588  }
1589  void session_save_default(THD *, set_var *var) override {
1591  }
1592  void global_save_default(THD *, set_var *var) override {
1594  }
1595  void saved_value_to_string(THD *thd, set_var *var, char *def_val) override {
1596  strcpy(def_val,
1597  flagset_to_string(thd, nullptr, var->save_result.ulonglong_value,
1598  typelib.type_names));
1599  }
1600  const uchar *session_value_ptr(THD *running_thd, THD *target_thd,
1601  LEX_STRING *) override {
1602  return (uchar *)flagset_to_string(running_thd, nullptr,
1603  session_var(target_thd, ulonglong),
1605  }
1606  const uchar *global_value_ptr(THD *thd, LEX_STRING *) override {
1607  return (uchar *)flagset_to_string(thd, nullptr, global_var(ulonglong),
1609  }
1610 };
1611 
1612 /**
1613  The class for SET variables - variables taking zero or more values
1614  from the given list. Example: @@sql_mode
1615 
1616  Class specific constructor arguments:
1617  char* values[] - 0-terminated list of strings of valid values
1618 
1619  Backing store: ulonglong
1620 */
1622  public:
1624  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
1625  size_t size [[maybe_unused]], CMD_LINE getopt, const char *values[],
1626  ulonglong def_val, PolyLock *lock = nullptr,
1627  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
1628  on_check_function on_check_func = nullptr,
1629  on_update_function on_update_func = nullptr,
1630  const char *substitute = nullptr)
1631  : Sys_var_typelib(name_arg, comment, flag_args, off, getopt, SHOW_CHAR,
1632  values, def_val, lock, binlog_status_arg, on_check_func,
1633  on_update_func, substitute) {
1635  global_var(ulonglong) = def_val;
1636  assert(typelib.count > 0);
1637  assert(typelib.count <= 64);
1638  assert(def_val < MAX_SET(typelib.count));
1639  assert(size == sizeof(ulonglong));
1640  }
1641  bool do_check(THD *, set_var *var) override {
1642  char buff[STRING_BUFFER_USUAL_SIZE];
1643  String str(buff, sizeof(buff), system_charset_info), *res;
1644 
1645  if (var->value->result_type() == STRING_RESULT) {
1646  if (!(res = var->value->val_str(&str)))
1647  return true;
1648  else {
1649  const char *error;
1650  uint error_len;
1651  bool not_used;
1652 
1654  find_set(&typelib, res->ptr(), static_cast<uint>(res->length()),
1655  nullptr, &error, &error_len, &not_used);
1656  /*
1657  note, we only issue an error if error_len > 0.
1658  That is even while empty (zero-length) values are considered
1659  errors by find_set(), these errors are ignored here
1660  */
1661  if (error_len) {
1662  ErrConvString err(error, error_len, res->charset());
1663  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.str, err.ptr());
1664  return true;
1665  }
1666  }
1667  } else {
1668  longlong tmp = var->value->val_int();
1669  if ((tmp < 0 && !var->value->unsigned_flag) ||
1670  (ulonglong)tmp > MAX_SET(typelib.count))
1671  return true;
1672  else
1673  var->save_result.ulonglong_value = tmp;
1674  }
1675 
1676  return false;
1677  }
1678  bool session_update(THD *thd, set_var *var) override {
1680  return false;
1681  }
1682  bool global_update(THD *, set_var *var) override {
1684  return false;
1685  }
1686  void session_save_default(THD *, set_var *var) override {
1688  }
1689  void global_save_default(THD *, set_var *var) override {
1691  }
1692  void saved_value_to_string(THD *thd, set_var *var, char *def_val) override {
1693  strcpy(def_val,
1694  set_to_string(thd, nullptr, var->save_result.ulonglong_value,
1695  typelib.type_names));
1696  }
1697  const uchar *session_value_ptr(THD *running_thd, THD *target_thd,
1698  LEX_STRING *) override {
1699  return (uchar *)set_to_string(running_thd, nullptr,
1700  session_var(target_thd, ulonglong),
1702  }
1703  const uchar *global_value_ptr(THD *thd, LEX_STRING *) override {
1704  return (uchar *)set_to_string(thd, nullptr, global_var(ulonglong),
1706  }
1707 };
1708 
1709 /**
1710  The class for variables which value is a plugin.
1711  Example: @@default_storage_engine
1712 
1713  Class specific constructor arguments:
1714  int plugin_type_arg (for example MYSQL_STORAGE_ENGINE_PLUGIN)
1715 
1716  Backing store: plugin_ref
1717 
1718  @note
1719  these variables don't support command-line equivalents, any such
1720  command-line options should be added manually to my_long_options in mysqld.cc
1721 */
1722 class Sys_var_plugin : public sys_var {
1724 
1725  public:
1727  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
1728  size_t size [[maybe_unused]], CMD_LINE getopt, int plugin_type_arg,
1729  const char **def_val, PolyLock *lock = nullptr,
1730  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
1731  on_check_function on_check_func = nullptr,
1732  on_update_function on_update_func = nullptr,
1733  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
1734  : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
1735  getopt.arg_type, SHOW_CHAR, (intptr)def_val, lock,
1736  binlog_status_arg, on_check_func, on_update_func, substitute,
1737  parse_flag),
1738  plugin_type(plugin_type_arg) {
1740  assert(size == sizeof(plugin_ref));
1741  assert(getopt.id == -1); // force NO_CMD_LINE
1742  }
1743  bool do_check(THD *thd, set_var *var) override {
1744  char buff[STRING_BUFFER_USUAL_SIZE];
1745  String str(buff, sizeof(buff), system_charset_info), *res;
1746 
1747  /* NULLs can't be used as a default storage engine */
1748  if (!(res = var->value->val_str(&str))) return true;
1749 
1750  LEX_CSTRING pname_cstr = res->lex_cstring();
1751  plugin_ref plugin;
1752 
1753  // special code for storage engines (e.g. to handle historical aliases)
1755  plugin = ha_resolve_by_name(thd, &pname_cstr, false);
1756  else {
1757  plugin = my_plugin_lock_by_name(thd, pname_cstr, plugin_type);
1758  }
1759 
1760  if (!plugin) {
1761  // historically different error code
1763  ErrConvString err(res);
1764  my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), err.ptr());
1765  }
1766  return true;
1767  }
1768  var->save_result.plugin = plugin;
1769  return false;
1770  }
1771  void do_update(plugin_ref *valptr, plugin_ref newval) {
1772  plugin_ref oldval = *valptr;
1773  if (oldval != newval) {
1774  *valptr = my_plugin_lock(nullptr, &newval);
1775  plugin_unlock(nullptr, oldval);
1776  }
1777  }
1778  bool session_update(THD *thd, set_var *var) override {
1780  return false;
1781  }
1782  bool global_update(THD *, set_var *var) override {
1784  return false;
1785  }
1786  void session_save_default(THD *thd, set_var *var) override {
1787  plugin_ref plugin = global_var(plugin_ref);
1788  var->save_result.plugin = my_plugin_lock(thd, &plugin);
1789  }
1790  void global_save_default(THD *thd, set_var *var) override {
1792  char **default_value = reinterpret_cast<char **>(option.def_value);
1793  pname.str = *default_value;
1794  pname.length = strlen(pname.str);
1795 
1796  plugin_ref plugin;
1798  plugin = ha_resolve_by_name(thd, &pname, false);
1799  else {
1800  plugin = my_plugin_lock_by_name(thd, pname, plugin_type);
1801  }
1802  assert(plugin);
1803 
1804  var->save_result.plugin = my_plugin_lock(thd, &plugin);
1805  }
1806  void saved_value_to_string(THD *, set_var *var, char *def_val) override {
1807  strncpy(def_val, plugin_name(var->save_result.plugin)->str,
1809  }
1811  return type != STRING_RESULT;
1812  }
1813  const uchar *session_value_ptr(THD *running_thd, THD *target_thd,
1814  LEX_STRING *) override {
1815  plugin_ref plugin = session_var(target_thd, plugin_ref);
1816  return (uchar *)(plugin ? running_thd->strmake(plugin_name(plugin)->str,
1817  plugin_name(plugin)->length)
1818  : nullptr);
1819  }
1820  const uchar *global_value_ptr(THD *thd, LEX_STRING *) override {
1821  plugin_ref plugin = global_var(plugin_ref);
1822  return (uchar *)(plugin ? thd->strmake(plugin_name(plugin)->str,
1823  plugin_name(plugin)->length)
1824  : nullptr);
1825  }
1826 };
1827 
1828 #if defined(ENABLED_DEBUG_SYNC)
1829 /**
1830  The class for @@debug_sync session-only variable
1831 */
1832 class Sys_var_debug_sync : public sys_var {
1833  public:
1834  Sys_var_debug_sync(
1835  const char *name_arg, const char *comment, int flag_args, CMD_LINE getopt,
1836  const char *def_val, PolyLock *lock = nullptr,
1837  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
1838  on_check_function on_check_func = nullptr,
1839  on_update_function on_update_func = nullptr,
1840  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
1841  : sys_var(&all_sys_vars, name_arg, comment, flag_args, 0, getopt.id,
1842  getopt.arg_type, SHOW_CHAR, (intptr)def_val, lock,
1843  binlog_status_arg, on_check_func, on_update_func, substitute,
1844  parse_flag) {
1845  assert(scope() == ONLY_SESSION);
1846  option.var_type = GET_NO_ARG;
1847  }
1848  bool do_check(THD *thd, set_var *var) override {
1849  char buff[STRING_BUFFER_USUAL_SIZE];
1850  String str(buff, sizeof(buff), system_charset_info), *res;
1851 
1852  if (!(res = var->value->val_str(&str)))
1853  var->save_result.string_value.str = const_cast<char *>("");
1854  else
1856  thd->strmake(res->ptr(), res->length());
1857  return false;
1858  }
1859  bool session_update(THD *thd, set_var *var) override {
1860  return debug_sync_update(thd, var->save_result.string_value.str);
1861  }
1862  bool global_update(THD *, set_var *) override {
1863  assert(false);
1864  return true;
1865  }
1866  void session_save_default(THD *, set_var *var) override {
1867  var->save_result.string_value.str = const_cast<char *>("");
1868  var->save_result.string_value.length = 0;
1869  }
1870  void global_save_default(THD *, set_var *) override { assert(false); }
1871  void saved_value_to_string(THD *, set_var *, char *) override {
1872  assert(false);
1873  }
1874  const uchar *session_value_ptr(THD *running_thd, THD *,
1875  LEX_STRING *) override {
1876  return debug_sync_value_ptr(running_thd);
1877  }
1878  const uchar *global_value_ptr(THD *, LEX_STRING *) override {
1879  assert(false);
1880  return nullptr;
1881  }
1882  bool check_update_type(Item_result type) override {
1883  return type != STRING_RESULT;
1884  }
1885 };
1886 #endif /* defined(ENABLED_DEBUG_SYNC) */
1887 
1888 /**
1889  The class for bit variables - a variant of boolean that stores the value
1890  in a bit.
1891 
1892  Class specific constructor arguments:
1893  ulonglong bitmask_arg - the mask for the bit to set in the ulonglong
1894  backing store
1895 
1896  Backing store: ulonglong
1897 
1898  @note
1899  This class supports the "reverse" semantics, when the value of the bit
1900  being 0 corresponds to the value of variable being set. To activate it
1901  use REVERSE(bitmask) instead of simply bitmask in the constructor.
1902 
1903  @note
1904  variables of this class cannot be set from the command line as
1905  my_getopt does not support bits.
1906 */
1910  void set(uchar *ptr, ulonglong value) {
1911  if ((value != 0) ^ reverse_semantics)
1912  (*(ulonglong *)ptr) |= bitmask;
1913  else
1914  (*(ulonglong *)ptr) &= ~bitmask;
1915  }
1916 
1917  public:
1919  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
1920  size_t size [[maybe_unused]], CMD_LINE getopt, ulonglong bitmask_arg,
1921  bool def_val, PolyLock *lock = nullptr,
1922  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
1923  on_check_function on_check_func = nullptr,
1924  pre_update_function pre_update_func = nullptr,
1925  on_update_function on_update_func = nullptr,
1926  const char *substitute = nullptr)
1927  : Sys_var_typelib(name_arg, comment, flag_args, off, getopt, SHOW_MY_BOOL,
1928  bool_values, def_val, lock, binlog_status_arg,
1929  on_check_func, on_update_func, substitute) {
1931  pre_update = pre_update_func;
1932  reverse_semantics = my_count_bits(bitmask_arg) > 1;
1933  bitmask = reverse_semantics ? ~bitmask_arg : bitmask_arg;
1934  set(global_var_ptr(), def_val);
1935  assert(getopt.id == -1); // force NO_CMD_LINE
1936  assert(size == sizeof(ulonglong));
1937  }
1938  bool session_update(THD *thd, set_var *var) override {
1940  return false;
1941  }
1942  bool global_update(THD *, set_var *var) override {
1944  return false;
1945  }
1946  void session_save_default(THD *, set_var *var) override {
1948  }
1949  void global_save_default(THD *, set_var *var) override {
1951  }
1952  void saved_value_to_string(THD *, set_var *var, char *def_val) override {
1954  }
1955  const uchar *session_value_ptr(THD *running_thd, THD *target_thd,
1956  LEX_STRING *) override {
1957  running_thd->sys_var_tmp.bool_value = static_cast<bool>(
1959  ((session_var(target_thd, ulonglong) & bitmask) != 0));
1960  return (uchar *)&running_thd->sys_var_tmp.bool_value;
1961  }
1962  const uchar *global_value_ptr(THD *thd, LEX_STRING *) override {
1963  thd->sys_var_tmp.bool_value = static_cast<bool>(
1965  return (uchar *)&thd->sys_var_tmp.bool_value;
1966  }
1967 };
1968 
1969 /**
1970  The class for variables that have a special meaning for a session,
1971  such as @@timestamp or @@rnd_seed1, their values typically cannot be read
1972  from SV structure, and a special "read" callback is provided.
1973 
1974  Class specific constructor arguments:
1975  everything derived from Sys_var_ulonglong
1976  session_special_read_function read_func_arg
1977 
1978  Backing store: ulonglong
1979 
1980  @note
1981  These variables are session-only, global or command-line equivalents
1982  are not supported as they're generally meaningless.
1983 */
1985  typedef bool (*session_special_update_function)(THD *thd, set_var *var);
1987 
1990 
1991  public:
1992  Sys_var_session_special(const char *name_arg, const char *comment,
1993  int flag_args, CMD_LINE getopt, ulonglong min_val,
1994  ulonglong max_val, uint block_size, PolyLock *lock,
1995  enum binlog_status_enum binlog_status_arg,
1996  on_check_function on_check_func,
1997  session_special_update_function update_func_arg,
1998  session_special_read_function read_func_arg,
1999  const char *substitute = nullptr)
2000  : Sys_var_ulonglong(name_arg, comment, flag_args, 0, sizeof(ulonglong),
2001  getopt, min_val, max_val, 0, block_size, lock,
2002  binlog_status_arg, on_check_func, nullptr,
2003  substitute),
2004  read_func(read_func_arg),
2005  update_func(update_func_arg) {
2006  assert(scope() == ONLY_SESSION);
2007  assert(getopt.id == -1); // NO_CMD_LINE, because the offset is fake
2008  }
2009  bool session_update(THD *thd, set_var *var) override {
2010  return update_func(thd, var);
2011  }
2012  bool global_update(THD *, set_var *) override {
2013  assert(false);
2014  return true;
2015  }
2016  void session_save_default(THD *, set_var *var) override {
2017  var->value = nullptr;
2018  }
2019  void global_save_default(THD *, set_var *) override { assert(false); }
2020  void saved_value_to_string(THD *, set_var *, char *) override {
2021  assert(false);
2022  }
2023  const uchar *session_value_ptr(THD *running_thd, THD *target_thd,
2024  LEX_STRING *) override {
2025  running_thd->sys_var_tmp.ulonglong_value = read_func(target_thd);
2026  return (uchar *)&running_thd->sys_var_tmp.ulonglong_value;
2027  }
2028  const uchar *global_value_ptr(THD *, LEX_STRING *) override {
2029  assert(false);
2030  return nullptr;
2031  }
2032 };
2033 
2034 /**
2035  Similar to Sys_var_session_special, but with double storage.
2036 */
2038  typedef bool (*session_special_update_function)(THD *thd, set_var *var);
2040 
2043 
2044  public:
2046  const char *name_arg, const char *comment, int flag_args, CMD_LINE getopt,
2047  double min_val, double max_val, uint, PolyLock *lock,
2048  enum binlog_status_enum binlog_status_arg,
2049  on_check_function on_check_func,
2050  session_special_update_function update_func_arg,
2052  const char *substitute = nullptr)
2053  : Sys_var_double(name_arg, comment, flag_args, 0, sizeof(double), getopt,
2054  min_val, max_val, 0.0, lock, binlog_status_arg,
2055  on_check_func, nullptr, substitute),
2056  read_func(read_func_arg),
2057  update_func(update_func_arg) {
2058  assert(scope() == ONLY_SESSION);
2059  assert(getopt.id == -1); // NO_CMD_LINE, because the offset is fake
2060  }
2061  bool session_update(THD *thd, set_var *var) override {
2062  return update_func(thd, var);
2063  }
2064  bool global_update(THD *, set_var *) override {
2065  assert(false);
2066  return true;
2067  }
2068  void session_save_default(THD *, set_var *var) override {
2069  var->value = nullptr;
2070  }
2071  void global_save_default(THD *, set_var *) override { assert(false); }
2072  void saved_value_to_string(THD *, set_var *, char *) override {
2073  assert(false);
2074  }
2075  const uchar *session_value_ptr(THD *running_thd, THD *target_thd,
2076  LEX_STRING *) override {
2077  running_thd->sys_var_tmp.double_value = read_func(target_thd);
2078  return (uchar *)&running_thd->sys_var_tmp.double_value;
2079  }
2080  const uchar *global_value_ptr(THD *, LEX_STRING *) override {
2081  assert(false);
2082  return nullptr;
2083  }
2084 };
2085 
2086 /**
2087  The class for read-only variables that show whether a particular
2088  feature is supported by the server. Example: have_compression
2089 
2090  Backing store: enum SHOW_COMP_OPTION
2091 
2092  @note
2093  These variables are necessarily read-only, only global, and have no
2094  command-line equivalent.
2095 */
2096 class Sys_var_have : public sys_var {
2097  public:
2099  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
2100  size_t size [[maybe_unused]], CMD_LINE getopt, PolyLock *lock = nullptr,
2101  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
2102  on_check_function on_check_func = nullptr,
2103  on_update_function on_update_func = nullptr,
2104  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
2105  : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
2106  getopt.arg_type, SHOW_CHAR, 0, lock, binlog_status_arg,
2107  on_check_func, on_update_func, substitute, parse_flag) {
2108  assert(scope() == GLOBAL);
2109  assert(getopt.id == -1);
2110  assert(lock == nullptr);
2111  assert(binlog_status_arg == VARIABLE_NOT_IN_BINLOG);
2112  assert(is_readonly());
2113  assert(on_update == nullptr);
2114  assert(size == sizeof(enum SHOW_COMP_OPTION));
2115  }
2116  bool do_check(THD *, set_var *) override {
2117  assert(false);
2118  return true;
2119  }
2120  bool session_update(THD *, set_var *) override {
2121  assert(false);
2122  return true;
2123  }
2124  bool global_update(THD *, set_var *) override {
2125  assert(false);
2126  return true;
2127  }
2128  void session_save_default(THD *, set_var *) override {}
2129  void global_save_default(THD *, set_var *) override {}
2130  void saved_value_to_string(THD *, set_var *, char *) override {}
2131  const uchar *session_value_ptr(THD *, THD *, LEX_STRING *) override {
2132  assert(false);
2133  return nullptr;
2134  }
2135  const uchar *global_value_ptr(THD *, LEX_STRING *) override {
2136  return pointer_cast<const uchar *>(
2138  }
2139  bool check_update_type(Item_result) override { return false; }
2140 };
2141 
2142 /**
2143  A subclass of @ref Sys_var_have to return dynamic values
2144 
2145  All the usual restrictions for @ref Sys_var_have apply.
2146  But instead of reading a global variable it calls a function
2147  to return the value.
2148  */
2150  public:
2151  /**
2152  Construct a new variable.
2153 
2154  @param name_arg The name of the variable
2155  @param comment Explanation of what the variable does
2156  @param func The function to call when in need to read the global value
2157  @param substitute If the variable is deprecated what to use instead
2158  */
2159  Sys_var_have_func(const char *name_arg, const char *comment,
2160  enum SHOW_COMP_OPTION (*func)(THD *),
2161  const char *substitute = nullptr)
2162  /*
2163  Note: it doesn't really matter what variable we use, as long as we are
2164  using one. So we use a local static dummy
2165  */
2166  : Sys_var_have(name_arg, comment,
2169  substitute),
2170  func_(func) {}
2171 
2172  const uchar *global_value_ptr(THD *thd, LEX_STRING *) override {
2173  return pointer_cast<const uchar *>(show_comp_option_name[func_(thd)]);
2174  }
2175 
2176  protected:
2177  enum SHOW_COMP_OPTION (*func_)(THD *);
2178  static enum SHOW_COMP_OPTION dummy_;
2179 };
2180 /**
2181  Generic class for variables for storing entities that are internally
2182  represented as structures, have names, and possibly can be referred to by
2183  numbers. Examples: character sets, collations, locales,
2184 
2185  Backing store: void*
2186  @tparam Struct_type type of struct being wrapped
2187  @tparam Name_getter must provide Name_getter(Struct_type*).get_name()
2188 
2189  @note
2190  As every such a structure requires special treatment from my_getopt,
2191  these variables don't support command-line equivalents, any such
2192  command-line options should be added manually to my_long_options in mysqld.cc
2193 */
2194 template <typename Struct_type, typename Name_getter>
2195 class Sys_var_struct : public sys_var {
2196  public:
2198  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
2199  size_t size [[maybe_unused]], CMD_LINE getopt, void *def_val,
2200  PolyLock *lock = nullptr,
2201  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
2202  on_check_function on_check_func = nullptr,
2203  on_update_function on_update_func = nullptr,
2204  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
2205  : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
2206  getopt.arg_type, SHOW_CHAR, (intptr)def_val, lock,
2207  binlog_status_arg, on_check_func, on_update_func, substitute,
2208  parse_flag) {
2210  /*
2211  struct variables are special on the command line - often (e.g. for
2212  charsets) the name cannot be immediately resolved, but only after all
2213  options (in particular, basedir) are parsed.
2214 
2215  thus all struct command-line options should be added manually
2216  to my_long_options in mysqld.cc
2217  */
2218  assert(getopt.id == -1);
2219  assert(size == sizeof(void *));
2220  }
2221  bool do_check(THD *, set_var *) override { return false; }
2222  bool session_update(THD *thd, set_var *var) override {
2223  session_var(thd, const void *) = var->save_result.ptr;
2224  return false;
2225  }
2226  bool global_update(THD *, set_var *var) override {
2227  global_var(const void *) = var->save_result.ptr;
2228  return false;
2229  }
2230  void session_save_default(THD *, set_var *var) override {
2231  var->save_result.ptr = global_var(void *);
2232  }
2233  void global_save_default(THD *, set_var *var) override {
2234  void **default_value = reinterpret_cast<void **>(option.def_value);
2235  var->save_result.ptr = *default_value;
2236  }
2237  void saved_value_to_string(THD *, set_var *var, char *def_val) override {
2238  const Struct_type *ptr =
2239  static_cast<const Struct_type *>(var->save_result.ptr);
2240  if (ptr)
2241  strcpy(def_val, pointer_cast<const char *>(Name_getter(ptr).get_name()));
2242  }
2244  return type != INT_RESULT && type != STRING_RESULT;
2245  }
2246  const uchar *session_value_ptr(THD *, THD *target_thd,
2247  LEX_STRING *) override {
2248  const Struct_type *ptr = session_var(target_thd, const Struct_type *);
2249  return ptr ? Name_getter(ptr).get_name() : nullptr;
2250  }
2251  const uchar *global_value_ptr(THD *, LEX_STRING *) override {
2252  const Struct_type *ptr = global_var(const Struct_type *);
2253  return ptr ? Name_getter(ptr).get_name() : nullptr;
2254  }
2255 };
2256 
2257 /**
2258  The class for variables that store time zones
2259 
2260  Backing store: Time_zone*
2261 
2262  @note
2263  Time zones cannot be supported directly by my_getopt, thus
2264  these variables don't support command-line equivalents, any such
2265  command-line options should be added manually to my_long_options in mysqld.cc
2266 */
2267 class Sys_var_tz : public sys_var {
2268  public:
2269  Sys_var_tz(const char *name_arg, const char *comment, int flag_args,
2270  ptrdiff_t off, size_t size [[maybe_unused]], CMD_LINE getopt,
2271  Time_zone **def_val, PolyLock *lock = nullptr,
2272  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
2273  on_check_function on_check_func = nullptr,
2274  on_update_function on_update_func = nullptr,
2275  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
2276  : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
2277  getopt.arg_type, SHOW_CHAR, (intptr)def_val, lock,
2278  binlog_status_arg, on_check_func, on_update_func, substitute,
2279  parse_flag) {
2280  assert(getopt.id == -1);
2281  assert(size == sizeof(Time_zone *));
2283  }
2284  bool do_check(THD *thd, set_var *var) override {
2285  char buff[MAX_TIME_ZONE_NAME_LENGTH];
2286  String str(buff, sizeof(buff), &my_charset_latin1);
2287  String *res = var->value->val_str(&str);
2288 
2289  if (!res) return true;
2290 
2291  if (!(var->save_result.time_zone = my_tz_find(thd, res))) {
2292  ErrConvString err(res);
2293  my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), err.ptr());
2294  return true;
2295  }
2296  return false;
2297  }
2298  bool session_update(THD *thd, set_var *var) override {
2299  session_var(thd, Time_zone *) = var->save_result.time_zone;
2300  return false;
2301  }
2302  bool global_update(THD *, set_var *var) override {
2304  return false;
2305  }
2306  void session_save_default(THD *, set_var *var) override {
2308  }
2309  void global_save_default(THD *, set_var *var) override {
2311  }
2312  void saved_value_to_string(THD *, set_var *var, char *def_val) override {
2313  strcpy(def_val, var->save_result.time_zone->get_name()->ptr());
2314  }
2315  const uchar *session_value_ptr(THD *, THD *target_thd,
2316  LEX_STRING *) override {
2317  /*
2318  This is an ugly fix for replication: we don't replicate properly queries
2319  invoking system variables' values to update tables; but
2320  CONVERT_TZ(,,@@session.time_zone) is so popular that we make it
2321  replicable (i.e. we tell the binlog code to store the session
2322  timezone). If it's the global value which was used we can't replicate
2323  (binlog code stores session value only).
2324  */
2325  target_thd->time_zone_used = true;
2326  return pointer_cast<const uchar *>(
2327  session_var(target_thd, Time_zone *)->get_name()->ptr());
2328  }
2329  const uchar *global_value_ptr(THD *, LEX_STRING *) override {
2330  return pointer_cast<const uchar *>(
2331  global_var(Time_zone *)->get_name()->ptr());
2332  }
2334  return type != STRING_RESULT;
2335  }
2336 };
2337 
2338 /**
2339  Class representing the 'transaction_isolation' system variable. This
2340  variable can also be indirectly set using 'SET TRANSACTION ISOLATION
2341  LEVEL'.
2342 */
2343 
2345  public:
2346  Sys_var_transaction_isolation(const char *name_arg, const char *comment,
2347  int flag_args, ptrdiff_t off, size_t size,
2348  CMD_LINE getopt, const char *values[],
2349  uint def_val, PolyLock *lock,
2350  enum binlog_status_enum binlog_status_arg,
2351  on_check_function on_check_func)
2352  : Sys_var_enum(name_arg, comment, flag_args, off, size, getopt, values,
2353  def_val, lock, binlog_status_arg, on_check_func) {}
2354  bool session_update(THD *thd, set_var *var) override;
2355 };
2356 
2357 /**
2358  Class representing the tx_read_only system variable for setting
2359  default transaction access mode.
2360 
2361  Note that there is a special syntax - SET TRANSACTION READ ONLY
2362  (or READ WRITE) that sets the access mode for the next transaction
2363  only.
2364 */
2365 
2367  public:
2368  Sys_var_transaction_read_only(const char *name_arg, const char *comment,
2369  int flag_args, ptrdiff_t off, size_t size,
2370  CMD_LINE getopt, bool def_val, PolyLock *lock,
2371  enum binlog_status_enum binlog_status_arg,
2372  on_check_function on_check_func)
2373  : Sys_var_bool(name_arg, comment, flag_args, off, size, getopt, def_val,
2374  lock, binlog_status_arg, on_check_func) {}
2375  bool session_update(THD *thd, set_var *var) override;
2376 };
2377 
2378 /**
2379  A class for @@global.binlog_checksum that has
2380  a specialized update method.
2381 */
2383  public:
2384  Sys_var_enum_binlog_checksum(const char *name_arg, const char *comment,
2385  int flag_args, ptrdiff_t off, size_t size,
2386  CMD_LINE getopt, const char *values[],
2387  uint def_val, PolyLock *lock,
2388  enum binlog_status_enum binlog_status_arg,
2389  on_check_function on_check_func = nullptr)
2390  : Sys_var_enum(name_arg, comment, flag_args | PERSIST_AS_READ_ONLY, off,
2391  size, getopt, values, def_val, lock, binlog_status_arg,
2392  on_check_func, nullptr) {}
2393  bool global_update(THD *thd, set_var *var) override;
2394 };
2395 
2396 /**
2397  Class for gtid_next.
2398 */
2399 class Sys_var_gtid_next : public sys_var {
2400  public:
2402  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
2403  size_t size [[maybe_unused]], CMD_LINE getopt, const char *def_val,
2404  PolyLock *lock = nullptr,
2405  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
2406  on_check_function on_check_func = nullptr,
2407  on_update_function on_update_func = nullptr,
2408  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
2409  : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
2410  getopt.arg_type, SHOW_CHAR, (intptr)def_val, lock,
2411  binlog_status_arg, on_check_func, on_update_func, substitute,
2412  parse_flag) {
2413  assert(size == sizeof(Gtid_specification));
2414  }
2415  bool session_update(THD *thd, set_var *var) override;
2416 
2417  bool global_update(THD *, set_var *) override {
2418  assert(false);
2419  return true;
2420  }
2421  void session_save_default(THD *, set_var *var) override {
2422  DBUG_TRACE;
2423  char *ptr = (char *)(intptr)option.def_value;
2424  var->save_result.string_value.str = ptr;
2425  var->save_result.string_value.length = ptr ? strlen(ptr) : 0;
2426  return;
2427  }
2428  void global_save_default(THD *, set_var *) override { assert(false); }
2429  void saved_value_to_string(THD *, set_var *, char *) override {
2430  assert(false);
2431  }
2432  bool do_check(THD *, set_var *) override { return false; }
2434  return type != STRING_RESULT;
2435  }
2436  const uchar *session_value_ptr(THD *running_thd, THD *target_thd,
2437  LEX_STRING *) override {
2438  DBUG_TRACE;
2441  ((Gtid_specification *)session_var_ptr(target_thd))
2444  char *ret = running_thd->mem_strdup(buf);
2445  return (uchar *)ret;
2446  }
2447  const uchar *global_value_ptr(THD *, LEX_STRING *) override {
2448  assert(false);
2449  return nullptr;
2450  }
2451 };
2452 
2453 #ifdef HAVE_GTID_NEXT_LIST
2454 /**
2455  Class for variables that store values of type Gtid_set.
2456 
2457  The back-end storage should be a Gtid_set_or_null, and it should be
2458  set to null by default. When the variable is set for the first
2459  time, the Gtid_set* will be allocated.
2460 */
2461 class Sys_var_gtid_set : public sys_var {
2462  public:
2463  Sys_var_gtid_set(
2464  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
2465  size_t size, CMD_LINE getopt, const char *def_val, PolyLock *lock = 0,
2466  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
2467  on_check_function on_check_func = 0,
2468  on_update_function on_update_func = 0, const char *substitute = 0,
2469  int parse_flag = PARSE_NORMAL)
2470  : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
2471  getopt.arg_type, SHOW_CHAR, (intptr)def_val, lock,
2472  binlog_status_arg, on_check_func, on_update_func, substitute,
2473  parse_flag) {
2474  assert(size == sizeof(Gtid_set_or_null));
2475  }
2476  bool session_update(THD *thd, set_var *var);
2477 
2478  bool global_update(THD *thd, set_var *var) {
2479  assert(false);
2480  return true;
2481  }
2482  void session_save_default(THD *thd, set_var *var) {
2483  DBUG_TRACE;
2485  char *ptr = (char *)(intptr)option.def_value;
2486  var->save_result.string_value.str = ptr;
2487  var->save_result.string_value.length = ptr ? strlen(ptr) : 0;
2489  return;
2490  }
2491  void global_save_default(THD *thd, set_var *var) { assert(false); }
2492  void saved_value_to_string(THD *, set_var *, char *) { assert(false); }
2493  bool do_check(THD *thd, set_var *var) {
2494  DBUG_TRACE;
2495  String str;
2496  String *res = var->value->val_str(&str);
2497  if (res == NULL) {
2499  return false;
2500  }
2501  assert(res->ptr() != NULL);
2502  var->save_result.string_value.str = thd->strmake(res->ptr(), res->length());
2503  if (var->save_result.string_value.str == NULL) {
2504  my_error(ER_OUT_OF_RESOURCES, MYF(0)); // thd->strmake failed
2505  return 1;
2506  }
2507  var->save_result.string_value.length = res->length();
2508  bool ret = !Gtid_set::is_valid(res->ptr());
2509  return ret;
2510  }
2511  bool check_update_type(Item_result type) { return type != STRING_RESULT; }
2512  uchar *session_value_ptr(THD *running_thd, THD *target_thd,
2513  LEX_STRING *base) {
2514  DBUG_TRACE;
2515  Gtid_set_or_null *gsn = (Gtid_set_or_null *)session_var_ptr(target_thd);
2516  Gtid_set *gs = gsn->get_gtid_set();
2517  if (gs == NULL) return NULL;
2518  char *buf;
2520  buf = (char *)running_thd->alloc(gs->get_string_length() + 1);
2521  if (buf)
2522  gs->to_string(buf);
2523  else
2524  my_error(ER_OUT_OF_RESOURCES, MYF(0)); // thd->alloc failed
2526  return (uchar *)buf;
2527  }
2528  uchar *global_value_ptr(THD *thd, LEX_STRING *base) {
2529  assert(false);
2530  return NULL;
2531  }
2532 };
2533 #endif
2534 
2535 /**
2536  Abstract base class for read-only variables (global or session) of
2537  string type where the value is generated by some function. This
2538  needs to be subclassed; the session_value_ptr or global_value_ptr
2539  function should be overridden. Since these variables cannot be
2540  set at command line, they cannot be persisted.
2541 */
2543  public:
2544  Sys_var_charptr_func(const char *name_arg, const char *comment,
2545  flag_enum flag_arg)
2546  : sys_var(&all_sys_vars, name_arg, comment,
2547  READ_ONLY NON_PERSIST flag_arg, 0 /*off*/, NO_CMD_LINE.id,
2548  NO_CMD_LINE.arg_type, SHOW_CHAR, (intptr)0 /*def_val*/,
2549  nullptr /*polylock*/, VARIABLE_NOT_IN_BINLOG,
2550  nullptr /*on_check_func*/, nullptr /*on_update_func*/,
2551  nullptr /*substitute*/, PARSE_NORMAL /*parse_flag*/) {
2552  assert(flag_arg == sys_var::GLOBAL || flag_arg == sys_var::SESSION ||
2553  flag_arg == sys_var::ONLY_SESSION);
2554  }
2555  bool session_update(THD *, set_var *) override {
2556  assert(false);
2557  return true;
2558  }
2559  bool global_update(THD *, set_var *) override {
2560  assert(false);
2561  return true;
2562  }
2563  void session_save_default(THD *, set_var *) override { assert(false); }
2564  void global_save_default(THD *, set_var *) override { assert(false); }
2565  void saved_value_to_string(THD *, set_var *, char *) override {
2566  assert(false);
2567  }
2568  bool do_check(THD *, set_var *) override {
2569  assert(false);
2570  return true;
2571  }
2573  assert(false);
2574  return true;
2575  }
2576  const uchar *session_value_ptr(THD *, THD *, LEX_STRING *) override {
2577  assert(false);
2578  return nullptr;
2579  }
2580  const uchar *global_value_ptr(THD *, LEX_STRING *) override {
2581  assert(false);
2582  return nullptr;
2583  }
2584 };
2585 
2586 /**
2587  Class for @@global.gtid_executed.
2588 */
2590  public:
2591  Sys_var_gtid_executed(const char *name_arg, const char *comment_arg)
2592  : Sys_var_charptr_func(name_arg, comment_arg, GLOBAL) {}
2593 
2594  const uchar *global_value_ptr(THD *thd, LEX_STRING *) override {
2595  DBUG_TRACE;
2597  const Gtid_set *gs = gtid_state->get_executed_gtids();
2598  char *buf = (char *)thd->alloc(gs->get_string_length() + 1);
2599  if (buf == nullptr)
2600  my_error(ER_OUT_OF_RESOURCES, MYF(0));
2601  else
2602  gs->to_string(buf);
2604  return (uchar *)buf;
2605  }
2606 };
2607 
2608 /**
2609  Class for @@global.system_time_zone.
2610 */
2612  public:
2613  Sys_var_system_time_zone(const char *name_arg, const char *comment_arg)
2614  : Sys_var_charptr_func(name_arg, comment_arg, GLOBAL) {
2615  is_os_charset = true;
2616  }
2617 
2618  const uchar *global_value_ptr(THD *, LEX_STRING *) override {
2619  DBUG_TRACE;
2620  time_t current_time = my_time(0);
2621  DBUG_EXECUTE_IF("set_cet_before_dst", {
2622  // 1616893190 => Sunday March 28, 2021 01:59:50 (am) (CET)
2623  current_time = 1616893190;
2624  });
2625  DBUG_EXECUTE_IF("set_cet_after_dst", {
2626  // 1616893200 => Sunday March 28, 2021 03:00:00 (am) (CEST)
2627  current_time = 1616893200;
2628  });
2629 
2630  struct tm tm_tmp;
2631  localtime_r(&current_time, &tm_tmp);
2632  return (uchar *)(tm_tmp.tm_isdst != 0 ? system_time_zone_dst_on
2634  }
2635 };
2636 
2637 /**
2638  Class for @@session.gtid_purged.
2639 */
2641  public:
2643  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
2644  size_t, CMD_LINE getopt, const char *def_val, PolyLock *lock = nullptr,
2645  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
2646  on_check_function on_check_func = nullptr,
2647  on_update_function on_update_func = nullptr,
2648  const char *substitute = nullptr, int parse_flag = PARSE_NORMAL)
2649  : sys_var(&all_sys_vars, name_arg, comment, flag_args, off, getopt.id,
2650  getopt.arg_type, SHOW_CHAR, (intptr)def_val, lock,
2651  binlog_status_arg, on_check_func, on_update_func, substitute,
2652  parse_flag) {}
2653 
2654  bool session_update(THD *, set_var *) override {
2655  assert(false);
2656  return true;
2657  }
2658 
2659  void session_save_default(THD *, set_var *) override { assert(false); }
2660 
2661  bool global_update(THD *thd, set_var *var) override;
2662 
2663  void global_save_default(THD *, set_var *var) override {
2664  /* gtid_purged does not have default value */
2665  my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str);
2666  }
2667  void saved_value_to_string(THD *, set_var *var, char *) override {
2668  my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str);
2669  }
2670 
2671  bool do_check(THD *thd, set_var *var) override {
2672  DBUG_TRACE;
2673  char buf[1024];
2674  String str(buf, sizeof(buf), system_charset_info);
2675  String *res = var->value->val_str(&str);
2676  if (!res) return true;
2677  var->save_result.string_value.str = thd->strmake(res->ptr(), res->length());
2678  if (!var->save_result.string_value.str) {
2679  my_error(ER_OUT_OF_RESOURCES, MYF(0)); // thd->strmake failed
2680  return true;
2681  }
2682  var->save_result.string_value.length = res->length();
2683  bool ret =
2684  Gtid_set::is_valid(var->save_result.string_value.str) ? false : true;
2685  DBUG_PRINT("info", ("ret=%d", ret));
2686  return ret;
2687  }
2688 
2690  return type != STRING_RESULT;
2691  }
2692 
2693  const uchar *global_value_ptr(THD *thd, LEX_STRING *) override {
2694  DBUG_TRACE;
2695  const Gtid_set *gs;
2697  if (opt_bin_log)
2698  gs = gtid_state->get_lost_gtids();
2699  else
2700  /*
2701  When binlog is off, report @@GLOBAL.GTID_PURGED from
2702  executed_gtids, since @@GLOBAL.GTID_PURGED and
2703  @@GLOBAL.GTID_EXECUTED are always same, so we did not
2704  save gtid into lost_gtids for every transaction for
2705  improving performance.
2706  */
2708  char *buf = (char *)thd->alloc(gs->get_string_length() + 1);
2709  if (buf == nullptr)
2710  my_error(ER_OUT_OF_RESOURCES, MYF(0));
2711  else
2712  gs->to_string(buf);
2714  return (uchar *)buf;
2715  }
2716 
2717  const uchar *session_value_ptr(THD *, THD *, LEX_STRING *) override {
2718  assert(false);
2719  return nullptr;
2720  }
2721 };
2722 
2724  public:
2725  Sys_var_gtid_owned(const char *name_arg, const char *comment_arg)
2726  : Sys_var_charptr_func(name_arg, comment_arg, SESSION) {}
2727 
2728  public:
2729  const uchar *session_value_ptr(THD *running_thd, THD *target_thd,
2730  LEX_STRING *) override {
2731  DBUG_TRACE;
2732  char *buf = nullptr;
2733  bool remote = (target_thd != running_thd);
2734 
2735  if (target_thd->owned_gtid.sidno == 0)
2736  return (uchar *)running_thd->mem_strdup("");
2737  else if (target_thd->owned_gtid.sidno == THD::OWNED_SIDNO_ANONYMOUS) {
2739  return (uchar *)running_thd->mem_strdup("ANONYMOUS");
2740  } else if (target_thd->owned_gtid.sidno == THD::OWNED_SIDNO_GTID_SET) {
2741 #ifdef HAVE_GTID_NEXT_LIST
2742  buf = (char *)running_thd->alloc(
2743  target_thd->owned_gtid_set.get_string_length() + 1);
2744  if (buf) {
2746  target_thd->owned_gtid_set.to_string(buf);
2748  } else
2749  my_error(ER_OUT_OF_RESOURCES, MYF(0));
2750 #else
2751  assert(0);
2752 #endif
2753  } else {
2754  buf = (char *)running_thd->alloc(Gtid::MAX_TEXT_LENGTH + 1);
2755  if (buf) {
2756  /* Take the lock if accessing another session. */
2757  if (remote) global_sid_lock->rdlock();
2758  running_thd->owned_gtid.to_string(target_thd->owned_sid, buf);
2759  if (remote) global_sid_lock->unlock();
2760  } else
2761  my_error(ER_OUT_OF_RESOURCES, MYF(0));
2762  }
2763  return (uchar *)buf;
2764  }
2765 
2766  const uchar *global_value_ptr(THD *thd, LEX_STRING *) override {
2767  DBUG_TRACE;
2768  const Owned_gtids *owned_gtids = gtid_state->get_owned_gtids();
2770  char *buf = (char *)thd->alloc(owned_gtids->get_max_string_length());
2771  if (buf)
2772  owned_gtids->to_string(buf);
2773  else
2774  my_error(ER_OUT_OF_RESOURCES, MYF(0)); // thd->alloc failed
2776  return (uchar *)buf;
2777  }
2778 };
2779 
2781  public:
2783  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
2784  size_t size, CMD_LINE getopt, const char *values[], uint def_val,
2785  PolyLock *lock = nullptr,
2786  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
2787  on_check_function on_check_func = nullptr)
2788  : Sys_var_enum(name_arg, comment, flag_args, off, size, getopt, values,
2789  def_val, lock, binlog_status_arg, on_check_func) {}
2790 
2791  bool global_update(THD *thd, set_var *var) override;
2792 };
2793 
2795  public:
2797  const char *name_arg, const char *comment, int flag_args, ptrdiff_t off,
2798  size_t size, CMD_LINE getopt, const ALIAS aliases[],
2800  PolyLock *lock = nullptr,
2801  enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
2802  on_check_function on_check_func = nullptr)
2803  : Sys_var_multi_enum(name_arg, comment, flag_args, off, size, getopt,
2805  lock, binlog_status_arg, on_check_func) {}
2806 
2807  bool global_update(THD *thd, set_var *var) override;
2808 };
2809 
2811  public:
2812  Sys_var_binlog_encryption(const char *name_arg, const char *comment,
2813  int flag_args, ptrdiff_t off, size_t size,
2814  CMD_LINE getopt, bool def_val, PolyLock *lock,
2815  enum binlog_status_enum binlog_status_arg,
2816  on_check_function on_check_func)
2817  : Sys_var_bool(name_arg, comment, flag_args | PERSIST_AS_READ_ONLY, off,
2818  size, getopt, def_val, lock, binlog_status_arg,
2819  on_check_func) {}
2820  bool global_update(THD *thd, set_var *var) override;
2821 };
2822 
2823 #endif /* SYS_VARS_H_INCLUDED */
void rdlock()
Acquire the read lock.
Definition: rpl_gtid.h:441
void wrlock()
Acquire the write lock.
Definition: rpl_gtid.h:450
void unlock()
Release the lock (whether it is a write or read lock).
Definition: rpl_gtid.h:461
Definition: sql_error.h:221
Represents a set of GTIDs.
Definition: rpl_gtid.h:1435
static bool is_valid(const char *text)
Returns true if the given string is a valid specification of a Gtid_set, false otherwise.
Definition: rpl_gtid_set.cc:567
size_t get_string_length(const String_format *string_format=nullptr) const
Returns the length of the output from to_string.
Definition: rpl_gtid_set.cc:868
size_t to_string(char *buf, bool need_lock=false, const String_format *string_format=nullptr) const
Formats this Gtid_set as a string and saves in a given buffer.
Definition: rpl_gtid_set.cc:760
const Gtid_set * get_lost_gtids() const
Return a pointer to the Gtid_set that contains the lost gtids.
Definition: rpl_gtid.h:3164
const Gtid_set * get_executed_gtids() const
Definition: rpl_gtid.h:3169
const Owned_gtids * get_owned_gtids() const
Return a pointer to the Owned_gtids that contains the owned gtids.
Definition: rpl_gtid.h:3185
int32 get_anonymous_ownership_count()
Return the number of clients that hold anonymous ownership.
Definition: rpl_gtid.h:2845
virtual double val_real()=0
virtual longlong val_int()=0
virtual Item_result result_type() const
Definition: item.h:1267
virtual String * val_str(String *str)=0
bool unsigned_flag
Definition: item.h:3354
Represents the set of GTIDs that are owned by some thread.
Definition: rpl_gtid.h:2397
size_t get_max_string_length() const
Return an upper bound on the length of the string representation of this Owned_gtids.
Definition: rpl_gtid.h:2492
int to_string(char *out) const
Write a string representation of this Owned_gtids to the given buffer.
Definition: rpl_gtid.h:2465
wrapper to hide a mutex and an rwlock under a common interface
Definition: sys_vars_shared.h:49
char * strmake(const char *str, size_t size) const
Definition: sql_class.h:324
char * mem_strdup(const char *str)
Definition: sql_class.h:323
void * alloc(size_t size)
Definition: sql_class.h:308
LEX_CSTRING external_user() const
Getter method for member m_external_user.
Definition: sql_security_ctx.h:444
LEX_CSTRING proxy_user() const
Getter method for member m_proxy_user.
Definition: sql_security_ctx.cc:1036
bool update(char **var, char *val, size_t val_len)
Frees the old alloced memory, memdup()'s the given val to a new memory address & updated the session ...
Definition: sys_vars_resource_mgr.cc:72
@ SL_WARNING
Definition: sql_error.h:59
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:165
LEX_CSTRING lex_cstring() const
Definition: sql_string.h:273
const char * ptr() const
Definition: sql_string.h:247
static bool needs_conversion(size_t arg_length, const CHARSET_INFO *cs_from, const CHARSET_INFO *cs_to, size_t *offset)
Definition: sql_string.cc:268
size_t length() const
Definition: sql_string.h:239
const CHARSET_INFO * charset() const
Definition: sql_string.h:238
A sys_var that is an alias for another sys_var.
Definition: sys_vars.h:338
Sys_var_alias(const char *name_arg, sys_var &base_var, const char *deprecation_substitute_arg, sys_var *persisted_alias, bool is_persisted_deprecated)
Special constructor used to implement Sys_var_deprecated alias.
Definition: sys_vars.h:364
virtual ulong get_var_type() override
Returns variable type.
Definition: sys_vars.h:400
virtual void cleanup() override
All the cleanup procedures should be performed here.
Definition: sys_vars.h:386
sys_var & m_base_var
Definition: sys_vars.h:340
virtual void set_source(enum_variable_source src) override
Definition: sys_vars.h:423
virtual const char * get_user() override
Definition: sys_vars.h:432
virtual bool set_host(const char *hst) override
Definition: sys_vars.h:434
virtual longlong get_min_value() override
Definition: sys_vars.h:394
virtual bool global_update(THD *thd, set_var *var) override
Definition: sys_vars.h:461
virtual const uchar * global_value_ptr(THD *thd, LEX_STRING *base) override
Definition: sys_vars.h:470
virtual bool set_user(const char *usr) override
Definition: sys_vars.h:429
virtual void set_timestamp() override
Definition: sys_vars.h:443
virtual ulonglong get_max_value() override
Definition: sys_vars.h:397
virtual enum_variable_source get_source() override
Definition: sys_vars.h:417
sys_var & get_base_var()
Definition: sys_vars.h:384
Sys_var_alias(const char *name_arg, sys_var &base_var)
Definition: sys_vars.h:380
virtual const char * get_source_name() override
Definition: sys_vars.h:420
virtual bool set_source_name(const char *path) override
Definition: sys_vars.h:426
virtual longlong get_default() override
Definition: sys_vars.h:393
virtual sys_var_pluginvar * cast_pluginvar() override
downcast for sys_var_pluginvar.
Definition: sys_vars.h:387
virtual ulonglong get_timestamp() const override
Definition: sys_vars.h:437
virtual void saved_value_to_string(THD *thd, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:410
virtual bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:458
virtual bool check_update_type(Item_result type) override
Definition: sys_vars.h:414
virtual bool do_check(THD *thd, set_var *var) override
Definition: sys_vars.h:449
virtual const uchar * session_value_ptr(THD *running_thd, THD *target_thd, LEX_STRING *base) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:466
virtual void update_default(longlong new_def_value) override
Definition: sys_vars.h:390
virtual void set_user_host(THD *thd) override
Definition: sys_vars.h:440
virtual bool is_non_persistent() override
Definition: sys_vars.h:407
virtual void set_arg_source(get_opt_arg_source *arg_source) override
Definition: sys_vars.h:401
virtual const char * get_host() override
Definition: sys_vars.h:433
virtual void global_save_default(THD *thd, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:455
virtual void set_timestamp(ulonglong ts) override
Definition: sys_vars.h:444
virtual void set_is_plugin(bool is_plugin) override
Definition: sys_vars.h:404
virtual void session_save_default(THD *thd, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:452
Definition: sys_vars.h:2810
Sys_var_binlog_encryption(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size, CMD_LINE getopt, bool def_val, PolyLock *lock, enum binlog_status_enum binlog_status_arg, on_check_function on_check_func)
Definition: sys_vars.h:2812
bool global_update(THD *thd, set_var *var) override
Definition: sys_vars.cc:7084
The class for bit variables - a variant of boolean that stores the value in a bit.
Definition: sys_vars.h:1907
void global_save_default(THD *, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:1949
const uchar * session_value_ptr(THD *running_thd, THD *target_thd, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:1955
Sys_var_bit(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, ulonglong bitmask_arg, bool def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, pre_update_function pre_update_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr)
Definition: sys_vars.h:1918
void saved_value_to_string(THD *, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:1952
void session_save_default(THD *, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:1946
const uchar * global_value_ptr(THD *thd, LEX_STRING *) override
Definition: sys_vars.h:1962
void set(uchar *ptr, ulonglong value)
Definition: sys_vars.h:1910
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:1938
ulonglong bitmask
Definition: sys_vars.h:1908
bool reverse_semantics
Definition: sys_vars.h:1909
bool global_update(THD *, set_var *var) override
Definition: sys_vars.h:1942
The class for boolean variables - a variant of ENUM variables with the fixed list of values of { OFF ...
Definition: sys_vars.h:687
bool global_update(THD *, set_var *var) override
Definition: sys_vars.h:710
void session_save_default(THD *thd, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:714
Sys_var_bool(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, bool def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr, int parse_flag=PARSE_NORMAL)
Definition: sys_vars.h:689
void saved_value_to_string(THD *, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:721
void global_save_default(THD *, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:718
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:705
Abstract base class for read-only variables (global or session) of string type where the value is gen...
Definition: sys_vars.h:2542
bool session_update(THD *, set_var *) override
Definition: sys_vars.h:2555
Sys_var_charptr_func(const char *name_arg, const char *comment, flag_enum flag_arg)
Definition: sys_vars.h:2544
bool check_update_type(Item_result) override
Definition: sys_vars.h:2572
const uchar * global_value_ptr(THD *, LEX_STRING *) override
Definition: sys_vars.h:2580
bool do_check(THD *, set_var *) override
Definition: sys_vars.h:2568
const uchar * session_value_ptr(THD *, THD *, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:2576
void saved_value_to_string(THD *, set_var *, char *) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:2565
bool global_update(THD *, set_var *) override
Definition: sys_vars.h:2559
void global_save_default(THD *, set_var *) override
save the global default value of the variable in var
Definition: sys_vars.h:2564
void session_save_default(THD *, set_var *) override
save the session default value of the variable in var
Definition: sys_vars.h:2563
The class for string variables.
Definition: sys_vars.h:1010
bool do_check(THD *thd, set_var *var) override
Definition: sys_vars.h:1036
bool check_update_type(Item_result type) override
Definition: sys_vars.h:1097
void cleanup() override
All the cleanup procedures should be performed here.
Definition: sys_vars.h:1031
void saved_value_to_string(THD *, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:1093
void global_save_default(THD *, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:1077
void session_save_default(THD *, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:1071
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:1060
bool global_update(THD *thd, set_var *var) override
Definition: sys_vars.cc:4058
Sys_var_charptr(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, enum charset_enum is_os_charset_arg, const char *def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr, int parse_flag=PARSE_NORMAL)
Definition: sys_vars.h:1012
@session.dbug and @global.dbug variables.
Definition: sys_vars.h:1228
bool do_check(THD *thd, set_var *var) override
Definition: sys_vars.h:1243
void session_save_default(THD *, set_var *) override
save the session default value of the variable in var
Definition: sys_vars.h:1267
bool check_update_type(Item_result type) override
Definition: sys_vars.h:1287
bool session_update(THD *, set_var *var) override
Definition: sys_vars.h:1254
bool global_update(THD *, set_var *var) override
Definition: sys_vars.h:1262
Sys_var_dbug(const char *name_arg, const char *comment, int flag_args, CMD_LINE getopt, const char *def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr, int parse_flag=PARSE_NORMAL)
Definition: sys_vars.h:1230
const uchar * global_value_ptr(THD *thd, LEX_STRING *) override
Definition: sys_vars.h:1282
const uchar * session_value_ptr(THD *running_thd, THD *, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:1276
void saved_value_to_string(THD *, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:1272
void global_save_default(THD *, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:1268
A deprecated alias for a variable.
Definition: sys_vars.h:553
std::string m_comment
Definition: sys_vars.h:555
Sys_var_deprecated_alias(const char *name_arg, sys_var &base_var)
Definition: sys_vars.h:558
The class for floating point variables.
Definition: sys_vars.h:1390
bool global_update(THD *, set_var *var) override
Definition: sys_vars.h:1426
void saved_value_to_string(THD *, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:1439
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:1422
void global_save_default(THD *, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:1436
bool check_update_type(Item_result type) override
Definition: sys_vars.h:1430
bool do_check(THD *thd, set_var *var) override
Definition: sys_vars.h:1414
Sys_var_double(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, double min_val, double max_val, double def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr, int parse_flag=PARSE_NORMAL)
Definition: sys_vars.h:1392
void session_save_default(THD *, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:1433
Definition: sys_vars.h:2794
Sys_var_enforce_gtid_consistency(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size, CMD_LINE getopt, const ALIAS aliases[], const uint value_count, uint def_val, uint command_line_no_value, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr)
Definition: sys_vars.h:2796
bool global_update(THD *thd, set_var *var) override
Definition: sys_vars.cc:4521
A class for @global.binlog_checksum that has a specialized update method.
Definition: sys_vars.h:2382
bool global_update(THD *thd, set_var *var) override
Definition: sys_vars.cc:4074
Sys_var_enum_binlog_checksum(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=nullptr)
Definition: sys_vars.h:2384
The class for ENUM variables - variables that take one value from a fixed list of values.
Definition: sys_vars.h:634
void session_save_default(THD *, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:661
bool global_update(THD *, set_var *var) override
Definition: sys_vars.h:657
void saved_value_to_string(THD *, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:667
const uchar * session_value_ptr(THD *, THD *target_thd, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:671
void global_save_default(THD *, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:664
Sys_var_enum(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, const char *values[], uint def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr, int parse_flag=PARSE_NORMAL)
Definition: sys_vars.h:636
const uchar * global_value_ptr(THD *, LEX_STRING *) override
Definition: sys_vars.h:676
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:652
Definition: sys_vars.h:1163
const uchar * session_value_ptr(THD *, THD *target_thd, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:1170
Sys_var_external_user(const char *name_arg, const char *comment_arg, enum charset_enum is_os_charset_arg)
Definition: sys_vars.h:1165
The class for flagset variables - a variant of SET that allows in-place editing (turning on/off indiv...
Definition: sys_vars.h:1521
const uchar * session_value_ptr(THD *running_thd, THD *target_thd, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:1600
bool global_update(THD *, set_var *var) override
Definition: sys_vars.h:1585
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:1581
void global_save_default(THD *, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:1592
const uchar * global_value_ptr(THD *thd, LEX_STRING *) override
Definition: sys_vars.h:1606
bool do_check(THD *thd, set_var *var) override
Definition: sys_vars.h:1542
void session_save_default(THD *, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:1589
Sys_var_flagset(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, const char *values[], ulonglong def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr)
Definition: sys_vars.h:1523
void saved_value_to_string(THD *thd, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:1595
Class for @global.gtid_executed.
Definition: sys_vars.h:2589
const uchar * global_value_ptr(THD *thd, LEX_STRING *) override
Definition: sys_vars.h:2594
Sys_var_gtid_executed(const char *name_arg, const char *comment_arg)
Definition: sys_vars.h:2591
Definition: sys_vars.h:2780
Sys_var_gtid_mode(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=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr)
Definition: sys_vars.h:2782
bool global_update(THD *thd, set_var *var) override
This function shall be called whenever the global scope of gtid_mode var is updated.
Definition: sys_vars.cc:4224
Class for gtid_next.
Definition: sys_vars.h:2399
void global_save_default(THD *, set_var *) override
save the global default value of the variable in var
Definition: sys_vars.h:2428
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.cc:4108
void saved_value_to_string(THD *, set_var *, char *) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:2429
Sys_var_gtid_next(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, const char *def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr, int parse_flag=PARSE_NORMAL)
Definition: sys_vars.h:2401
bool global_update(THD *, set_var *) override
Definition: sys_vars.h:2417
const uchar * global_value_ptr(THD *, LEX_STRING *) override
Definition: sys_vars.h:2447
void session_save_default(THD *, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:2421
const uchar * session_value_ptr(THD *running_thd, THD *target_thd, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:2436
bool do_check(THD *, set_var *) override
Definition: sys_vars.h:2432
bool check_update_type(Item_result type) override
Definition: sys_vars.h:2433
Definition: sys_vars.h:2723
Sys_var_gtid_owned(const char *name_arg, const char *comment_arg)
Definition: sys_vars.h:2725
const uchar * global_value_ptr(THD *thd, LEX_STRING *) override
Definition: sys_vars.h:2766
const uchar * session_value_ptr(THD *running_thd, THD *target_thd, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:2729
Class for @session.gtid_purged.
Definition: sys_vars.h:2640
bool global_update(THD *thd, set_var *var) override
Definition: sys_vars.cc:6469
bool do_check(THD *thd, set_var *var) override
Definition: sys_vars.h:2671
bool check_update_type(Item_result type) override
Definition: sys_vars.h:2689
const uchar * session_value_ptr(THD *, THD *, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:2717
bool session_update(THD *, set_var *) override
Definition: sys_vars.h:2654
void saved_value_to_string(THD *, set_var *var, char *) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:2667
Sys_var_gtid_purged(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t, CMD_LINE getopt, const char *def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr, int parse_flag=PARSE_NORMAL)
Definition: sys_vars.h:2642
void session_save_default(THD *, set_var *) override
save the session default value of the variable in var
Definition: sys_vars.h:2659
const uchar * global_value_ptr(THD *thd, LEX_STRING *) override
Definition: sys_vars.h:2693
void global_save_default(THD *, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:2663
A subclass of Sys_var_have to return dynamic values.
Definition: sys_vars.h:2149
static enum SHOW_COMP_OPTION dummy_
Definition: sys_vars.h:2178
const uchar * global_value_ptr(THD *thd, LEX_STRING *) override
Definition: sys_vars.h:2172
enum SHOW_COMP_OPTION(* func_)(THD *)
Definition: sys_vars.h:2177
Sys_var_have_func(const char *name_arg, const char *comment, enum SHOW_COMP_OPTION(*func)(THD *), const char *substitute=nullptr)
Construct a new variable.
Definition: sys_vars.h:2159
The class for read-only variables that show whether a particular feature is supported by the server.
Definition: sys_vars.h:2096
const uchar * session_value_ptr(THD *, THD *, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:2131
bool global_update(THD *, set_var *) override
Definition: sys_vars.h:2124
const uchar * global_value_ptr(THD *, LEX_STRING *) override
Definition: sys_vars.h:2135
void session_save_default(THD *, set_var *) override
save the session default value of the variable in var
Definition: sys_vars.h:2128
bool check_update_type(Item_result) override
Definition: sys_vars.h:2139
bool do_check(THD *, set_var *) override
Definition: sys_vars.h:2116
void global_save_default(THD *, set_var *) override
save the global default value of the variable in var
Definition: sys_vars.h:2129
bool session_update(THD *, set_var *) override
Definition: sys_vars.h:2120
void saved_value_to_string(THD *, set_var *, char *) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:2130
Sys_var_have(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr, int parse_flag=PARSE_NORMAL)
Definition: sys_vars.h:2098
Sys_var_integer template is used to generate Sys_var_* classes for variables that represent the value...
Definition: sys_vars.h:182
T * max_var_ptr()
Definition: sys_vars.h:313
void global_save_default(THD *, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:300
bool do_check(THD *thd, set_var *var) override
Definition: sys_vars.h:217
Sys_var_integer(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, T min_val, T max_val, T def_val, uint block_size, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr, int parse_flag=PARSE_NORMAL)
Definition: sys_vars.h:184
void session_save_default(THD *thd, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:296
bool check_update_type(Item_result type) override
Definition: sys_vars.h:293
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:285
void saved_value_to_string(THD *, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:303
bool global_update(THD *, set_var *var) override
Definition: sys_vars.h:289
The class for keycache_* variables.
Definition: sys_vars.h:1311
const uchar * global_value_ptr(THD *thd, LEX_STRING *base) override
Definition: sys_vars.h:1367
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, uint block_size, PolyLock *lock, enum binlog_status_enum binlog_status_arg, on_check_function on_check_func, keycache_update_function on_update_func, const char *substitute=nullptr)
Definition: sys_vars.h:1315
bool global_update(THD *thd, set_var *var) override
Definition: sys_vars.h:1334
keycache_update_function keycache_update
Definition: sys_vars.h:1312
The class for string variables.
Definition: sys_vars.h:1190
Sys_var_lexstring(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, enum charset_enum is_os_charset_arg, const char *def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr)
Definition: sys_vars.h:1192
bool global_update(THD *thd, set_var *var) override
Definition: sys_vars.h:1209
The class for the max_user_connections.
Definition: sys_vars.h:1482
Sys_var_max_user_conn(const char *name_arg, const char *comment, int, ptrdiff_t off, size_t size, CMD_LINE getopt, uint min_val, uint max_val, uint def_val, uint block_size, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr)
Definition: sys_vars.h:1484
const uchar * session_value_ptr(THD *running_thd, THD *target_thd, LEX_STRING *base) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:1495
A variant of enum where:
Definition: sys_vars.h:750
uint command_line_no_value
Definition: sys_vars.h:995
const char * command_line_value
Pointer to the value set by the command line (set by the command line parser, copied to the global va...
Definition: sys_vars.h:994
const uint value_count
The number of allowed numeric values.
Definition: sys_vars.h:984
uint alias_count
The number of elements of aliases (computed in the constructor).
Definition: sys_vars.h:988
void global_save_default(THD *, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:955
bool global_update(THD *, set_var *) override
Definition: sys_vars.h:929
const ALIAS * aliases
Array of all textual aliases.
Definition: sys_vars.h:986
bool check_update_type(Item_result type) override
Definition: sys_vars.h:914
const uchar * session_value_ptr(THD *, THD *, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:966
bool session_update(THD *, set_var *) override
Definition: sys_vars.h:917
void session_save_default(THD *, set_var *) override
save the session default value of the variable in var
Definition: sys_vars.h:942
int find_value(const char *text)
Return the numeric value for a given alias string, or -1 if the string is not a valid alias.
Definition: sys_vars.h:835
const char * fixup_command_line(const char *value_str)
Because of limitations in the command-line parsing library, the value given on the command-line canno...
Definition: sys_vars.h:856
bool do_check(THD *, set_var *var) override
Definition: sys_vars.h:886
const uchar * global_value_ptr(THD *, LEX_STRING *) override
Definition: sys_vars.h:977
Sys_var_multi_enum(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, const ALIAS aliases_arg[], uint value_count_arg, uint def_val, uint command_line_no_value_arg, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr, int parse_flag=PARSE_NORMAL)
Enumerated type system variable.
Definition: sys_vars.h:802
void saved_value_to_string(THD *, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:962
The class for variables which value is a plugin.
Definition: sys_vars.h:1722
bool check_update_type(Item_result type) override
Definition: sys_vars.h:1810
bool do_check(THD *thd, set_var *var) override
Definition: sys_vars.h:1743
const uchar * session_value_ptr(THD *running_thd, THD *target_thd, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:1813
void session_save_default(THD *thd, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:1786
void saved_value_to_string(THD *, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:1806
void global_save_default(THD *thd, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:1790
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:1778
void do_update(plugin_ref *valptr, plugin_ref newval)
Definition: sys_vars.h:1771
int plugin_type
Definition: sys_vars.h:1723
bool global_update(THD *, set_var *var) override
Definition: sys_vars.h:1782
const uchar * global_value_ptr(THD *thd, LEX_STRING *) override
Definition: sys_vars.h:1820
Sys_var_plugin(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, int plugin_type_arg, const char **def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr, int parse_flag=PARSE_NORMAL)
Definition: sys_vars.h:1726
Definition: sys_vars.h:1125
void session_save_default(THD *, set_var *) override
save the session default value of the variable in var
Definition: sys_vars.h:1148
bool check_update_type(Item_result) override
Definition: sys_vars.h:1153
bool session_update(THD *, set_var *) override
Definition: sys_vars.h:1140
bool do_check(THD *, set_var *) override
Definition: sys_vars.h:1136
Sys_var_proxy_user(const char *name_arg, const char *comment, enum charset_enum is_os_charset_arg)
Definition: sys_vars.h:1127
bool global_update(THD *, set_var *) override
Definition: sys_vars.h:1144
void global_save_default(THD *, set_var *) override
save the global default value of the variable in var
Definition: sys_vars.h:1149
const uchar * session_value_ptr(THD *, THD *target_thd, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:1156
void saved_value_to_string(THD *, set_var *, char *) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:1150
Similar to Sys_var_session_special, but with double storage.
Definition: sys_vars.h:2037
void global_save_default(THD *, set_var *) override
save the global default value of the variable in var
Definition: sys_vars.h:2071
void session_save_default(THD *, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:2068
session_special_read_double_function read_func
Definition: sys_vars.h:2041
const uchar * session_value_ptr(THD *running_thd, THD *target_thd, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:2075
const uchar * global_value_ptr(THD *, LEX_STRING *) override
Definition: sys_vars.h:2080
double(* session_special_read_double_function)(THD *thd)
Definition: sys_vars.h:2039
session_special_update_function update_func
Definition: sys_vars.h:2042
void saved_value_to_string(THD *, set_var *, char *) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:2072
Sys_var_session_special_double(const char *name_arg, const char *comment, int flag_args, CMD_LINE getopt, double min_val, double max_val, uint, 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_double_function read_func_arg, const char *substitute=nullptr)
Definition: sys_vars.h:2045
bool global_update(THD *, set_var *) override
Definition: sys_vars.h:2064
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:2061
bool(* session_special_update_function)(THD *thd, set_var *var)
Definition: sys_vars.h:2038
The class for variables that have a special meaning for a session, such as @timestamp or @rnd_seed1,...
Definition: sys_vars.h:1984
bool global_update(THD *, set_var *) override
Definition: sys_vars.h:2012
bool(* session_special_update_function)(THD *thd, set_var *var)
Definition: sys_vars.h:1985
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:2009
const uchar * global_value_ptr(THD *, LEX_STRING *) override
Definition: sys_vars.h:2028
void session_save_default(THD *, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:2016
Sys_var_session_special(const char *name_arg, const char *comment, int flag_args, CMD_LINE getopt, ulonglong min_val, ulonglong max_val, uint block_size, 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, const char *substitute=nullptr)
Definition: sys_vars.h:1992
void global_save_default(THD *, set_var *) override
save the global default value of the variable in var
Definition: sys_vars.h:2019
const uchar * session_value_ptr(THD *running_thd, THD *target_thd, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:2023
ulonglong(* session_special_read_function)(THD *thd)
Definition: sys_vars.h:1986
session_special_read_function read_func
Definition: sys_vars.h:1988
session_special_update_function update_func
Definition: sys_vars.h:1989
void saved_value_to_string(THD *, set_var *, char *) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:2020
The class for SET variables - variables taking zero or more values from the given list.
Definition: sys_vars.h:1621
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:1678
bool do_check(THD *, set_var *var) override
Definition: sys_vars.h:1641
const uchar * session_value_ptr(THD *running_thd, THD *target_thd, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:1697
void session_save_default(THD *, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:1686
void global_save_default(THD *, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:1689
void saved_value_to_string(THD *thd, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:1692
bool global_update(THD *, set_var *var) override
Definition: sys_vars.h:1682
const uchar * global_value_ptr(THD *thd, LEX_STRING *) override
Definition: sys_vars.h:1703
Sys_var_set(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, const char *values[], ulonglong def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr)
Definition: sys_vars.h:1623
Generic class for variables for storing entities that are internally represented as structures,...
Definition: sys_vars.h:2195
bool check_update_type(Item_result type) override
Definition: sys_vars.h:2243
void saved_value_to_string(THD *, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:2237
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:2222
Sys_var_struct(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, void *def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr, int parse_flag=PARSE_NORMAL)
Definition: sys_vars.h:2197
void global_save_default(THD *, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:2233
const uchar * session_value_ptr(THD *, THD *target_thd, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:2246
const uchar * global_value_ptr(THD *, LEX_STRING *) override
Definition: sys_vars.h:2251
bool global_update(THD *, set_var *var) override
Definition: sys_vars.h:2226
void session_save_default(THD *, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:2230
bool do_check(THD *, set_var *) override
Definition: sys_vars.h:2221
Class for @global.system_time_zone.
Definition: sys_vars.h:2611
const uchar * global_value_ptr(THD *, LEX_STRING *) override
Definition: sys_vars.h:2618
Sys_var_system_time_zone(const char *name_arg, const char *comment_arg)
Definition: sys_vars.h:2613
The class for test_flags (core_file for now).
Definition: sys_vars.h:1454
const uchar * global_value_ptr(THD *, LEX_STRING *) override
Definition: sys_vars.h:1466
bool test_flag_value
Definition: sys_vars.h:1456
uint test_flag_mask
Definition: sys_vars.h:1457
Sys_var_test_flag(const char *name_arg, const char *comment, uint mask)
Definition: sys_vars.h:1460
Class representing the 'transaction_isolation' system variable.
Definition: sys_vars.h:2344
bool session_update(THD *thd, set_var *var) override
This function sets the session variable thd->variables.transaction_isolation to reflect changes to @s...
Definition: sys_vars.cc:4964
Sys_var_transaction_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)
Definition: sys_vars.h:2346
Class representing the tx_read_only system variable for setting default transaction access mode.
Definition: sys_vars.h:2366
bool session_update(THD *thd, set_var *var) override
This function sets the session variable thd->variables.transaction_read_only to reflect changes to @s...
Definition: sys_vars.cc:5033
Sys_var_transaction_read_only(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size, CMD_LINE getopt, bool def_val, PolyLock *lock, enum binlog_status_enum binlog_status_arg, on_check_function on_check_func)
Definition: sys_vars.h:2368
Helper class for variables that take values from a TYPELIB.
Definition: sys_vars.h:569
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, const char *substitute, int parse_flag=PARSE_NORMAL)
Definition: sys_vars.h:574
bool do_check(THD *, set_var *var) override
Definition: sys_vars.h:592
TYPELIB typelib
Definition: sys_vars.h:571
bool check_update_type(Item_result type) override
Definition: sys_vars.h:615
The class for variables that store time zones.
Definition: sys_vars.h:2267
bool do_check(THD *thd, set_var *var) override
Definition: sys_vars.h:2284
bool session_update(THD *thd, set_var *var) override
Definition: sys_vars.h:2298
void global_save_default(THD *, set_var *var) override
save the global default value of the variable in var
Definition: sys_vars.h:2309
bool check_update_type(Item_result type) override
Definition: sys_vars.h:2333
const uchar * session_value_ptr(THD *, THD *target_thd, LEX_STRING *) override
A pointer to a value of the variable for SHOW.
Definition: sys_vars.h:2315
bool global_update(THD *, set_var *var) override
Definition: sys_vars.h:2302
void session_save_default(THD *, set_var *var) override
save the session default value of the variable in var
Definition: sys_vars.h:2306
Sys_var_tz(const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, size_t size[[maybe_unused]], CMD_LINE getopt, Time_zone **def_val, PolyLock *lock=nullptr, enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG, on_check_function on_check_func=nullptr, on_update_function on_update_func=nullptr, const char *substitute=nullptr, int parse_flag=PARSE_NORMAL)
Definition: sys_vars.h:2269
const uchar * global_value_ptr(THD *, LEX_STRING *) override
Definition: sys_vars.h:2329
void saved_value_to_string(THD *, set_var *var, char *def_val) override
This function converts value stored in save_result to string.
Definition: sys_vars.h:2312
Definition: sys_vars.h:1102
~Sys_var_version() override=default
const uchar * global_value_ptr(THD *thd, LEX_STRING *base) override
Definition: sys_vars.h:1112
Sys_var_version(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)
Definition: sys_vars.h:1104
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:821
Gtid owned_gtid
The GTID of the currently owned transaction.
Definition: sql_class.h:3496
static const int OWNED_SIDNO_GTID_SET
Definition: sql_class.h:3497
rpl_sid owned_sid
For convenience, this contains the SID component of the GTID stored in owned_gtid.
Definition: sql_class.h:3504
double double_value
Definition: sql_class.h:2541
static const int OWNED_SIDNO_ANONYMOUS
Definition: sql_class.h:3498
Session_sysvar_resource_manager session_sysvar_res_mgr
Definition: sql_class.h:4176
const USER_CONN * get_user_connect() const
Definition: sql_class.h:2146
bool bool_value
Definition: sql_class.h:2537
Security_context * security_context() const
Definition: sql_class.h:1134
struct System_variables variables
Definition: sql_class.h:1006
union THD::@151 sys_var_tmp
bool time_zone_used
Definition: sql_class.h:2497
ulonglong ulonglong_value
Definition: sql_class.h:2540
This class represents abstract time zone and provides basic interface for MYSQL_TIME <-> my_time_t co...
Definition: tztime.h:48
virtual const String * get_name() const =0
Because of constness of String returned by get_name() time zone name have to be already zeroended to ...
set_var_base descendant for assignments to the system variables.
Definition: set_var.h:453
ulonglong ulonglong_value
for all integer, set, enum sysvars
Definition: set_var.h:460
LEX_CSTRING base
for structured variables, like keycache_name.variable_name
Definition: set_var.h:468
union set_var::@145 save_result
Time_zone * time_zone
for Sys_var_tz
Definition: set_var.h:463
Item * value
the expression that provides the new value of the variable
Definition: set_var.h:456
sys_var * var
system variable to be updated
Definition: set_var.h:455
LEX_STRING string_value
for Sys_var_charptr and others
Definition: set_var.h:464
enum_var_type type
Definition: set_var.h:457
plugin_ref plugin
for Sys_var_plugin
Definition: set_var.h:462
const void * ptr
for Sys_var_struct
Definition: set_var.h:465
double double_value
for Sys_var_double
Definition: set_var.h:461
Definition: sql_plugin_var.h:195
A class representing one system variable - that is something that can be accessed as @global....
Definition: set_var.h:102
virtual bool global_update(THD *thd, set_var *var)=0
my_option * get_option()
Definition: set_var.h:243
virtual bool set_source_name(const char *path)
Definition: set_var.h:229
my_option option
min, max, default values are stored here
Definition: set_var.h:165
bool(* on_update_function)(sys_var *self, THD *thd, enum_var_type type)
Definition: set_var.h:159
virtual void session_save_default(THD *thd, set_var *var)=0
save the session default value of the variable in var
LEX_CSTRING name
Definition: set_var.h:105
virtual void set_arg_source(get_opt_arg_source *)
Definition: set_var.h:222
virtual ulonglong get_max_value()
Definition: set_var.h:215
virtual void set_user_host(THD *thd)
Definition: set_var.cc:419
uchar * global_var_ptr()
Definition: set_var.cc:367
virtual const uchar * global_value_ptr(THD *thd, LEX_STRING *base)
Definition: set_var.cc:359
enum sys_var::binlog_status_enum binlog_status
uchar * session_var_ptr(THD *thd)
A pointer to a storage area of the variable, to the raw data.
Definition: set_var.cc:363
flag_enum
Definition: set_var.h:123
@ SESSION
Definition: set_var.h:125
@ GLOBAL
Definition: set_var.h:124
@ READONLY
Definition: set_var.h:128
@ ALLOCATED
Definition: set_var.h:129
@ NOTPERSIST
Definition: set_var.h:132
@ PERSIST_AS_READ_ONLY
There can be some variables which needs to be set before plugin is loaded.
Definition: set_var.h:143
@ ONLY_SESSION
Definition: set_var.h:126
virtual bool do_check(THD *thd, set_var *var)=0
virtual bool check_update_type(Item_result type)=0
virtual void cleanup()
All the cleanup procedures should be performed here.
Definition: set_var.h:199
virtual longlong get_min_value()
Definition: set_var.h:214
virtual const char * get_host()
Definition: set_var.h:237
virtual void set_is_plugin(bool)
Definition: set_var.h:223
binlog_status_enum
Enumeration type to indicate for a system variable whether it will be written to the binlog or not.
Definition: set_var.h:151
@ VARIABLE_NOT_IN_BINLOG
Definition: set_var.h:152
virtual void saved_value_to_string(THD *thd, set_var *var, char *def_val)=0
This function converts value stored in save_result to string.
bool is_os_charset
true if the value is in character_set_filesystem
Definition: set_var.h:176
ptrdiff_t offset
offset to the value from global_system_variables
Definition: set_var.h:167
virtual bool set_user(const char *usr)
Definition: set_var.h:233
bool(* on_check_function)(sys_var *self, THD *thd, set_var *var)
Definition: set_var.h:157
virtual enum_variable_source get_source()
Definition: set_var.h:224
virtual sys_var_pluginvar * cast_pluginvar()
downcast for sys_var_pluginvar.
Definition: set_var.h:204
virtual void global_save_default(THD *thd, set_var *var)=0
save the global default value of the variable in var
virtual const char * get_user()
Definition: set_var.h:236
on_check_function on_check
Definition: set_var.h:168
const CHARSET_INFO * charset(THD *thd)
Definition: set_var.cc:555
virtual ulong get_var_type()
Returns variable type.
Definition: set_var.h:221
pre_update_function pre_update
Pointer to function to be invoked before updating system variable (but after calling on_check hook),...
Definition: set_var.h:173
virtual const uchar * session_value_ptr(THD *running_thd, THD *target_thd, LEX_STRING *base)
A pointer to a value of the variable for SHOW.
Definition: set_var.cc:355
int scope() const
Definition: set_var.h:264
virtual void set_timestamp()
Definition: set_var.h:244
const SHOW_TYPE show_val_type
what value_ptr() returns for sql_show.cc
Definition: set_var.h:164
on_update_function on_update
Definition: set_var.h:174
int flags
or'ed flag_enum values
Definition: set_var.h:162
static const int PARSE_NORMAL
Definition: set_var.h:146
virtual const char * get_source_name()
Definition: set_var.h:225
virtual void update_default(longlong new_def_value)
Definition: set_var.h:210
virtual bool set_host(const char *hst)
Definition: set_var.h:238
PolyLock * guard
second lock that protects the variable
Definition: set_var.h:166
virtual longlong get_default()
Definition: set_var.h:213
virtual bool is_non_persistent()
Definition: set_var.h:246
const char *const deprecation_substitute
Definition: set_var.h:175
virtual ulonglong get_timestamp() const
Definition: set_var.h:241
bool(* pre_update_function)(sys_var *self, THD *thd, set_var *var)
Definition: set_var.h:158
bool is_readonly() const
Definition: set_var.h:266
virtual bool session_update(THD *thd, set_var *var)=0
int m_parse_flag
either PARSE_EARLY or PARSE_NORMAL.
Definition: set_var.h:163
virtual void set_source(enum_variable_source src)
Definition: set_var.h:226
Declarations for the Debug Sync Facility.
Dialog Client Authentication nullptr
Definition: dialog.cc:352
DBUG_TRACE
Definition: do_ctype.cc:46
#define base_name(A)
Definition: my_sys.h:705
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:215
#define MYSQL_STORAGE_ENGINE_PLUGIN
Definition: plugin.h:113
Key cache variable structures.
KEY_CACHE * dflt_key_cache
Definition: keycache.h:132
KEY_CACHE * get_key_cache(const LEX_CSTRING *cache_name)
Definition: keycaches.cc:67
LEX_CSTRING default_key_cache_base
Definition: keycaches.cc:62
KEY_CACHE * create_key_cache(const char *name, size_t length)
Definition: keycaches.cc:73
KEY_CACHE zero_key_cache
@nonexistent_cache.param->value_ptr() points here
Definition: keycaches.cc:65
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:48
#define comment
Definition: lexyy.cc:959
A better implementation of the UNIX ctype(3) library.
MYSQL_PLUGIN_IMPORT CHARSET_INFO * system_charset_info
Definition: mysqld.cc:1512
#define my_strcasecmp(s, a, b)
Definition: m_ctype.h:677
MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_latin1
Definition: ctype-latin1.cc:367
char * longlong10_to_str(int64_t val, char *dst, int radix)
Converts a 64-bit integer to its string representation in decimal notation.
Definition: int2str.cc:100
size_t my_fcvt(double x, int precision, char *to, bool *error)
Converts a given floating point number to a zero-terminated string representation using the 'f' forma...
Definition: dtoa.cc:203
static mi_bit_type mask[]
Definition: mi_packrec.cc:140
This file includes constants used by all storage engines.
Some useful bit functions.
static uint my_count_bits(ulonglong v)
Definition: my_bit.h:53
Header for compiler-dependent features.
#define DBUG_SET_INITIAL(a1)
Definition: my_dbug.h:179
#define DBUG_EXECUTE_IF(keyword, a1)
Definition: my_dbug.h:158
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:168
#define DBUG_EXPLAIN(buf, len)
Definition: my_dbug.h:186
#define DBUG_SET(a1)
Definition: my_dbug.h:178
#define DBUG_EXPLAIN_INITIAL(buf, len)
Definition: my_dbug.h:187
#define DBUG_POP()
Definition: my_dbug.h:177
#define GET_NO_ARG
Definition: my_getopt.h:41
get_opt_arg_type
Enumeration of the my_option::arg_type attributes.
Definition: my_getopt.h:78
@ OPT_ARG
Definition: my_getopt.h:78
@ NO_ARG
Definition: my_getopt.h:78
#define GET_STR
Definition: my_getopt.h:49
#define GET_DOUBLE
Definition: my_getopt.h:54
ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp, bool *fix)
Definition: my_getopt.cc:1177
#define GET_SET
Definition: my_getopt.h:53
#define GET_ENUM
Definition: my_getopt.h:52
#define GET_FLAGSET
Definition: my_getopt.h:55
#define GET_STR_ALLOC
Definition: my_getopt.h:50
double getopt_double_limit_value(double num, const struct my_option *optp, bool *fix)
Definition: my_getopt.cc:1217
double getopt_ulonglong2double(ulonglong)
Returns the double value which corresponds to the given raw representation.
Definition: my_getopt.cc:165
ulonglong max_of_int_range(int var_type)
Maximum possible value for an integer GET_* variable type.
Definition: my_getopt.cc:1083
#define GET_ASK_ADDR
Definition: my_getopt.h:68
#define GET_BOOL
Definition: my_getopt.h:42
longlong getopt_ll_limit_value(longlong, const struct my_option *, bool *fix)
Definition: my_getopt.cc:1110
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
unsigned char uchar
Definition: my_inttypes.h:51
intptr_t intptr
Definition: my_inttypes.h:69
long long int longlong
Definition: my_inttypes.h:54
#define MYF(v)
Definition: my_inttypes.h:96
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:80
Common header for many mysys elements.
time_t my_time(int)
Return current time.
Definition: my_systime.h:172
Sid_map * global_sid_map
Definition: mysqld.cc:1789
uint test_flags
Definition: mysqld.cc:1298
const char * show_comp_option_name[]
Definition: mysqld.cc:1014
char system_time_zone_dst_off[30]
Definition: mysqld.cc:1442
bool opt_bin_log
Definition: mysqld.cc:1157
Gtid_state * gtid_state
Global state of GTIDs.
Definition: mysqld.cc:1790
Checkable_rwlock * global_sid_lock
Protects Gtid_state. See comment above gtid_state for details.
Definition: mysqld.cc:1788
struct System_variables max_system_variables
Definition: mysqld.cc:1507
char system_time_zone_dst_on[30]
Definition: mysqld.cc:1442
static char * path
Definition: mysqldump.cc:130
arg_type
Definition: mysqltest.cc:1138
int find_set(REP_SETS *sets, REP_SET *find)
Definition: mysqltest.cc:11145
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1056
Definition: buf0block_hint.cc:29
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:908
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:78
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:191
ulonglong getopt_double2ulonglong(double v)
Returns an ulonglong value containing a raw representation of the given double value.
Definition: my_getopt.cc:154
const string value("\"Value\"")
required string type
Definition: replication_group_member_actions.proto:33
bool throw_bounds_warning(THD *thd, const char *name, bool fixed, bool is_unsigned, longlong v)
Throw warning (error in STRICT mode) if value for variable needed bounding.
Definition: set_var.cc:516
"public" interface to sys_var - server configuration variables.
enum enum_mysql_show_type SHOW_TYPE
Definition: set_var.h:68
@ OPT_GLOBAL
Definition: set_var.h:90
plugin_ref ha_resolve_by_name(THD *thd, const LEX_CSTRING *name, bool is_temp_table)
Return the storage engine handlerton for the supplied name.
Definition: handler.cc:400
File containing constants that can be used throughout the server.
SHOW_COMP_OPTION
Definition: sql_const.h:375
#define MAX_TIME_ZONE_NAME_LENGTH
Maximum length of time zone name that we support (Time zone name is char(64) in db).
Definition: sql_const.h:280
#define STRING_BUFFER_USUAL_SIZE
Definition: sql_const.h:126
void push_warning_printf(THD *thd, Sql_condition::enum_severity_level severity, uint code, const char *format,...)
Push the warning to error list if there is still room in the list.
Definition: sql_error.cc:680
void plugin_unlock(THD *thd, plugin_ref plugin)
Definition: sql_plugin.cc:1244
#define my_plugin_lock_by_name(A, B, C)
Definition: sql_plugin.h:173
#define my_plugin_lock(A, B)
Definition: sql_plugin.h:175
LEX_CSTRING * plugin_name(st_plugin_int **ref)
Definition: sql_plugin_ref.h:94
Our own string classes, used pervasively throughout the executor.
LEX_CSTRING to_lex_cstring(const LEX_STRING &s)
Definition: sql_string.h:647
bool validate_string(const CHARSET_INFO *cs, const char *str, size_t length, size_t *valid_length, bool *length_error)
Check if an input byte sequence is a valid character string of a given charset.
Definition: sql_string.cc:1164
@ SHOW_DOUBLE
Definition: status_var.h:39
@ SHOW_CHAR_PTR
Definition: status_var.h:36
@ SHOW_MY_BOOL
Definition: status_var.h:49
@ SHOW_CHAR
Definition: status_var.h:35
@ SHOW_LEX_STRING
Definition: status_var.h:54
char * set_to_string(THD *thd, LEX_STRING *result, ulonglong set, const char *lib[], bool quoted)
Definition: strfunc.cc:269
char * flagset_to_string(THD *thd, LEX_STRING *result, ulonglong set, const char *lib[])
Definition: strfunc.cc:302
A small wrapper class to pass getopt arguments as a pair to the Sys_var_* constructors.
Definition: sys_vars.h:160
int id
Definition: sys_vars.h:161
CMD_LINE(enum get_opt_arg_type getopt_arg_type, int getopt_id=0)
Definition: sys_vars.h:163
enum get_opt_arg_type arg_type
Definition: sys_vars.h:162
Holds information about a Gtid_set.
Definition: rpl_gtid.h:2350
Gtid_set * get_gtid_set() const
Return NULL if this is NULL, otherwise return the Gtid_set.
Definition: rpl_gtid.h:2356
This struct represents a specification of a GTID for a statement to be executed: either "AUTOMATIC",...
Definition: rpl_gtid.h:3765
static const int MAX_TEXT_LENGTH
Definition: rpl_gtid.h:3816
static const int MAX_TEXT_LENGTH
The maximal length of the textual representation of a SID, not including the terminating '\0'.
Definition: rpl_gtid.h:1082
rpl_sidno sidno
SIDNO of this Gtid.
Definition: rpl_gtid.h:1049
int to_string(const rpl_sid &sid, char *buf) const
Convert a Gtid to a string.
Definition: rpl_gtid_misc.cc:117
Definition: keycache.h:70
bool in_init
Definition: keycache.h:128
Definition: mysql_lex_string.h:39
const char * str
Definition: mysql_lex_string.h:40
size_t length
Definition: mysql_lex_string.h:41
Definition: mysql_lex_string.h:34
char * str
Definition: mysql_lex_string.h:35
size_t length
Definition: mysql_lex_string.h:36
Definition: sys_vars.h:752
uint number
Definition: sys_vars.h:754
const char * alias
Definition: sys_vars.h:753
Definition: system_variables.h:178
Definition: typelib.h:34
const char ** type_names
Definition: typelib.h:37
size_t count
Definition: typelib.h:35
const char * name
Definition: typelib.h:36
unsigned int * type_lengths
Definition: typelib.h:38
Definition: my_getopt.h:80
const char * comment
option comment, for autom.
Definition: my_getopt.h:110
longlong min_value
Min allowed value (for numbers)
Definition: my_getopt.h:120
ulonglong max_value
Max allowed value (for numbers)
Definition: my_getopt.h:121
longlong def_value
Default value.
Definition: my_getopt.h:119
long block_size
Value should be a mult.
Definition: my_getopt.h:124
const char * name
Name of the option.
Definition: my_getopt.h:91
void * u_max_value
The user def.
Definition: my_getopt.h:115
ulong var_type
GET_BOOL, GET_ULL, etc.
Definition: my_getopt.h:117
TYPELIB * typelib
Pointer to possible values.
Definition: my_getopt.h:116
void * value
A pointer to the variable value.
Definition: my_getopt.h:114
Definition: sql_plugin_ref.h:44
Definition: set_var.h:79
Definition: sql_connect.h:69
USER_RESOURCES user_resources
Definition: sql_connect.h:94
uint user_conn
Definition: sql_connect.h:51
#define NO_CMD_LINE
Definition: sys_vars.h:114
Sys_var_integer< ulong, GET_ULONG, SHOW_LONG, false > Sys_var_ulong
Definition: sys_vars.h:323
#define keycache_var_ptr(KC, OFF)
Definition: sys_vars.h:1295
#define keycache_var(KC, OFF)
Definition: sys_vars.h:1296
charset_enum
Definition: sys_vars.h:149
@ IN_SYSTEM_CHARSET
Definition: sys_vars.h:149
@ IN_FS_CHARSET
Definition: sys_vars.h:149
#define NON_PERSIST
Definition: sys_vars.h:132
#define MAX_SET(X)
Definition: sys_vars.h:1505
Sys_var_integer< uint, GET_UINT, SHOW_INT, false > Sys_var_uint
Definition: sys_vars.h:322
sys_var_chain all_sys_vars
Definition: set_var.cc:114
Sys_var_integer< int32, GET_UINT, SHOW_INT, false > Sys_var_int32
Definition: sys_vars.h:321
#define session_var(THD, TYPE)
Definition: sys_vars.h:142
Sys_var_integer< long, GET_LONG, SHOW_SIGNED_LONG, true > Sys_var_long
Definition: sys_vars.h:328
#define GLOBAL_VAR(X)
Definition: sys_vars.h:105
bool(* keycache_update_function)(THD *, KEY_CACHE *, ptrdiff_t, ulonglong)
Definition: sys_vars.h:1297
static const char * bool_values[3]
Definition: sys_vars.h:151
#define global_var(TYPE)
Definition: sys_vars.h:143
const char * fixup_enforce_gtid_consistency_command_line(char *value_arg)
Definition: sys_vars.cc:6317
Sys_var_integer< ha_rows, GET_HA_ROWS, SHOW_HA_ROWS, false > Sys_var_harows
Definition: sys_vars.h:325
Sys_var_integer< ulonglong, GET_ULL, SHOW_LONGLONG, false > Sys_var_ulonglong
Definition: sys_vars.h:327
#define READ_ONLY
Definition: sys_vars.h:126
"protected" interface to sys_var - server configuration variables.
enum_variable_source
This enum values define how system variables are set.
Definition: system_variable_source_type.h:32
Include file for Sun RPC to compile out of the box.
int find_type(const char *x, const TYPELIB *typelib, unsigned int flags)
Search after a string in a list of strings.
Definition: typelib.cc:86
uint64_t find_set_from_flags(const TYPELIB *lib, int default_name, uint64_t cur_set, uint64_t default_set, const char *str, unsigned int length, const char **err_pos, unsigned int *err_len)
Parse and apply a set of flag assingments.
Definition: typelib.cc:297
#define NULL
Definition: types.h:54
Time_zone * my_tz_find(const int64 displacement)
static const char * pname[]
Definition: uca-dump.cc:275
unsigned int uint
Definition: uca-dump.cc:29
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:38
@ STRING_RESULT
not valid for UDFs
Definition: udf_registration_types.h:40
@ DECIMAL_RESULT
not valid for UDFs
Definition: udf_registration_types.h:44
@ REAL_RESULT
char *
Definition: udf_registration_types.h:41
@ INT_RESULT
double
Definition: udf_registration_types.h:42
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:506