MySQL 8.0.40
Source Code Documentation
set_var.h
Go to the documentation of this file.
1#ifndef SET_VAR_INCLUDED
2#define SET_VAR_INCLUDED
3/* Copyright (c) 2002, 2024, 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 designed to work 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 either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26/**
27 @file
28 "public" interface to sys_var - server configuration variables.
29*/
30
31#include "my_config.h"
32
33#include <sys/types.h>
34
35#include <cstddef>
36#include <cstring>
37#include <functional>
38#include <optional>
39#include <string>
40#include <string_view>
41#include <vector>
42
43#include "lex_string.h"
44#include "m_ctype.h"
45#include "my_getopt.h" // get_opt_arg_type
46#include "my_hostname.h" // HOSTNAME_LENGTH
47#include "my_inttypes.h"
48#include "my_sys.h"
49#include "my_systime.h" // my_micro_time()
51#include "mysql/status_var.h"
53#include "mysql_com.h" // Item_result
54#include "prealloced_array.h" // Prealloced_array
55#include "sql/sql_const.h" // SHOW_COMP_OPTION
56#include "sql/sql_plugin_ref.h" // plugin_ref
57#include "typelib.h" // TYPELIB
58
59class Item;
61class PolyLock;
62class String;
63class THD;
64class Time_zone;
65class set_var;
66class sys_var;
68struct LEX_USER;
69template <class Key, class Value>
71
75template <class T>
76class List;
77
79
83};
84
86
89
90enum enum_var_type : int {
96};
97
98/**
99 A class representing one system variable - that is something
100 that can be accessed as @@global.variable_name or @@session.variable_name,
101 visible in SHOW xxx VARIABLES and in INFORMATION_SCHEMA.xxx_VARIABLES,
102 optionally it can be assigned to, optionally it can have a command-line
103 counterpart with the same name.
104*/
105class sys_var {
106 public:
109 /**
110 If the variable has an alias in the persisted variables file, this
111 should point to it. This has the following consequences:
112 - A SET PERSIST statement that sets either of the variables will
113 persist both variables in the file.
114 - When loading persisted variables, an occurrence of any one of
115 the variables will initialize both variables.
116 */
118 /**
119 If m_persist_alias is set, and the current variable is deprecated
120 and m_persist_alias is the recommended substitute, then this flag
121 should be set to true. This has the consequence that the code
122 that loads persisted variables will generate a warning if it
123 encounters this variable but does not encounter the alias.
124 */
127 GLOBAL = 0x0001,
128 SESSION = 0x0002,
129 ONLY_SESSION = 0x0004,
130 SCOPE_MASK = 0x03FF, // 1023
131 READONLY = 0x0400, // 1024
132 ALLOCATED = 0x0800, // 2048
133 INVISIBLE = 0x1000, // 4096
134 TRI_LEVEL = 0x2000, // 8192 - default is neither GLOBAL nor SESSION
135 NOTPERSIST = 0x4000,
136 HINT_UPDATEABLE = 0x8000, // Variable is updateable using SET_VAR hint
137 /**
138 There can be some variables which needs to be set before plugin is loaded.
139 ex: binlog_checksum needs to be set before GR plugin is loaded.
140 Also, there are some variables which needs to be set before some server
141 internal component initialization.
142 ex: binlog_encryption needs to be set before binary and relay log
143 files generation.
144 */
145
147 /**
148 Sensitive variable. If keyring is available, the variable will be
149 persisted in mysqld-auto.cnf in encrypted format
150 */
151 SENSITIVE = 0x20000
152 };
153 static const int PARSE_EARLY = 1;
154 static const int PARSE_NORMAL = 2;
155 /**
156 Enumeration type to indicate for a system variable whether
157 it will be written to the binlog or not.
158 */
163
164 protected:
165 typedef bool (*on_check_function)(sys_var *self, THD *thd, set_var *var);
166 typedef bool (*pre_update_function)(sys_var *self, THD *thd, set_var *var);
167 typedef bool (*on_update_function)(sys_var *self, THD *thd,
169
170 int flags; ///< or'ed flag_enum values
171 int m_parse_flag; ///< either PARSE_EARLY or PARSE_NORMAL.
172 const SHOW_TYPE show_val_type; ///< what value_ptr() returns for sql_show.cc
173 my_option option; ///< min, max, default values are stored here
174 PolyLock *guard; ///< *second* lock that protects the variable
175 ptrdiff_t offset; ///< offset to the value from global_system_variables
177 /**
178 Pointer to function to be invoked before updating system variable (but
179 after calling on_check hook), while we do not hold any locks yet.
180 */
183 const char *const deprecation_substitute;
184 bool is_os_charset; ///< true if the value is in character_set_filesystem
186 char user[USERNAME_CHAR_LENGTH + 1]; /* which user has set this variable */
187 char host[HOSTNAME_LENGTH + 1]; /* host on which this variable is set */
188 ulonglong timestamp; /* represents when this variable was set */
189
190 public:
191 sys_var(sys_var_chain *chain, const char *name_arg, const char *comment,
192 int flag_args, ptrdiff_t off, int getopt_id,
193 enum get_opt_arg_type getopt_arg_type, SHOW_TYPE show_val_type_arg,
194 longlong def_val, PolyLock *lock,
195 enum binlog_status_enum binlog_status_arg,
196 on_check_function on_check_func, on_update_function on_update_func,
197 const char *substitute, int parse_flag,
198 sys_var *persisted_alias = nullptr,
199 bool is_persisted_deprecated = false);
200
201 virtual ~sys_var() = default;
202
204 /**
205 All the cleanup procedures should be performed here
206 */
207 virtual void cleanup() {}
208 /**
209 downcast for sys_var_pluginvar. Returns this if it's an instance
210 of sys_var_pluginvar, and 0 otherwise.
211 */
212 virtual sys_var_pluginvar *cast_pluginvar() { return nullptr; }
213
214 bool check(THD *thd, set_var *var);
215 const uchar *value_ptr(THD *running_thd, THD *target_thd, enum_var_type type,
216 std::string_view keycache_name);
217 const uchar *value_ptr(THD *thd, enum_var_type type,
218 std::string_view keycache_name);
219 virtual void update_default(longlong new_def_value) {
220 option.def_value = new_def_value;
221 }
222 virtual longlong get_default() { return option.def_value; }
225 /**
226 Returns variable type.
227
228 @return variable type
229 */
230 virtual ulong get_var_type() { return (option.var_type & GET_TYPE_MASK); }
232 virtual void set_is_plugin(bool) {}
234 virtual const char *get_source_name() { return source.m_path_name; }
237 }
238 virtual bool set_source_name(const char *path) {
240 sizeof(option.arg_source->m_path_name));
241 }
242 virtual bool set_user(const char *usr) {
243 return set_and_truncate(user, usr, sizeof(user));
244 }
245 virtual const char *get_user() { return user; }
246 virtual const char *get_host() { return host; }
247 virtual bool set_host(const char *hst) {
248 return set_and_truncate(host, hst, sizeof(host));
249 }
250 virtual ulonglong get_timestamp() const { return timestamp; }
251 virtual void set_user_host(THD *thd);
253 virtual void set_timestamp() { timestamp = my_micro_time(); }
254 virtual void set_timestamp(ulonglong ts) { timestamp = ts; }
255 virtual bool is_non_persistent() { return flags & NOTPERSIST; }
256
257 /**
258 Update the system variable with the default value from either
259 session or global scope. The default value is stored in the
260 'var' argument. Return false when successful.
261 */
262 bool set_default(THD *thd, set_var *var);
263 bool update(THD *thd, set_var *var);
264
265 /**
266 This function converts value stored in save_result to string. This
267 function must be called after calling save_default() as save_default() will
268 store default value to save_result.
269 */
270 virtual void saved_value_to_string(THD *thd, set_var *var, char *def_val) = 0;
271
273 int scope() const { return flags & SCOPE_MASK; }
274 const CHARSET_INFO *charset(THD *thd);
275 bool is_readonly() const { return flags & READONLY; }
276 bool not_visible() const { return flags & INVISIBLE; }
277 bool is_trilevel() const { return flags & TRI_LEVEL; }
279 bool is_parse_early() const { return (m_parse_flag == PARSE_EARLY); }
280 bool is_sensitive() const { return flags & SENSITIVE; }
281 /**
282 Check if the variable can be set using SET_VAR hint.
283
284 @return true if the variable can be set using SET_VAR hint,
285 false otherwise.
286 */
287 bool is_hint_updateable() const { return flags & HINT_UPDATEABLE; }
288 /**
289 the following is only true for keycache variables,
290 that support the syntax @@keycache_name.variable_name
291 */
293 /*
294 Indicates whether this system variable is written to the binlog or not.
295
296 Variables are written to the binlog as part of "status_vars" in
297 Query_log_event, as an Intvar_log_event, or a Rand_log_event.
298
299 @return true if the variable is written to the binlog, false otherwise.
300 */
303 }
305
306 /**
307 Return true for success if:
308 Global query and variable scope is GLOBAL or SESSION, or
309 Session query and variable scope is SESSION or ONLY_SESSION.
310 */
311 bool check_scope(enum_var_type query_type) {
312 switch (query_type) {
313 case OPT_PERSIST:
314 case OPT_PERSIST_ONLY:
315 case OPT_GLOBAL:
316 return scope() & (GLOBAL | SESSION);
317 case OPT_SESSION:
318 return scope() & (SESSION | ONLY_SESSION);
319 case OPT_DEFAULT:
320 return scope() & (SESSION | ONLY_SESSION);
321 }
322 return false;
323 }
325 return (type == OPT_GLOBAL || type == OPT_PERSIST ||
327 }
328
329 /**
330 Return true if settable at the command line
331 */
332 bool is_settable_at_command_line() { return option.id != -1; }
333
334 bool register_option(std::vector<my_option> *array, int parse_flags) {
335 return is_settable_at_command_line() && (m_parse_flag & parse_flags) &&
336 (array->push_back(option), false);
337 }
338 void do_deprecated_warning(THD *thd);
339 /**
340 Create item from system variable value.
341
342 @param thd pointer to THD object
343
344 @return pointer to Item object or NULL if it's
345 impossible to obtain the value.
346 */
347 Item *copy_value(THD *thd);
348
349 void save_default(THD *thd, set_var *var) { global_save_default(thd, var); }
350
351 bool check_if_sensitive_in_context(THD *, bool suppress_errors = true) const;
352
353 private:
354 /**
355 Like strncpy, but ensures the destination is '\0'-terminated. Is
356 also safe to call if dst==string (but not if they overlap in any
357 other way).
358
359 @param dst Target string
360 @param string Source string
361 @param sizeof_dst Size of the dst buffer
362 @retval false The entire string was copied to dst
363 @retval true strlen(string) was bigger than or equal to sizeof_dst, so
364 dst contains only the sizeof_dst-1 first characters of string.
365 */
366 inline static bool set_and_truncate(char *dst, const char *string,
367 size_t sizeof_dst) {
368 if (dst == string) return false;
369 size_t string_length = strlen(string), length;
370 length = std::min(sizeof_dst - 1, string_length);
371 memcpy(dst, string, length);
372 dst[length] = 0;
373 return length < string_length; // truncated
374 }
375
376 private:
377 virtual bool do_check(THD *thd, set_var *var) = 0;
378 /**
379 save the session default value of the variable in var
380 */
381 virtual void session_save_default(THD *thd, set_var *var) = 0;
382 /**
383 save the global default value of the variable in var
384 */
385 virtual void global_save_default(THD *thd, set_var *var) = 0;
386 virtual bool session_update(THD *thd, set_var *var) = 0;
387 virtual bool global_update(THD *thd, set_var *var) = 0;
388
389 protected:
390 /**
391 A pointer to a value of the variable for SHOW.
392 It must be of show_val_type type (bool for SHOW_BOOL, int for SHOW_INT,
393 longlong for SHOW_LONGLONG, etc).
394 */
395 virtual const uchar *session_value_ptr(THD *running_thd, THD *target_thd,
396 std::string_view keycache_name);
397 virtual const uchar *global_value_ptr(THD *thd,
398 std::string_view keycache_name);
399
400 /**
401 A pointer to a storage area of the variable, to the raw data.
402 Typically it's the same as session_value_ptr(), but it's different,
403 for example, for ENUM, that is printed as a string, but stored as a number.
404 */
406
408
409 friend class Sys_var_alias;
410};
411
413
415
416enum class Is_already_locked { NO, YES };
417
418enum class Is_single_thread { NO, YES };
419
420/**
421 Wrapper interface for all kinds of system variables.
422
423 The interface encapsulates parse- and execution-time resolvers for all kinds
424 of sys_var:
425 * regular (static) system variables
426 * MyISAM Multiple Key Cache variables
427 * plugin-registered variables
428 * component-registered variables
429*/
430/*
431 There are 4 different sorts of system variables in MySQL:
432
433 1. Static system variables.
434
435 2. MyISAM Multiple Key Cache variables A.K.A. "Structured Variables" (the
436 latest is easy to confuse with component-registered variables, so here
437 and below the "Multiple Key Cache variable" or just "key cache variable"
438 name is preferred.
439
440 3. Plugin-registered variables.
441
442 4. Component-registered variables.
443
444 While they share the same internals/data structures for resolving them by
445 name, they have different naming conventions, lifetimes, and lock policies
446 at the same time.
447
448
449 How to differentiate sorts of system variables by their syntax in SQL
450 ---------------------------------------------------------------------
451
452 Common note: the "@@" prefix is optional in lvalue syntax (left-hand sides of
453 assignments in the SET statement) and mandatory in rvalue syntax (query
454 blocks).
455
456 1. Static system variable names have the simplest syntax:
457
458 ["@@"][<scope> "."]<name>
459
460 where <scope> ::= SESSION | LOCAL | GLOBAL | PERSIST | PERSIST_ONLY
461
462 Thus, static system variable names can be confused with plugin-registered
463 variables names or reduced forms of key cache variable names.
464
465 2. Key cache variables can have either simple (reduced) or structured syntax:
466
467 structured:
468
469 ["@@"][<scope> "."][<cache-name> | DEFAULT "."]<cache-variable>
470
471 simple (reduced):
472
473 ["@@"][<scope> "."]<cache-variable>
474
475 where <scope> ::= GLOBAL | PERSIST | PERSIST_ONLY
476
477 and <cache-variable> ::= key_buffer_size |
478 key_cache_block_size |
479 key_cache_division_limit |
480 key_cache_age_threshold
481
482 Semantically, a name of the reduced form "cache_name_foo" is equivalent to
483 the structured name "DEFAULT.cache_name_foo".
484
485 Thus, key cache variable names of the simple form can be confused with
486 static system variable names while names of the structured form can be
487 confused with component-registered variable names.
488
489 3. Plugin-registered variables have almost same simple syntax as static
490 system variables:
491
492 ["@@"][<scope> "."]<name>
493
494 where <scope> ::= GLOBAL | PERSIST | PERSIST_ONLY
495
496 4. Component-registered variable name syntax reminds the structured syntax
497 of key cache variables:
498
499 ["@@"][<scope> "."]<component-name> "." <variable-name>
500
501 where <scope> ::= GLOBAL | PERSIST | PERSIST_ONLY
502
503 Note on overlapping names:
504
505 Component-registered and key cache variable names have a similar structured
506 syntax (dot-separated).
507 Plugin-registered and static system have similar syntax too (plain
508 identifiers).
509 To manage name conflicts, the server rejects registration of
510 plugin-registered variable names coinciding with compiled-in names
511 of static system variables.
512 OTOH, the server silently accepts component-registered variable names like
513 key_buffer_size etc. (conflict with qualified key cache variables), so
514 those newly-registered variables won't be easily accessible via SQL.
515
516
517 API
518 ---
519
520 All 4 sorts of system variables share the same interface: sys_var.
521
522 See following paragraph "Lifetime" for API return value lifetime details.
523
524 Common note about using variable names as API parameter:
525 the search key is
526
527 * case-insensitive
528 * doesn't include the "@@" prefix
529 * doesn't include a scope prefix
530
531
532 Lifetimes
533 ---------
534
535 1. Static system variable definitions are compiled into the server binary
536 and have a runtime-wide life time, so pointers to their sys_var objects
537 are stable.
538
539 2. While key cache variables are dynamic by their nature, their sys_var
540 object pointers are stable, since all key caches (including DEFAULT) do
541 share 4 always existing sys_var objects. So, pointers to key cache
542 sys_var objects are as stable as pointers to sys_var objects of static
543 system variables.
544
545 3. Plugin-registered variables can be unregistered by the UNINSTALL PLUGIN
546 statement any time, so pointers to their sys_var objects are unstable
547 between references to them. To make sys_var pointers stable
548 during a single query execution, the plugin library maintains:
549
550 * internally: a reference counting
551 * in the outer world: the LEX::plugins release list.
552
553 4. Component-registered variables can be unregistered by the UNINSTALL
554 COMPONENT statement any time, so pointers to their sys_var objects are
555 unstable.
556
557
558 Locking internals
559 -----------------
560
561 1. Static system variables and key cache variables don't need/cause a lock on
562 LOCK_system_variables_hash for resolving their sys_var objects since they
563 use a separate stable dictionary: static_system_variable_hash.
564
565 2. Both plugin-registered and component-registered variables share the same
566 dynamic_system_variable_hash dictionary, and, normally, both need to lock
567 LOCK_system_variables_hash while resolving their sys_var objects and
568 accessing variable data.
569*/
570
571/**
572 Encapsulation of system variable resolving and data accessing tasks.
573*/
575 struct Static {};
576 struct Keycache {};
577 struct Plugin {};
578 struct Component {};
579
581
582 System_variable_tracker(Keycache, std::string_view cache_name, sys_var *var);
583
584 System_variable_tracker(Plugin, std::string_view name);
585
586 System_variable_tracker(Component, std::string_view dot_separated_name);
587 System_variable_tracker(Component, std::string_view component_name,
588 std::string_view variable_name);
589
590 public:
591 enum Lifetime {
592 STATIC, ///< for regular static variables
593 KEYCACHE, ///< for MyISAM Multiple Key Cache variables
594 PLUGIN, ///< for plugin-registered system variables
595 COMPONENT, ///< for component-registered variables
596 };
597
599
601
603
604 /**
605 Static "constructor"
606
607 @note This function requires no locks and allocates nothing on memory heaps.
608
609 @param prefix
610 One of: component name, MyISAM Multiple Key Cache name, or empty string.
611
612 @param suffix
613 In a dot-separated syntax (@p prefix is mandatory):
614 component-registered variable name, or
615 MyISAM Multiple Key Cache property name.
616 Otherwise (@p is empty): name of static or plugin-registered variables.
617
618 @returns System_variable_tracker object
619 */
620 static System_variable_tracker make_tracker(std::string_view prefix,
621 std::string_view suffix);
622 /**
623 Static "constructor"
624
625 @note This function requires no locks and allocates nothing on memory heaps.
626
627 @param multipart_name
628 Variable name, optionally dot-separated.
629
630 @returns System_variable_tracker object
631 */
632 static System_variable_tracker make_tracker(std::string_view multipart_name);
633
634 Lifetime lifetime() const { return m_tag; }
635
636 bool operator==(const System_variable_tracker &x) const {
637 if (m_tag != x.m_tag) {
638 return false;
639 }
640 switch (m_tag) {
641 case STATIC:
642 return m_static.m_static_var == x.m_static.m_static_var;
643 case KEYCACHE:
644 return m_keycache.m_keycache_var == x.m_keycache.m_keycache_var;
645 case PLUGIN:
646 return names_are_same(m_plugin.m_plugin_var_name,
648 case COMPONENT:
649 return names_are_same(m_component.m_component_var_name,
651 }
652 my_abort(); // to make compiler happy
653 }
654
655 bool is_keycache_var() const { return m_tag == KEYCACHE; }
656
657 bool eq_static_sys_var(const sys_var *var) const {
658 return m_tag == STATIC && m_static.m_static_var == var;
659 }
660
661 /**
662 @returns 1) normalized names of regular system variables;
663 2) user-specified dot-separated names of key cache variables, or
664 user-specified unqualified names of default key cache
665 property names;
666 3) user-specified names of plugin-registered variables;
667 4) user-specified dot-separated names of component-registered
668 variables.
669 */
670 const char *get_var_name() const;
671
672 /**
673 @returns 1) not normalized names of MyISAM Multiple Key Caches,
674 also can return empty string for the implicit
675 prefix (i.e. implicit "DEFAULT.").
676 2) empty string for the rest of system variables.
677 */
678 std::string_view get_keycache_name() const {
679 return m_tag == KEYCACHE ? std::string_view{m_keycache.m_keycache_var_name,
680 m_keycache.m_keycache_name_size}
681 : std::string_view{};
682 }
683
684 /**
685 @returns true if the underlying variable can be referenced in the
686 SET_VAR optimizer hint syntax, otherwise false.
687 */
688 bool is_hint_updateable() const {
689 return m_tag == STATIC && m_static.m_static_var->is_hint_updateable();
690 }
691
692 /**
693 Safely pass a sys_var object to a function. Non-template variant.
694
695 access_system_variable() is the most important interface:
696 it does necessary locks,
697 if a dynamic variable is inaccessible it exits,
698 otherwise it calls @p function.
699 access_system_variable() is reentrant:
700 being called recursively it suppresses double locks.
701
702 Simplified pseudo code of access_system_variable() implementation:
703
704 if system variable is @@session_track_system_variables {
705 // a special case: the system variable is static,
706 // but it references a comma-separated list of
707 // other system variables
708 if function is not no-op {
709 process @@session_track_system_variables as plugin-registered one
710 } else {
711 return false // success
712 }
713 }
714 if system variable is static or key cache variable {
715 // no dictionary/plugin locks needed
716 call function(cached sys_var pointer)
717 return false // success
718 }
719 if system variable is plugin-registered one {
720 if need to hold LOCK_system_variables_hash {
721 acquire read-only LOCK_system_variables_hash
722 }
723 if need to hold LOCK_plugin {
724 acquire LOCK_plugin, unlock on exit
725 }
726 find sys_var
727 if found {
728 intern_plugin_lock
729 }
730 if this function acquired LOCK_plugin {
731 release LOCK_plugin
732 }
733 if this function acquired LOCK_system_variables_hash {
734 release LOCK_system_variables_hash
735 }
736 if not found or plugin is not in the PLUGIN_IS_READY state {
737 return true // error: variable not found or
738 }
739 call function(found sys_var pointer)
740 return false // success
741 }
742 if system variable is component-registered one {
743 if need to hold LOCK_system_variables_hash(**) {
744 acquire read-only LOCK_system_variables_hash, unlock on exit
745 }
746 find sys_var
747 if not found {
748 return true
749 }
750 call function(found sys_var pointer)
751 return false // success
752 }
753
754 @param thd
755 A connection handler or nullptr.
756 @param function
757 An optional anonymous function to pass a sys_var object if the latest
758 is accessible.
759 @param suppress_not_found_error
760 Suppress or output ER_UNKNOWN_SYSTEM_VARIABLE if a dynamic variable is
761 unavailable.
762 @param force_sensitive_variable_access
763 Suppress privilege check for SENSITIVE variables.
764 @param is_already_locked
765 YES means LOCK_system_variables_hash has already been taken.
766 @param is_single_thread
767 YES means we are called from mysqld_main, during bootstrap.
768
769 @returns True if the dynamic variable is unavailable, otherwise false.
770 */
772 THD *thd,
773 std::function<void(const System_variable_tracker &, sys_var *)> function =
774 {},
775 Suppress_not_found_error suppress_not_found_error =
777 Force_sensitive_system_variable_access force_sensitive_variable_access =
779 Is_already_locked is_already_locked = Is_already_locked::NO,
780 Is_single_thread is_single_thread = Is_single_thread::NO) const;
781
782 /**
783 Safely pass a sys_var object to a function. Template variant.
784
785 access_system_variable() is the most important interface:
786 it does necessary locks,
787 if a dynamic variable is inaccessible then access_system_variable() exits
788 returning empty std::option,
789 otherwise it calls @p function and returns the result value of @p function
790 to the caller.
791
792 See the pseudo code part at the comment above a signature of the
793 non-template variant of access_system_variable() for details (replace
794 "return true" with "return std::option{}" and "return false" with "return
795 result value of anonymous function call").
796
797 @tparam T
798 A type of a return value of the callback function.
799
800 @param thd
801 A connection handler or nullptr.
802 @param function
803 A function to pass a sys_var object if the latest is accessible.
804 @param suppress_not_found_error
805 Suppress or output ER_UNKNOWN_SYSTEM_VARIABLE if a dynamic variable is
806 unavailable.
807 @param force_sensitive_variable_access
808 Suppress privilege check for SENSITIVE variables.
809 @param is_already_locked
810 YES means LOCK_system_variables_hash has already been taken.
811 @param is_single_thread
812 YES means we are called from mysqld_main, during bootstrap.
813
814 @returns
815 No value if the dynamic variable is unavailable, otherwise a value of
816 type T returned by the callback function.
817 */
818 template <typename T>
819 std::optional<T> access_system_variable(
820 THD *thd,
821 std::function<T(const System_variable_tracker &, sys_var *)> function,
822 Suppress_not_found_error suppress_not_found_error =
824 Force_sensitive_system_variable_access force_sensitive_variable_access =
826 Is_already_locked is_already_locked = Is_already_locked::NO,
827 Is_single_thread is_single_thread = Is_single_thread::NO) const {
828 T result;
829 auto wrapper = [function, &result](const System_variable_tracker &t,
830 sys_var *v) {
831 result = function(t, v); // clang-format
832 };
833 return access_system_variable(thd, wrapper, suppress_not_found_error,
834 force_sensitive_variable_access,
835 is_already_locked, is_single_thread)
836 ? std::optional<T>{}
837 : std::optional<T>{result};
838 }
839
841 if (!m_cache.has_value()) my_abort();
842 return m_cache.value().m_cached_show_type;
843 }
844
845 bool cached_is_sensitive() const {
846 if (!m_cache.has_value()) my_abort();
847 return m_cache.value().m_cached_is_sensitive;
848 }
849
850 /** Number of system variable elements to preallocate. */
851 static constexpr size_t SYSTEM_VARIABLE_PREALLOC = 200;
852
855 friend Array; // for Array::emplace_back()
856
857 static bool enumerate_sys_vars(bool sort, enum enum_var_type type,
858 bool strict, Array *output);
859
860 private:
861 static bool enumerate_sys_vars_in_hash(
863 enum enum_var_type query_scope, bool strict,
865
866 static bool names_are_same(const char *, const char *);
867
869 switch (m_tag) {
870 case STATIC:
871 return m_static.m_static_var;
872 case KEYCACHE:
873 return m_keycache.m_keycache_var;
874 default:
875 assert(false);
876 return nullptr; // should never happen
877 }
878 }
879
880 private:
881 bool visit_plugin_variable(THD *, std::function<bool(sys_var *)>,
883 Is_single_thread) const;
884
885 bool visit_component_variable(THD *, std::function<bool(sys_var *)>,
887 Is_single_thread) const;
888
889 void cache_metadata(THD *thd, sys_var *v) const;
890
891 private:
893
894 struct Cache {
897 };
898 mutable std::optional<Cache> m_cache;
899
900 /**
901 A non-zero value suppresses LOCK_system_variables_hash guards in
902 System_variable_tracker::access_system_variable
903 */
904 thread_local static int m_hash_lock_recursion_depth;
905
906 union {
907 struct {
909 } m_static; // when m_tag == STATIC
910
911 struct {
912 /// A dot-separated key cache name or, for a reduced form of key cache
913 /// variable names, a key cache property name as specified by the
914 /// caller of System_variable_tracker::make_traker().
915 char m_keycache_var_name[NAME_LEN + sizeof(".key_cache_division_limit")];
918 } m_keycache; // when m_tag == KEYCACHE
919
920 struct {
921 /// A "_"-separated plugin-registered variables name.
924 } m_plugin; // when m_tag == PLUGIN
925
926 struct {
927 /// A dot-separated component-registered variable name.
928 char m_component_var_name[NAME_LEN + sizeof('.') + NAME_LEN + 1];
931 };
932};
933
934/****************************************************************************
935 Classes for parsing of the SET command
936****************************************************************************/
937
938/**
939 A base class for everything that can be set with SET command.
940 It's similar to Items, an instance of this is created by the parser
941 for every assignment in SET (or elsewhere, e.g. in SELECT).
942*/
944 public:
945 set_var_base() = default;
946 virtual ~set_var_base() = default;
947 virtual int resolve(THD *thd) = 0; ///< Check privileges & fix_fields
948 virtual int check(THD *thd) = 0; ///< Evaluate the expression
949 virtual int update(THD *thd) = 0; ///< Set the value
950 virtual bool print(const THD *thd, String *str) = 0; ///< To self-print
951
952 /**
953 @returns whether this variable is @@@@optimizer_trace.
954 */
955 virtual bool is_var_optimizer_trace() const { return false; }
956 virtual void cleanup() {}
957
958 /**
959 Used only by prepared statements to resolve and check. No locking of tables
960 between the two phases.
961 */
962 virtual int light_check(THD *thd) { return (resolve(thd) || check(thd)); }
963
964 /** Used to identify if variable is sensitive or not */
965 virtual bool is_sensitive() const { return false; }
966};
967
968/**
969 set_var_base descendant for assignments to the system variables.
970*/
971class set_var : public set_var_base {
972 public:
973 Item *value; ///< the expression that provides the new value of the variable
975 union ///< temp storage to hold a value between sys_var::check and ::update
976 {
977 ulonglong ulonglong_value; ///< for all integer, set, enum sysvars
978 double double_value; ///< for Sys_var_double
979 plugin_ref plugin; ///< for Sys_var_plugin
980 Time_zone *time_zone; ///< for Sys_var_tz
981 LEX_STRING string_value; ///< for Sys_var_charptr and others
982 const void *ptr; ///< for Sys_var_struct
983 } save_result;
984
985 ///< Resolver of the variable at the left hand side of the assignment.
987
988 public:
990 Item *value_arg)
991 : value{value_arg}, type{type_arg}, m_var_tracker(var_arg) {}
992
993 int resolve(THD *thd) override;
994 int check(THD *thd) override;
995 int update(THD *thd) override;
996 int light_check(THD *thd) override;
997 /**
998 Print variable in short form.
999
1000 @param thd Thread handle.
1001 @param str String buffer to append the partial assignment to.
1002 */
1003 void print_short(const THD *thd, String *str);
1004 bool print(const THD *, String *str) override; /* To self-print */
1006 return (type == OPT_GLOBAL || type == OPT_PERSIST ||
1008 }
1009 bool is_var_optimizer_trace() const override {
1012 }
1013
1014 bool is_sensitive() const override;
1015
1017};
1018
1019/* User variables like @my_own_variable */
1022
1023 public:
1025 int resolve(THD *thd) override;
1026 int check(THD *thd) override;
1027 int update(THD *thd) override;
1028 int light_check(THD *thd) override;
1029 bool print(const THD *thd, String *str) override; /* To self-print */
1030};
1031
1035 const char *current_password;
1039
1040 public:
1041 set_var_password(LEX_USER *user_arg, char *password_arg,
1042 char *current_password_arg, bool retain_current,
1043 bool generate_password);
1044
1045 const LEX_USER *get_user(void) { return user; }
1048 int resolve(THD *) override { return 0; }
1049 int check(THD *thd) override;
1050 int update(THD *thd) override;
1051 bool print(const THD *thd, String *str) override; /* To self-print */
1052 ~set_var_password() override;
1053};
1054
1055/* For SET NAMES and SET CHARACTER SET */
1056
1062
1063 public:
1067 SET_CS_COLLATE = 4
1069 set_var_collation_client(int set_cs_flags_arg,
1070 const CHARSET_INFO *client_coll_arg,
1071 const CHARSET_INFO *connection_coll_arg,
1072 const CHARSET_INFO *result_coll_arg)
1073 : set_cs_flags(set_cs_flags_arg),
1074 character_set_client(client_coll_arg),
1075 character_set_results(result_coll_arg),
1076 collation_connection(connection_coll_arg) {}
1077 int resolve(THD *) override { return 0; }
1078 int check(THD *thd) override;
1079 int update(THD *thd) override;
1080 bool print(const THD *thd, String *str) override; /* To self-print */
1081};
1082
1083/* optional things, have_* variables */
1085
1091
1092/*
1093 Helper functions
1094*/
1095ulong get_system_variable_count(void);
1101
1102extern bool get_sysvar_source(const char *name, uint length,
1104
1105int sql_set_variables(THD *thd, List<set_var_base> *var_list, bool opened);
1106bool keyring_access_test();
1108
1111 LEX_STRING *ls);
1113 LEX_STRING *ls);
1114
1119
1121
1122const CHARSET_INFO *get_old_charset_by_name(const char *old_name);
1123
1124int sys_var_init();
1125int sys_var_add_options(std::vector<my_option> *long_options, int parse_flags);
1126void sys_var_end(void);
1127
1128/* check needed privileges to perform SET PERSIST[_only] or RESET PERSIST */
1129bool check_priv(THD *thd, bool static_variable);
1130
1131#define PERSIST_ONLY_ADMIN_X509_SUBJECT "persist_only_admin_x509_subject"
1132#define PERSISTED_GLOBALS_LOAD "persisted_globals_load"
1134
1135#endif
This class is used to implement operations like SET @variable or @variable:= expression.
Definition: item_func.h:3155
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:853
Definition: sql_list.h:434
wrapper to hide a mutex and an rwlock under a common interface
Definition: sys_vars_shared.h:52
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:168
A sys_var that is an alias for another sys_var.
Definition: sys_vars.h:352
Wrapper interface for all kinds of system variables.
Definition: set_var.h:574
Lifetime lifetime() const
Definition: set_var.h:634
System_variable_tracker(Static, sys_var *var)
Definition: set_var.cc:633
struct System_variable_tracker::@155::@158 m_keycache
static thread_local int m_hash_lock_recursion_depth
A non-zero value suppresses LOCK_system_variables_hash guards in System_variable_tracker::access_syst...
Definition: set_var.h:904
sys_var * get_stable_var() const
Definition: set_var.h:868
char m_keycache_var_name[NAME_LEN+sizeof(".key_cache_division_limit")]
A dot-separated key cache name or, for a reduced form of key cache variable names,...
Definition: set_var.h:915
sys_var * m_static_var
Definition: set_var.h:908
std::string_view get_keycache_name() const
Definition: set_var.h:678
Lifetime m_tag
Definition: set_var.h:892
void operator=(System_variable_tracker &&)
Definition: set_var.cc:740
SHOW_TYPE cached_show_type() const
Definition: set_var.h:840
static bool enumerate_sys_vars_in_hash(collation_unordered_map< std::string, sys_var * > *hash, enum enum_var_type query_scope, bool strict, System_variable_tracker::Array *output)
Definition: set_var.cc:1028
static System_variable_tracker make_tracker(std::string_view prefix, std::string_view suffix)
Static "constructor".
Definition: set_var.cc:849
sys_var * m_plugin_var_cache
Definition: set_var.h:923
sys_var * m_component_var_cache
Definition: set_var.h:929
Lifetime
Definition: set_var.h:591
@ KEYCACHE
for MyISAM Multiple Key Cache variables
Definition: set_var.h:593
@ PLUGIN
for plugin-registered system variables
Definition: set_var.h:594
@ STATIC
for regular static variables
Definition: set_var.h:592
@ COMPONENT
for component-registered variables
Definition: set_var.h:595
struct System_variable_tracker::@155::@159 m_plugin
bool eq_static_sys_var(const sys_var *var) const
Definition: set_var.h:657
bool visit_component_variable(THD *, std::function< bool(sys_var *)>, Suppress_not_found_error, Is_already_locked, Is_single_thread) const
Definition: set_var.cc:1241
bool access_system_variable(THD *thd, std::function< void(const System_variable_tracker &, sys_var *)> function={}, Suppress_not_found_error suppress_not_found_error=Suppress_not_found_error::NO, Force_sensitive_system_variable_access force_sensitive_variable_access=Force_sensitive_system_variable_access::NO, Is_already_locked is_already_locked=Is_already_locked::NO, Is_single_thread is_single_thread=Is_single_thread::NO) const
Definition: set_var.cc:761
static bool enumerate_sys_vars(bool sort, enum enum_var_type type, bool strict, Array *output)
Constructs an array of system variables for display to the user.
Definition: set_var.cc:1111
struct System_variable_tracker::@155::@160 m_component
struct System_variable_tracker::@155::@157 m_static
void cache_metadata(THD *thd, sys_var *v) const
Definition: set_var.cc:1284
std::optional< Cache > m_cache
Definition: set_var.h:898
char m_plugin_var_name[NAME_LEN+1]
A "_"-separated plugin-registered variables name.
Definition: set_var.h:922
Prealloced_array< System_variable_tracker, SYSTEM_VARIABLE_PREALLOC > Array
Definition: set_var.h:854
const char * get_var_name() const
Definition: set_var.cc:747
~System_variable_tracker()
Definition: set_var.cc:723
bool is_hint_updateable() const
Definition: set_var.h:688
sys_var * m_keycache_var
Definition: set_var.h:917
bool cached_is_sensitive() const
Definition: set_var.h:845
bool is_keycache_var() const
Definition: set_var.h:655
size_t m_keycache_name_size
Definition: set_var.h:916
bool operator==(const System_variable_tracker &x) const
Definition: set_var.h:636
static bool names_are_same(const char *, const char *)
Definition: set_var.cc:845
char m_component_var_name[NAME_LEN+sizeof('.')+NAME_LEN+1]
A dot-separated component-registered variable name.
Definition: set_var.h:928
friend Array
Definition: set_var.h:855
std::optional< T > access_system_variable(THD *thd, std::function< T(const System_variable_tracker &, sys_var *)> function, Suppress_not_found_error suppress_not_found_error=Suppress_not_found_error::NO, Force_sensitive_system_variable_access force_sensitive_variable_access=Force_sensitive_system_variable_access::NO, Is_already_locked is_already_locked=Is_already_locked::NO, Is_single_thread is_single_thread=Is_single_thread::NO) const
Safely pass a sys_var object to a function.
Definition: set_var.h:819
bool visit_plugin_variable(THD *, std::function< bool(sys_var *)>, Suppress_not_found_error, Is_already_locked, Is_single_thread) const
Definition: set_var.cc:1138
static constexpr size_t SYSTEM_VARIABLE_PREALLOC
Number of system variable elements to preallocate.
Definition: set_var.h:851
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
This class represents abstract time zone and provides basic interface for MYSQL_TIME <-> my_time_t co...
Definition: tztime.h:49
std::unordered_map, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:210
A base class for everything that can be set with SET command.
Definition: set_var.h:943
virtual ~set_var_base()=default
set_var_base()=default
virtual int check(THD *thd)=0
Evaluate the expression.
virtual int light_check(THD *thd)
Used only by prepared statements to resolve and check.
Definition: set_var.h:962
virtual bool is_sensitive() const
Used to identify if variable is sensitive or not.
Definition: set_var.h:965
virtual void cleanup()
Definition: set_var.h:956
virtual int resolve(THD *thd)=0
Check privileges & fix_fields.
virtual bool print(const THD *thd, String *str)=0
To self-print.
virtual int update(THD *thd)=0
Set the value.
virtual bool is_var_optimizer_trace() const
Definition: set_var.h:955
Definition: set_var.h:1057
set_cs_flags_enum
Definition: set_var.h:1064
@ SET_CS_DEFAULT
Definition: set_var.h:1066
@ SET_CS_NAMES
Definition: set_var.h:1065
@ SET_CS_COLLATE
Definition: set_var.h:1067
const CHARSET_INFO * character_set_client
Definition: set_var.h:1059
const CHARSET_INFO * character_set_results
Definition: set_var.h:1060
const CHARSET_INFO * collation_connection
Definition: set_var.h:1061
set_var_collation_client(int set_cs_flags_arg, const CHARSET_INFO *client_coll_arg, const CHARSET_INFO *connection_coll_arg, const CHARSET_INFO *result_coll_arg)
Definition: set_var.h:1069
bool print(const THD *thd, String *str) override
To self-print.
Definition: set_var.cc:2039
int update(THD *thd) override
Set the value.
Definition: set_var.cc:2012
int set_cs_flags
Definition: set_var.h:1058
int resolve(THD *) override
Check privileges & fix_fields.
Definition: set_var.h:1077
int check(THD *thd) override
Evaluate the expression.
Definition: set_var.cc:2002
Definition: set_var.h:1032
LEX_USER * user
Definition: set_var.h:1033
char * str_generated_password
Definition: set_var.h:1038
int check(THD *thd) override
Check the validity of the SET PASSWORD request.
Definition: set_var.cc:1945
set_var_password(LEX_USER *user_arg, char *password_arg, char *current_password_arg, bool retain_current, bool generate_password)
Definition: set_var.cc:1915
bool print(const THD *thd, String *str) override
To self-print.
Definition: set_var.cc:1977
bool retain_current_password
Definition: set_var.h:1036
bool has_generated_password(void)
Definition: set_var.h:1046
int resolve(THD *) override
Check privileges & fix_fields.
Definition: set_var.h:1048
const LEX_USER * get_user(void)
Definition: set_var.h:1045
const char * get_generated_password(void)
Definition: set_var.h:1047
char * password
Definition: set_var.h:1034
int update(THD *thd) override
Set the value.
Definition: set_var.cc:1953
bool generate_password
Definition: set_var.h:1037
~set_var_password() override
Definition: set_var.cc:1931
const char * current_password
Definition: set_var.h:1035
Definition: set_var.h:1020
int check(THD *thd) override
Evaluate the expression.
Definition: set_var.cc:1865
int update(THD *thd) override
Set the value.
Definition: set_var.cc:1893
set_var_user(Item_func_set_user_var *item)
Definition: set_var.h:1024
int resolve(THD *thd) override
Check privileges & fix_fields.
Definition: set_var.cc:1856
Item_func_set_user_var * user_var_item
Definition: set_var.h:1021
bool print(const THD *thd, String *str) override
To self-print.
Definition: set_var.cc:1906
int light_check(THD *thd) override
Check variable, but without assigning value (used by PS).
Definition: set_var.cc:1885
set_var_base descendant for assignments to the system variables.
Definition: set_var.h:971
ulonglong ulonglong_value
for all integer, set, enum sysvars
Definition: set_var.h:977
int resolve(THD *thd) override
Resolve the variable assignment.
Definition: set_var.cc:1578
set_var(enum_var_type type_arg, const System_variable_tracker &var_arg, Item *value_arg)
Definition: set_var.h:989
int update(THD *thd) override
Update variable.
Definition: set_var.cc:1772
const enum_var_type type
Definition: set_var.h:974
const System_variable_tracker m_var_tracker
Definition: set_var.h:986
void update_source_user_host_timestamp(THD *thd, sys_var *var)
Update variable source, user, host and timestamp values.
Definition: set_var.cc:1753
bool is_global_persist()
Definition: set_var.h:1005
Time_zone * time_zone
for Sys_var_tz
Definition: set_var.h:980
int light_check(THD *thd) override
Check variable, but without assigning value (used by PS).
Definition: set_var.cc:1703
union set_var::@161 save_result
Resolver of the variable at the left hand side of the assignment.
Item * value
the expression that provides the new value of the variable
Definition: set_var.h:973
int check(THD *thd) override
Verify that the supplied value is correct.
Definition: set_var.cc:1660
LEX_STRING string_value
for Sys_var_charptr and others
Definition: set_var.h:981
bool is_sensitive() const override
Check if system variable is of type SENSITIVE.
Definition: set_var.cc:1848
bool print(const THD *, String *str) override
Self-print assignment.
Definition: set_var.cc:1821
bool is_var_optimizer_trace() const override
Definition: set_var.h:1009
plugin_ref plugin
for Sys_var_plugin
Definition: set_var.h:979
void print_short(const THD *thd, String *str)
Print variable in short form.
Definition: set_var.cc:1800
const void * ptr
for Sys_var_struct
Definition: set_var.h:982
double double_value
for Sys_var_double
Definition: set_var.h:978
Definition: sql_plugin_var.h:196
A class representing one system variable - that is something that can be accessed as @global....
Definition: set_var.h:105
static const int PARSE_EARLY
Definition: set_var.h:153
virtual bool global_update(THD *thd, set_var *var)=0
bool is_hint_updateable() const
Check if the variable can be set using SET_VAR hint.
Definition: set_var.h:287
virtual bool set_source_name(const char *path)
Definition: set_var.h:238
my_option option
min, max, default values are stored here
Definition: set_var.h:173
my_option * get_option()
Definition: set_var.h:252
bool(* on_update_function)(sys_var *self, THD *thd, enum_var_type type)
Definition: set_var.h:167
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:108
virtual void set_arg_source(get_opt_arg_source *)
Definition: set_var.h:231
sys_var * next
Definition: set_var.h:107
char host[HOSTNAME_LENGTH+1]
Definition: set_var.h:187
virtual const char * get_host()
Definition: set_var.h:246
virtual ulonglong get_max_value()
Definition: set_var.h:224
virtual void set_user_host(THD *thd)
Definition: set_var.cc:454
uchar * global_var_ptr()
Definition: set_var.cc:401
bool m_is_persisted_deprecated
If m_persist_alias is set, and the current variable is deprecated and m_persist_alias is the recommen...
Definition: set_var.h:125
bool is_sensitive() const
Definition: set_var.h:280
bool check(THD *thd, set_var *var)
Definition: set_var.cc:405
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:397
void save_default(THD *thd, set_var *var)
Definition: set_var.h:349
bool register_option(std::vector< my_option > *array, int parse_flags)
Definition: set_var.h:334
flag_enum
Definition: set_var.h:126
@ SESSION
Definition: set_var.h:128
@ GLOBAL
Definition: set_var.h:127
@ INVISIBLE
Definition: set_var.h:133
@ SENSITIVE
Sensitive variable.
Definition: set_var.h:151
@ READONLY
Definition: set_var.h:131
@ SCOPE_MASK
Definition: set_var.h:130
@ ALLOCATED
Definition: set_var.h:132
@ NOTPERSIST
Definition: set_var.h:135
@ TRI_LEVEL
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:146
@ HINT_UPDATEABLE
Definition: set_var.h:136
@ ONLY_SESSION
Definition: set_var.h:129
virtual bool do_check(THD *thd, set_var *var)=0
sys_var * m_persisted_alias
If the variable has an alias in the persisted variables file, this should point to it.
Definition: set_var.h:117
bool is_global_persist(enum_var_type type)
Definition: set_var.h:324
virtual bool check_update_type(Item_result type)=0
virtual void set_timestamp(ulonglong ts)
Definition: set_var.h:254
const uchar * value_ptr(THD *running_thd, THD *target_thd, enum_var_type type, std::string_view keycache_name)
Definition: set_var.cc:427
virtual const char * get_user()
Definition: set_var.h:245
virtual void cleanup()
All the cleanup procedures should be performed here.
Definition: set_var.h:207
virtual longlong get_min_value()
Definition: set_var.h:223
virtual ~sys_var()=default
virtual void set_is_plugin(bool)
Definition: set_var.h:232
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:159
@ SESSION_VARIABLE_IN_BINLOG
Definition: set_var.h:161
@ VARIABLE_NOT_IN_BINLOG
Definition: set_var.h:160
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:184
bool is_parse_early() const
Definition: set_var.h:279
ptrdiff_t offset
offset to the value from global_system_variables
Definition: set_var.h:175
virtual bool set_user(const char *usr)
Definition: set_var.h:242
bool check_scope(enum_var_type query_type)
Return true for success if: Global query and variable scope is GLOBAL or SESSION, or Session query an...
Definition: set_var.h:311
bool(* on_check_function)(sys_var *self, THD *thd, set_var *var)
Definition: set_var.h:165
virtual enum_variable_source get_source()
Definition: set_var.h:233
SHOW_TYPE show_type()
Definition: set_var.h:272
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:393
const char * get_deprecation_substitute()
Definition: set_var.h:203
on_check_function on_check
Definition: set_var.h:176
const CHARSET_INFO * charset(THD *thd)
Definition: set_var.cc:589
virtual ulong get_var_type()
Returns variable type.
Definition: set_var.h:230
bool is_struct()
the following is only true for keycache variables, that support the syntax @keycache_name....
Definition: set_var.h:292
virtual const char * get_source_name()
Definition: set_var.h:234
bool set_default(THD *thd, set_var *var)
Update the system variable with the default value from either session or global scope.
Definition: set_var.cc:443
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:181
bool is_trilevel() const
Definition: set_var.h:277
bool is_persist_readonly() const
Definition: set_var.h:278
void do_deprecated_warning(THD *thd)
Definition: set_var.cc:477
int scope() const
Definition: set_var.h:273
struct get_opt_arg_source source
Definition: set_var.h:185
virtual void set_timestamp()
Definition: set_var.h:253
const SHOW_TYPE show_val_type
what value_ptr() returns for sql_show.cc
Definition: set_var.h:172
on_update_function on_update
Definition: set_var.h:182
int flags
or'ed flag_enum values
Definition: set_var.h:170
static const int PARSE_NORMAL
Definition: set_var.h:154
bool update(THD *thd, set_var *var)
Definition: set_var.cc:337
char user[USERNAME_CHAR_LENGTH+1]
Definition: set_var.h:186
bool is_written_to_binlog(enum_var_type type)
Definition: set_var.h:301
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:388
bool check_if_sensitive_in_context(THD *, bool suppress_errors=true) const
Definition: set_var.cc:1361
virtual void update_default(longlong new_def_value)
Definition: set_var.h:219
virtual bool set_host(const char *hst)
Definition: set_var.h:247
bool not_visible() const
Definition: set_var.h:276
bool is_settable_at_command_line()
Return true if settable at the command line.
Definition: set_var.h:332
PolyLock * guard
second lock that protects the variable
Definition: set_var.h:174
virtual longlong get_default()
Definition: set_var.h:222
virtual bool is_non_persistent()
Definition: set_var.h:255
virtual sys_var_pluginvar * cast_pluginvar()
downcast for sys_var_pluginvar.
Definition: set_var.h:212
Item * copy_value(THD *thd)
Create item from system variable value.
Definition: set_var.cc:498
const char *const deprecation_substitute
Definition: set_var.h:183
virtual ulonglong get_timestamp() const
Definition: set_var.h:250
static bool set_and_truncate(char *dst, const char *string, size_t sizeof_dst)
Like strncpy, but ensures the destination is '\0'-terminated.
Definition: set_var.h:366
bool(* pre_update_function)(sys_var *self, THD *thd, set_var *var)
Definition: set_var.h:166
bool is_readonly() const
Definition: set_var.h:275
virtual bool session_update(THD *thd, set_var *var)=0
int m_parse_flag
either PARSE_EARLY or PARSE_NORMAL.
Definition: set_var.h:171
ulonglong timestamp
Definition: set_var.h:188
sys_var(sys_var_chain *chain, const char *name_arg, const char *comment, int flag_args, ptrdiff_t off, int getopt_id, enum get_opt_arg_type getopt_arg_type, SHOW_TYPE show_val_type_arg, longlong 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, sys_var *persisted_alias=nullptr, bool is_persisted_deprecated=false)
sys_var constructor
Definition: set_var.cc:268
virtual void set_source(enum_variable_source src)
Definition: set_var.h:235
ulonglong sql_mode_t
Definition: dd_event.h:37
#define comment
Definition: lexyy.cc:959
static int opened
Definition: log_filter_dragnet.cc:123
A better implementation of the UNIX ctype(3) library.
void my_abort()
Calls our own implementation of abort, if specified, or std's abort().
Definition: my_init.cc:258
get_opt_arg_type
Enumeration of the my_option::arg_type attributes.
Definition: my_getopt.h:81
#define GET_TYPE_MASK
Definition: my_getopt.h:72
#define GET_ASK_ADDR
Definition: my_getopt.h:71
Common definition used by mysys, performance schema and server & client.
static constexpr int HOSTNAME_LENGTH
Definition: my_hostname.h:43
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
unsigned char uchar
Definition: my_inttypes.h:52
long long int longlong
Definition: my_inttypes.h:55
Common header for many mysys elements.
Defines for getting and processing the current system type programmatically.
unsigned long long int my_micro_time()
Return time in microseconds.
Definition: my_systime.h:182
Common definition between mysql server & client.
#define NAME_LEN
Definition: mysql_com.h:67
#define USERNAME_CHAR_LENGTH
Definition: mysql_com.h:64
static char * path
Definition: mysqldump.cc:137
static const char * sql_mode
Definition: mysqlslap.cc:197
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1052
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:76
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
struct result result
Definition: result.h:34
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42
required string type
Definition: replication_group_member_actions.proto:34
ulonglong dynamic_system_variable_hash_version
Definition: set_var.cc:89
int sys_var_init()
Definition: set_var.cc:140
sys_var * Sys_gtid_purged_ptr
Definition: sys_vars.cc:6772
enum enum_mysql_show_type SHOW_TYPE
Definition: set_var.h:73
SHOW_COMP_OPTION have_rtree_keys
Definition: set_var.h:1088
ulonglong sql_mode_t
Definition: set_var.h:70
char * sys_var_persist_only_admin_x509_subject
global X509 subject name to require from the client session to allow SET PERSIST[_ONLY] on sys_var::N...
Definition: set_var.cc:1507
Force_sensitive_system_variable_access
Definition: set_var.h:414
collation_unordered_map< std::string, sys_var * > * get_dynamic_system_variable_hash(void)
Definition: set_var.cc:95
collation_unordered_map< std::string, sys_var * > * get_static_system_variable_hash(void)
Definition: set_var.cc:91
SHOW_COMP_OPTION have_profiling
Definition: mysqld.cc:1555
bool fix_delay_key_write(sys_var *self, THD *thd, enum_var_type type)
Definition: sys_vars.cc:2088
bool get_sysvar_source(const char *name, uint length, enum enum_variable_source *source)
Get source of a given system variable given its name and name length.
Definition: set_var.cc:107
enum enum_mysql_show_scope SHOW_SCOPE
Definition: set_var.h:74
Is_single_thread
Definition: set_var.h:418
SHOW_COMP_OPTION have_compress
Definition: mysqld.cc:1554
sys_var * Sys_gtid_next_ptr
Definition: sys_vars.cc:6673
ulong get_system_variable_count(void)
Definition: set_var.cc:1015
SHOW_COMP_OPTION have_symlink
Definition: mysqld.cc:1552
SHOW_COMP_OPTION have_statement_timeout
Definition: mysqld.cc:1556
bool add_static_system_variable_chain(sys_var *chain)
Add variables to the hash of static system variables.
Definition: set_var.cc:978
bool sql_mode_string_representation(THD *thd, sql_mode_t sql_mode, LEX_STRING *ls)
Definition: sys_vars.cc:5002
bool add_dynamic_system_variable_chain(sys_var *chain)
Add variables to the dynamic hash of system variables.
Definition: set_var.cc:952
Is_already_locked
Definition: set_var.h:416
void delete_dynamic_system_variable_chain(sys_var *chain)
Remove variables from the dynamic hash of system variables.
Definition: set_var.cc:1003
bool keyring_access_test()
This function is used to check if key management UDFs like keying_key_generate/store/remove should pr...
Definition: set_var.cc:1489
SHOW_COMP_OPTION have_geometry
Definition: mysqld.cc:1553
bool sql_mode_quoted_string_representation(THD *thd, sql_mode_t sql_mode, LEX_STRING *ls)
Definition: sys_vars.cc:5007
sys_var * Sys_autocommit_ptr
Definition: sys_vars.cc:5476
int sql_set_variables(THD *thd, List< set_var_base > *var_list, bool opened)
Execute update of all variables.
Definition: set_var.cc:1413
Suppress_not_found_error
Definition: set_var.h:412
ulonglong get_dynamic_system_variable_hash_version(void)
Definition: set_var.cc:1024
TYPELIB bool_typelib
Definition: sys_vars.cc:215
void sys_var_end(void)
Definition: set_var.cc:179
const CHARSET_INFO * get_old_charset_by_name(const char *old_name)
Definition: set_var.cc:926
int sys_var_add_options(std::vector< my_option > *long_options, int parse_flags)
Definition: set_var.cc:165
enum_var_type
Definition: set_var.h:90
@ OPT_PERSIST_ONLY
Definition: set_var.h:95
@ OPT_PERSIST
Definition: set_var.h:94
@ OPT_GLOBAL
Definition: set_var.h:93
@ OPT_DEFAULT
Definition: set_var.h:91
@ OPT_SESSION
Definition: set_var.h:92
sql_mode_t expand_sql_mode(sql_mode_t sql_mode, THD *thd)
Definition: sys_vars.cc:4894
bool check_priv(THD *thd, bool static_variable)
This function will check for necessary privileges needed to perform RESET PERSIST or SET PERSIST[_ONL...
Definition: set_var.cc:203
SHOW_COMP_OPTION have_query_cache
Definition: mysqld.cc:1552
SHOW_COMP_OPTION have_dlopen
Definition: set_var.h:1086
sys_var * Sys_gtid_next_list_ptr
File containing constants that can be used throughout the server.
SHOW_COMP_OPTION
Definition: sql_const.h:227
case opt name
Definition: sslopt-case.h:33
enum_mysql_show_type
Declarations for SHOW STATUS support in plugins.
Definition: status_var.h:30
enum_mysql_show_scope
Status variable scope.
Definition: status_var.h:68
Definition: m_ctype.h:385
Definition: table.h:2658
Definition: mysql_lex_string.h:40
Definition: mysql_lex_string.h:35
Definition: set_var.h:894
bool m_cached_is_sensitive
Definition: set_var.h:896
SHOW_TYPE m_cached_show_type
Definition: set_var.h:895
Definition: set_var.h:578
Definition: set_var.h:576
Definition: set_var.h:577
Definition: set_var.h:575
Definition: typelib.h:35
Definition: my_getopt.h:83
char m_path_name[FN_REFLEN]
config file path OR compiled default values
Definition: my_getopt.h:87
enum enum_variable_source m_source
Definition: my_getopt.h:88
Definition: my_getopt.h:93
longlong min_value
Min allowed value (for numbers)
Definition: my_getopt.h:123
ulonglong max_value
Max allowed value (for numbers)
Definition: my_getopt.h:124
longlong def_value
Default value.
Definition: my_getopt.h:122
ulong var_type
GET_BOOL, GET_ULL, etc.
Definition: my_getopt.h:120
int id
For 0<id<=255 it's means one character for a short option (like -A), if >255 no short option is creat...
Definition: my_getopt.h:98
struct get_opt_arg_source * arg_source
Represents source/path from where this variable is set.
Definition: my_getopt.h:125
Definition: result.h:30
Definition: sql_plugin_ref.h:45
Definition: set_var.h:80
sys_var * first
Definition: set_var.h:81
sys_var * last
Definition: set_var.h:82
export sys_var * Sys_optimizer_trace_ptr
Definition: sys_vars.cc:3541
enum_variable_source
This enum values define how system variables are set.
Definition: system_variable_source_type.h:33
unsigned int uint
Definition: uca9-dump.cc:75
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:39