MySQL 8.0.39
Source Code Documentation
set_var.cc File Reference
#include "sql/set_var.h"
#include <sys/types.h>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <string_view>
#include <utility>
#include "m_ctype.h"
#include "m_string.h"
#include "map_helpers.h"
#include "my_dbug.h"
#include "my_io.h"
#include "my_loglevel.h"
#include "my_sys.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/components/services/log_shared.h"
#include "mysql/plugin_audit.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/psi/mysql_rwlock.h"
#include "mysqld_error.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/auth/sql_security_ctx.h"
#include "sql/debug_sync.h"
#include "sql/derror.h"
#include "sql/enum_query_type.h"
#include "sql/item.h"
#include "sql/item_func.h"
#include "sql/log.h"
#include "sql/mysqld.h"
#include "sql/persisted_variable.h"
#include "sql/protocol_classic.h"
#include "sql/session_tracker.h"
#include "sql/sql_audit.h"
#include "sql/sql_base.h"
#include "sql/sql_class.h"
#include "sql/sql_error.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_parse.h"
#include "sql/sql_plugin_ref.h"
#include "sql/sql_plugin_var.h"
#include "sql/sql_select.h"
#include "sql/sql_show.h"
#include "sql/sys_vars_shared.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/thd_raii.h"
#include "sql_string.h"

Classes

struct  my_old_conv
 

Functions

collation_unordered_map< string, sys_var * > * get_static_system_variable_hash ()
 
collation_unordered_map< string, sys_var * > * get_dynamic_system_variable_hash ()
 
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. More...
 
int sys_var_init ()
 
int sys_var_add_options (std::vector< my_option > *long_options, int parse_flags)
 
void sys_var_end ()
 
bool check_priv (THD *thd, bool static_variable)
 This function will check for necessary privileges needed to perform RESET PERSIST or SET PERSIST[_ONLY] operation. More...
 
bool throw_bounds_warning (THD *thd, const char *name, bool fixed, bool is_unsigned, longlong v)
 Throw warning (error in STRICT mode) if value for variable needed bounding. More...
 
bool throw_bounds_warning (THD *thd, const char *name, bool fixed, double v)
 
static void set_tail_to_triple_dot (char *s, size_t size)
 
template<size_t N>
static void copy_name (char(&to)[N], std::string_view from)
 
static void merge_names (char *to, size_t capacity, std::string_view from1, std::string_view from2)
 
const CHARSET_INFOget_old_charset_by_name (const char *name)
 
bool add_dynamic_system_variable_chain (sys_var *first)
 Add variables to the dynamic hash of system variables. More...
 
bool add_static_system_variable_chain (sys_var *first)
 Add variables to the hash of static system variables. More...
 
void delete_dynamic_system_variable_chain (sys_var *first)
 Remove variables from the dynamic hash of system variables. More...
 
ulong get_system_variable_count (void)
 
ulonglong get_dynamic_system_variable_hash_version (void)
 
sys_varfind_static_system_variable (const std::string &name)
 Find a static system variable. More...
 
sys_varfind_dynamic_system_variable (const std::string &name)
 Find a dynamic system variable. More...
 
sys_varintern_find_sys_var (const char *str, size_t length)
 Find a system variable, either static or dynamic. More...
 
sys_varcheck_find_sys_var (THD *thd, const char *str, size_t length, bool *sensitive)
 
int sql_set_variables (THD *thd, List< set_var_base > *var_list, bool opened)
 Execute update of all variables. More...
 
bool keyring_access_test ()
 This function is used to check if key management UDFs like keying_key_generate/store/remove should proceed or not. More...
 
static bool can_persist_non_persistent_var (THD *thd, sys_var *var, enum_var_type setvar_type)
 Checks if a THD can set non-persist variables. More...
 

Variables

static collation_unordered_map< string, sys_var * > * static_system_variable_hash
 
static collation_unordered_map< string, sys_var * > * dynamic_system_variable_hash
 
static PolyLock_mutex PLock_global_system_variables & LOCK_global_system_variables
 
