一.table_cache 相关参数
1.open_files_limit
2.max_connections
3.table_open_cache
4.table_definition_cache
问题?
经常会看到自己my.cnf设置的那四个值和在MySQL中看到的值不一样.
我修改了其中一个参数,结构发现所有的上面的四个参数都发生了变化。
参数到底应该设置为多少合适?
二.源码分析之初始化
1.常量定义
源码位置:/sql/sql_const.h
#define TABLE_OPEN_CACHE_MIN 400
#define TABLE_OPEN_CACHE_DEFAULT 2000
#define TABLE_DEF_CACHE_DEFAULT 400
#define MAX_CONNECTIONS_DEFAULT 151
#define TABLE_DEF_CACHE_MIN 400
源码位置:/mysql-5.7.33/my_global.h
#ifdef _WIN32
#define MY_FILE_MIN 2048
#else
#define MY_FILE_MIN 0
#endif
#ifdef _WIN32
#define MY_NFILE (16384 + MY_FILE_MIN)
#else
#define MY_NFILE 64
#endif
#define OS_FILE_LIMIT UINT_MAX
2.变量静态文件
源码位置:/mysql-5.7.33/sql/sys_vars.cc
static Sys_var_ulong Sys_open_files_limit(
"open_files_limit",
"If this is not 0, then mysqld will use this value to reserve file "
"descriptors to use with setrlimit(). If this value is 0 then mysqld "
"will reserve max_connections*5 or max_connections + table_open_cache*2 "
"(whichever is larger) number of file descriptors",
READ_ONLY GLOBAL_VAR(open_files_limit), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(0, OS_FILE_LIMIT), DEFAULT(0), BLOCK_SIZE(1),
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL), ON_UPDATE(NULL),
NULL,
sys_var::PARSE_EARLY);
static Sys_var_ulong Sys_max_connections(
"max_connections", "The number of simultaneous clients allowed",
GLOBAL_VAR(max_connections), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(1, 100000),
DEFAULT(MAX_CONNECTIONS_DEFAULT),
BLOCK_SIZE(1),
NO_MUTEX_GUARD,
NOT_IN_BINLOG,
ON_CHECK(0),
ON_UPDATE(0),
NULL,
sys_var::PARSE_EARLY);
static bool fix_table_cache_size(sys_var *self, THD *thd, enum_var_type type)
{
table_cache_size_per_instance= table_cache_size / table_cache_instances;
return false;
}
static Sys_var_ulong Sys_table_cache_size(
"table_open_cache&