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