ulonglong dynamic_system_variable_hash_version = 0
 
static collation_unordered_set< string > * never_persistable_vars
 list of variables that shouldn't be persisted in all cases More...
 
sys_var_chain all_sys_vars = {nullptr, nullptr}
 
static my_old_conv old_conv []
 
char * sys_var_persist_only_admin_x509_subject = nullptr
 global X509 subject name to require from the client session to allow SET PERSIST[_ONLY] on sys_var::NOTPERSIST variables More...
 

Function Documentation

◆ add_dynamic_system_variable_chain()

bool add_dynamic_system_variable_chain ( sys_var first)

Add variables to the dynamic hash of system variables.

Parameters
firstPointer to first system variable to add
Returns
false on success, otherwise true.
Note
Requires r/w lock on LOCK_system_variables_hash.

◆ add_static_system_variable_chain()

bool add_static_system_variable_chain ( sys_var first)

Add variables to the hash of static system variables.

Parameters
firstPointer to first system variable to add
Returns
false on success, otherwise true.

◆ can_persist_non_persistent_var()

static bool can_persist_non_persistent_var ( THD thd,
sys_var var,
enum_var_type  setvar_type 
)
static

Checks if a THD can set non-persist variables.

Requires that: the session uses SSL the peer has presented a valid certificate the certificate has a certain subject name

The format checked is deliberately kept the same as the other SSL system and status variables representing names. Hence X509_NAME_oneline is used.

Return values
truethe THD can set NON_PERSIST variables
falseusual restrictions apply
Parameters
thdthe THD handle
varthe variable to be set
setvar_typethe operation to check against.
See also
sys_variables_admin_dn

◆ check_find_sys_var()

sys_var * check_find_sys_var ( THD thd,
const char *  str,
size_t  length,
bool *  sensitive 
)

◆ check_priv()

bool check_priv ( THD thd,
bool  static_variable 
)

This function will check for necessary privileges needed to perform RESET PERSIST or SET PERSIST[_ONLY] operation.

Parameters
[in]thdPointer to connection handle.
[in]static_variabledescribes if variable is static or dynamic
Returns
0 Success
1 Failure

◆ copy_name()

template<size_t N>
static void copy_name ( char(&)  to[N],
std::string_view  from 
)
static

◆ delete_dynamic_system_variable_chain()

void delete_dynamic_system_variable_chain ( sys_var first)

Remove variables from the dynamic hash of system variables.

Parameters
firstPointer to first system variable to remove
Note
Requires r/w lock on LOCK_system_variables_hash.

◆ find_dynamic_system_variable()

sys_var * find_dynamic_system_variable ( const std::string &  name)

Find a dynamic system variable.

Parameters
nameName of system variable to find
Return values
pointerpointer to variable definitions
nullptr1. Unknown static variable (error message is given).
  1. Invisible static variable (no error message).
Note
Requires an external lock on LOCK_system_variable_hash.

◆ find_static_system_variable()

sys_var * find_static_system_variable ( const std::string &  name)

Find a static system variable.

Parameters
nameName of system variable to find
Return values
pointerpointer to variable definitions
nullptr1. Unknown static variable (error message is given).
  1. Invisible static variable (no error message).
Note
Unlike intern_find_sys_var() and find_dynamic_system_variable(), an external lock on LOCK_system_variable_hash is not necessary.

◆ get_dynamic_system_variable_hash()

collation_unordered_map< string, sys_var * > * get_dynamic_system_variable_hash ( void  )

◆ get_dynamic_system_variable_hash_version()

ulonglong get_dynamic_system_variable_hash_version ( void  )

◆ get_old_charset_by_name()

const CHARSET_INFO * get_old_charset_by_name ( const char *  name)

◆ get_static_system_variable_hash()

collation_unordered_map< string, sys_var * > * get_static_system_variable_hash ( void  )

◆ get_system_variable_count()

ulong get_system_variable_count ( void  )

◆ get_sysvar_source()

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.

Note
Holds an intermediate lock on LOCK_system_variables_hash.

