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