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