MySQL参数
-
ref https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html
-
变量
- 分为不同作用域
- 编译时设置
- 初始化时设置
- 需要重启
- 需要
- 分为 global和local
- 当前 session 的值是创建链接时从全局变量设置的,运行时使用的session变量
- session 变量
- 分为不同作用域
-
部分参数定义类似 pg,这部分 MySQL 称之为 VARIABLES,可以使用 'select @@[global|session].variable_name' 查询参数
-
MySQL还存在一些反应系统状态的参数,MySQL 称之为 STATUS
- 都可以使用语句
show [global|local] [variables|status] [like 'pattern']来查询
- 都可以使用语句
-
参数存在全局和local的区别,local参数只对当前会话有效,全局参数对所有会话有效
show variables like '%optimizer_switch%'; show global variables like '%optimizer_switch%';
- 实际是一条select 语句,读取的 pfs 中
QS:
- 变量的内部管理机制
- 每一个参数都是静态变量,使用下面两个 hash 表管理
- dynamic_system_variable_hash
- 动态参数,插件内部定义的值,使用这个 map 管理,对外不区分使用方法
- static_system_variable_hash
- MySQL 内部参数,例如优化器参数
- dynamic_system_variable_hash
- intern_find_sys_var 的使用,使用 name 去找具体的参数
- 没有直接使用这两个hash表保存具体的参数,而是使用 System_variables 保存具体的参数
- global_system_variables 是全局变量,保存的是全局参数
- thd->variables 是 session 变量,保存的是当前会话参数
- 每一个参数都是静态变量,使用下面两个 hash 表管理
- 新链接的时候,session 变量的初始化过程
- 在 THD 初始化的时候,在函数 plugin_thdvar_init 中,把 global_system_variables 复制给 thd->variables,然后再微调部分参数
- 设置值的时候,具体的操作步骤
- 使用 find_static_system_variable 和 find_static_system_variable 按名字查找 var
- 每一个参数是 继承自 sys_var 的子类
- 修改 global 的时候,调用的是 global_update, 修改的是 global_system_variables
- 修改 session 的时候,调用的是 session_update, 修改的是 thd->variables
- 使用的时候,使用的值
- 无论什么时候,都是使用 thd->variables 的值,所以在修改参数的时候,如果修改的是 global 的值,已经启动的会话是不受影响的,除非重启会话
set global optimizer_switch='index_merge=off';
optimizer相关参数
index_merge=on,
index_merge_union=on,
index_merge_sort_union=on,
index_merge_intersection=on,
engine_condition_pushdown=on,
index_condition_pushdown=on,
mrr=on,
mrr_cost_based=on,
block_nested_loop=on,
batched_key_access=off,
materialization=on,
semijoin=on,
loosescan=on,
firstmatch=on,
duplicateweedout=on,
subquery_materialization_cost_based=on,
use_index_extensions=on,
condition_fanout_filter=on,
derived_merge=on,
use_invisible_indexes=on,
skip_scan=on,
hash_join=on,
subquery_to_derived=off,
prefer_ordering_index=on,
hypergraph_optimizer=off,
derived_condition_pushdown=on,
favor_range_scan=off,
remove_useless_outerjoin=off
#define PLUGIN_VAR_UNSIGNED 0x0080 /**< The variable is unsigned */
#define PLUGIN_VAR_THDLOCAL 0x0100 /**< Variable is per-connection */
#define PLUGIN_VAR_READONLY 0x0200 /**< Server variable is read only */
#define PLUGIN_VAR_NOSYSVAR 0x0400 /**< Not a server variable */
#define PLUGIN_VAR_NOCMDOPT 0x0800 /**< Not a command line option */
#define PLUGIN_VAR_NOCMDARG 0x1000 /**< No argument for cmd line */
#define PLUGIN_VAR_RQCMDARG 0x0000 /**< Argument required for cmd line */
#define PLUGIN_VAR_OPCMDARG 0x2000 /**< Argument optional for cmd line */
#define PLUGIN_VAR_NODEFAULT 0x4000 /**< SET DEFAULT is prohibited */
#define PLUGIN_VAR_MEMALLOC 0x8000 /**< String needs memory allocated */
#define PLUGIN_VAR_NOPERSIST \
0x10000 /**< SET PERSIST_ONLY is prohibited for read only variables */
#define PLUGIN_VAR_PERSIST_AS_READ_ONLY 0x20000
#define PLUGIN_VAR_INVISIBLE 0x40000 /**< Variable should not be shown */
#define PLUGIN_VAR_SENSITIVE 0x80000 /**< Sensitive variable */
/**
This flag enables variables to be recognized by SET_VAR() HINT. Should
be used only THDVAR() variables, ie variables which have session scope.
*/
#define PLUGIN_VAR_HINTUPDATEABLE 0x100000
19 个结果 - 2 文件
sql/sql_plugin_var.h:
211: class sys_var_pluginvar : public sys_var
sql/sys_vars.h:
198: class Sys_var_integer : public sys_var
358: class Sys_var_alias : public sys_var
577: class Sys_var_typelib : public sys_var
772: class Sys_var_multi_enum : public sys_var
1049: class Sys_var_charptr : public sys_var
1192: class Sys_var_proxy_user : public sys_var
1331: class Sys_var_dbug : public sys_var
1515: class Sys_var_double : public sys_var
1864: class Sys_var_plugin : public sys_var
1979: class Sys_var_debug_sync : public sys_var
2250: class Sys_var_have : public sys_var
2350: class Sys_var_struct : public sys_var
2431: class Sys_var_tz : public sys_var
2567: class Sys_var_gtid_next : public sys_var
2632: class Sys_var_gtid_set : public sys_var
2713: class Sys_var_charptr_func : public sys_var
2814: class Sys_var_gtid_purged : public sys_var
3004: class Sys_var_errors_set : public sys_var