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