- 论坛徽章:
- 0
|
回复 1# qlks
更新一下5.1+版本的修改步骤,很简单:
第一步:没变。按qlks大牛说的步骤
在mysqld.cc文件查找结构体my_option my_long_options[],并在其中的参数设置值搜索:long_query_time参数值,修改倒数第5个值,如下红色的值,其实默认就为0值。
{"long_query_time", OPT_LONG_QUERY_TIME,
"Log all queries that have taken more than long_query_time seconds to "
"execute. The argument will be treated as a decimal value with "
"microsecond precision.",
&long_query_time, &long_query_time, 0, GET_DOUBLE,
REQUIRED_ARG, 10, 0, LONG_TIMEOUT, 0, 0, 0}
说明:long_query_time的这些值,是根据结构体my_option定义的,见文件my_getopt.h,如下:
struct my_option
{
const char *name; /* 参数名 */
int id; /* 参数id或参数名简称 */
const char *comment; /* 注释 */
void *value; /* 参数值 */
void *u_max_value; /* The user def. max variable value */
struct st_typelib *typelib; /* Pointer to possible values */
ulong var_type; /* Must match the variable type */
enum get_opt_arg_type arg_type;
longlong def_value; /* 默认值 */
longlong min_value; /* Min allowed value */
longlong max_value; /* Max allowed value */
longlong sub_size; /* Subtract this from given value */
long block_size; /* Value should be a mult. of this */
void *app_type; /* To be used by an application */
};
第二步:变化比较大。在sql_parse.cc中搜索log_slow_statement方法:- void log_slow_statement(THD *thd)
- {
- DBUG_ENTER("log_slow_statement");
- /*
- The following should never be true with our current code base,
- but better to keep this here so we don't accidently try to log a
- statement in a trigger or stored function
- */
- if (unlikely(thd->in_sub_stmt))
- DBUG_VOID_RETURN; // Don't set time for sub stmt
- /*
- Do not log administrative statements unless the appropriate option is
- set.
- */
- if (thd->enable_slow_log)
- {
- ulonglong end_utime_of_query= thd->current_utime();
- thd_proc_info(thd, "logging slow query");
- if (((end_utime_of_query - thd->utime_after_lock) >
- thd->variables.long_query_time ||
- ((thd->server_status &
- (SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) &&
- opt_log_queries_not_using_indexes &&
- !(sql_command_flags[thd->lex->sql_command] & CF_STATUS_COMMAND))) &&
- thd->examined_row_count >= thd->variables.min_examined_row_limit)
- {
- thd_proc_info(thd, "logging slow query");
- thd->status_var.long_query_count++;
- slow_log_print(thd, thd->query(), thd->query_length(),
- end_utime_of_query);
- }
- }
- DBUG_VOID_RETURN;
- }
复制代码 修改if中的第一个条件中end_utime_of_query - thd->utime_after_lock) > thd->variables.long_query_time为end_utime_of_query - thd->utime_after_lock) >= thd->variables.long_query_time
其它说明见lz的说明。。。 |
|