◆ intern_find_sys_var()

sys_var * intern_find_sys_var ( const char *  str,
size_t  length 
)

Find a system variable, either static or dynamic.

Parameters
strName of system variable to find
lengthLength of variable. zero means that we should use strlen() on the variable
Return values
pointerpointer to variable definitions
nullptr1. Unknown variable (error message is given).
  1. Invisible variable (no error message).
Note
Requires an external lock on LOCK_system_variable_hash.

◆ keyring_access_test()

bool keyring_access_test ( )

This function is used to check if key management UDFs like keying_key_generate/store/remove should proceed or not.

If global variable @keyring_operations is OFF then above said udfs will fail.

Returns
Operation status
Return values
0OK
1ERROR, keyring operations are not allowed
See also
Sys_keyring_operations

◆ merge_names()

static void merge_names ( char *  to,
size_t  capacity,
std::string_view  from1,
std::string_view  from2 
)
static

◆ set_tail_to_triple_dot()

static void set_tail_to_triple_dot ( char *  s,
size_t  size 
)
static

◆ sql_set_variables()

int sql_set_variables ( THD thd,
List< set_var_base > *  var_list,
bool  opened 
)

Execute update of all variables.

First run a check of all variables that all updates will go ok. If yes, then execute all updates, returning an error if any one failed.

This should ensure that in all normal cases none all or variables are updated.

Parameters
thdThread id
var_listList of variables to update
openedTrue means tables are open and this function will lock them.
Return values
0ok
1ERROR, message sent (normally no variables was updated)
-1ERROR, message not sent

◆ sys_var_add_options()

int sys_var_add_options ( std::vector< my_option > *  long_options,
int  parse_flags 
)

◆ sys_var_end()

void sys_var_end ( void  )

◆ sys_var_init()

int sys_var_init ( )

◆ throw_bounds_warning() [1/2]

bool throw_bounds_warning ( THD thd,
const char *  name,
bool  fixed,
bool  is_unsigned,
longlong  v 
)

Throw warning (error in STRICT mode) if value for variable needed bounding.

Plug-in interface also uses this.

Parameters
thdthread handle
namevariable's name
fixeddid we have to correct the value? (throw warn/err if so)
is_unsignedis value's type unsigned?
vvariable's value
Return values
trueon error, false otherwise (warning or ok)

◆ throw_bounds_warning() [2/2]

bool throw_bounds_warning ( THD thd,
const char *  name,
bool  fixed,
double  v 
)

Variable Documentation

◆ all_sys_vars

sys_var_chain all_sys_vars = {nullptr, nullptr}

◆ dynamic_system_variable_hash

collation_unordered_map<string, sys_var *>* dynamic_system_variable_hash
static

◆ dynamic_system_variable_hash_version

ulonglong dynamic_system_variable_hash_version = 0

◆ LOCK_global_system_variables

PolyLock_mutex PLock_global_system_variables & LOCK_global_system_variables
static

◆ never_persistable_vars

collation_unordered_set<string>* never_persistable_vars
static

list of variables that shouldn't be persisted in all cases

◆ old_conv

my_old_conv old_conv[]
static
Initial value:
= {{"cp1251_koi8", "cp1251"},
{"cp1250_latin2", "cp1250"},
{"kam_latin2", "keybcs2"},
{"mac_latin2", "MacRoman"},
{"macce_latin2", "MacCE"},
{"pc2_latin2", "pclatin2"},
{"vga_latin2", "pclatin1"},
{"koi8_cp1251", "koi8r"},
{"win1251ukr_koi8_ukr", "win1251ukr"},
{"koi8_ukr_win1251ukr", "koi8u"},
{nullptr, nullptr}}

◆ static_system_variable_hash

collation_unordered_map<string, sys_var *>* static_system_variable_hash
static

◆ sys_var_persist_only_admin_x509_subject

char* sys_var_persist_only_admin_x509_subject = nullptr

global X509 subject name to require from the client session to allow SET PERSIST[_ONLY] on sys_var::NOTPERSIST variables

See also
set_var::resolve