diff options
author | Monty <monty@mariadb.org> | 2014-08-03 15:26:47 +0300 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2014-08-09 13:22:01 +0300 |
commit | e2b2bde358f434d945e9730acfbc6eedeb9ab8a2 (patch) | |
tree | f7309ce86e95b4f4bd20e84065fe892e83a0f625 /sql | |
parent | 7375f025ee9cd39909c1ec5529ca8c4007b92368 (diff) | |
download | mariadb-git-e2b2bde358f434d945e9730acfbc6eedeb9ab8a2.tar.gz |
Made sql_log_slow a session variable
mysqldump:
- Added --log-queries to allow one to disable logging for the dump
sql/log_event.cc:
- Removed setting of enable_slow_log as it's not required anymore.
sql/sql_parse.cc:
- Set enable_slow_log to value of thd->variables.sql_log_slow as this will speed up tests if slow log is disabled.
- opt_log_slow_admin_statements can now only disable slow log, not enable it.
sql/sql_explain.cc:
- Minor cleanup
Other things:
- Added sql_log_slow to system variables.
- Changed opt_slow_log to global_system_variables.sql_log_slow in all files
- Updated tests to reflect changes
Diffstat (limited to 'sql')
-rw-r--r-- | sql/log.cc | 18 | ||||
-rw-r--r-- | sql/log_event.cc | 13 | ||||
-rw-r--r-- | sql/mysqld.cc | 23 | ||||
-rw-r--r-- | sql/mysqld.h | 2 | ||||
-rw-r--r-- | sql/rpl_parallel.cc | 2 | ||||
-rw-r--r-- | sql/slave.cc | 2 | ||||
-rw-r--r-- | sql/sql_class.h | 7 | ||||
-rw-r--r-- | sql/sql_explain.cc | 2 | ||||
-rw-r--r-- | sql/sql_parse.cc | 11 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 2 | ||||
-rw-r--r-- | sql/sql_reload.cc | 2 | ||||
-rw-r--r-- | sql/sys_vars.cc | 14 |
12 files changed, 48 insertions, 50 deletions
diff --git a/sql/log.cc b/sql/log.cc index 75a895e25f8..d2032b0f4ab 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -517,7 +517,7 @@ bool LOGGER::is_log_table_enabled(uint log_table_type) { switch (log_table_type) { case QUERY_LOG_SLOW: - return (table_log_handler != NULL) && opt_slow_log; + return (table_log_handler != NULL) && global_system_variables.sql_log_slow; case QUERY_LOG_GENERAL: return (table_log_handler != NULL) && opt_log ; default: @@ -1048,7 +1048,7 @@ bool Log_to_file_event_handler::init() { if (!is_initialized) { - if (opt_slow_log) + if (global_system_variables.sql_log_slow) mysql_slow_log.open_slow_log(opt_slow_logname); if (opt_log) @@ -1072,7 +1072,7 @@ void Log_to_file_event_handler::flush() /* reopen log files */ if (opt_log) mysql_log.reopen_file(); - if (opt_slow_log) + if (global_system_variables.sql_log_slow) mysql_slow_log.reopen_file(); } @@ -1200,7 +1200,7 @@ bool LOGGER::flush_slow_log() logger.lock_exclusive(); /* Reopen slow log file */ - if (opt_slow_log) + if (global_system_variables.sql_log_slow) file_log_handler->get_mysql_slow_log()->reopen_file(); /* End of log flush */ @@ -1270,11 +1270,11 @@ bool LOGGER::slow_log_print(THD *thd, const char *query, uint query_length, if (*slow_log_handler_list) { /* do not log slow queries from replication threads */ - if (thd->slave_thread && !opt_log_slow_slave_statements) + if (!thd->variables.sql_log_slow) return 0; lock_shared(); - if (!opt_slow_log) + if (!global_system_variables.sql_log_slow) { unlock(); return 0; @@ -1448,7 +1448,7 @@ bool LOGGER::activate_log_handler(THD* thd, uint log_type) lock_exclusive(); switch (log_type) { case QUERY_LOG_SLOW: - if (!opt_slow_log) + if (!global_system_variables.sql_log_slow) { file_log= file_log_handler->get_mysql_slow_log(); @@ -1462,7 +1462,7 @@ bool LOGGER::activate_log_handler(THD* thd, uint log_type) else { init_slow_log(log_output_options); - opt_slow_log= TRUE; + global_system_variables.sql_log_slow= TRUE; } } break; @@ -1501,7 +1501,7 @@ void LOGGER::deactivate_log_handler(THD *thd, uint log_type) switch (log_type) { case QUERY_LOG_SLOW: - tmp_opt= &opt_slow_log; + tmp_opt= &global_system_variables.sql_log_slow; file_log= file_log_handler->get_mysql_slow_log(); break; case QUERY_LOG_GENERAL: diff --git a/sql/log_event.cc b/sql/log_event.cc index 6a85893803e..27dddb69144 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -4280,6 +4280,7 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, THD_STAGE_INFO(thd, stage_init); MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi, thd->query(), thd->query_length()); + thd->enable_slow_log= thd->variables.sql_log_slow; mysql_parse(thd, thd->query(), thd->query_length(), &parser_state); /* Finalize server status flags after executing a statement. */ thd->update_server_status(); @@ -4287,18 +4288,6 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, } thd->variables.option_bits&= ~OPTION_MASTER_SQL_ERROR; - - /* - Resetting the enable_slow_log thd variable. - - We need to reset it back to the opt_log_slow_slave_statements - value after the statement execution (and slow logging - is done). It might have changed if the statement was an - admin statement (in which case, down in mysql_parse execution - thd->enable_slow_log is set to the value of - opt_log_slow_admin_statements). - */ - thd->enable_slow_log= opt_log_slow_slave_statements; } else { diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 066dae224eb..e420a70b33f 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -373,7 +373,7 @@ static DYNAMIC_ARRAY all_options; /* Global variables */ bool opt_bin_log, opt_bin_log_used=0, opt_ignore_builtin_innodb= 0; -my_bool opt_log, opt_slow_log, debug_assert_if_crashed_table= 0, opt_help= 0; +my_bool opt_log, debug_assert_if_crashed_table= 0, opt_help= 0; static my_bool opt_abort; ulonglong log_output_options; my_bool opt_userstat_running; @@ -3329,7 +3329,7 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused))) sql_print_information("Got signal %d to shutdown mysqld",sig); #endif /* switch to the old log message processing */ - logger.set_handlers(LOG_FILE, opt_slow_log ? LOG_FILE:LOG_NONE, + logger.set_handlers(LOG_FILE, global_system_variables.sql_log_slow ? LOG_FILE:LOG_NONE, opt_log ? LOG_FILE:LOG_NONE); DBUG_PRINT("info",("Got signal: %d abort_loop: %d",sig,abort_loop)); if (!abort_loop) @@ -3367,13 +3367,15 @@ pthread_handler_t signal_hand(void *arg __attribute__((unused))) if (log_output_options & LOG_NONE) { logger.set_handlers(LOG_FILE, - opt_slow_log ? LOG_TABLE : LOG_NONE, + global_system_variables.sql_log_slow ? + LOG_TABLE : LOG_NONE, opt_log ? LOG_TABLE : LOG_NONE); } else { logger.set_handlers(LOG_FILE, - opt_slow_log ? log_output_options : LOG_NONE, + global_system_variables.sql_log_slow ? + log_output_options : LOG_NONE, opt_log ? log_output_options : LOG_NONE); } break; @@ -4263,7 +4265,8 @@ static int init_common_variables() "--log option, log tables are used. " "To enable logging to files use the --log-output option."); - if (opt_slow_log && opt_slow_logname && *opt_slow_logname && + if (global_system_variables.sql_log_slow && opt_slow_logname && + *opt_slow_logname && !(log_output_options & (LOG_FILE | LOG_NONE))) sql_print_warning("Although a path was specified for the " "--log-slow-queries option, log tables are used. " @@ -4904,7 +4907,9 @@ a file name for --log-bin-index option", opt_binlog_index_name); /* purecov: end */ } - logger.set_handlers(LOG_FILE, opt_slow_log ? log_output_options:LOG_NONE, + logger.set_handlers(LOG_FILE, + global_system_variables.sql_log_slow ? + log_output_options:LOG_NONE, opt_log ? log_output_options:LOG_NONE); } @@ -8123,7 +8128,7 @@ static int mysql_init_variables(void) /* We can only test for sub paths if my_symlink.c is using realpath */ myisam_test_invalid_symlink= test_if_data_home_dir; #endif - opt_log= opt_slow_log= 0; + opt_log= 0; opt_bin_log= opt_bin_log_used= 0; opt_disable_networking= opt_skip_show_db=0; opt_skip_name_resolve= 0; @@ -8818,7 +8823,7 @@ static int get_options(int *argc_ptr, char ***argv_ptr) if ((opt_log_slow_admin_statements || opt_log_queries_not_using_indexes || opt_log_slow_slave_statements) && - !opt_slow_log) + !global_system_variables.sql_log_slow) sql_print_warning("options --log-slow-admin-statements, --log-queries-not-using-indexes and --log-slow-slave-statements have no effect if --log_slow_queries is not set"); if (global_system_variables.net_buffer_length > global_system_variables.max_allowed_packet) @@ -9033,7 +9038,7 @@ void set_server_version(void) if (!strstr(MYSQL_SERVER_SUFFIX_STR, "-debug")) end= strmov(end, "-debug"); #endif - if (opt_log || opt_slow_log || opt_bin_log) + if (opt_log || global_system_variables.sql_log_slow || opt_bin_log) strmov(end, "-log"); // This may slow down system } diff --git a/sql/mysqld.h b/sql/mysqld.h index a1656a49047..21c020b8b5e 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -80,7 +80,7 @@ extern CHARSET_INFO *character_set_filesystem; extern MY_BITMAP temp_pool; extern bool opt_large_files, server_id_supplied; extern bool opt_update_log, opt_bin_log, opt_error_log; -extern my_bool opt_log, opt_slow_log, opt_bootstrap; +extern my_bool opt_log, opt_bootstrap; extern my_bool opt_backup_history_log; extern my_bool opt_backup_progress_log; extern ulonglong log_output_options; diff --git a/sql/rpl_parallel.cc b/sql/rpl_parallel.cc index e72d3470a7f..90ee2360eb7 100644 --- a/sql/rpl_parallel.cc +++ b/sql/rpl_parallel.cc @@ -235,7 +235,7 @@ handle_rpl_parallel_thread(void *arg) thd->security_ctx->skip_grants(); thd->variables.max_allowed_packet= slave_max_allowed_packet; thd->slave_thread= 1; - thd->enable_slow_log= opt_log_slow_slave_statements; + thd->variables.sql_log_slow= opt_log_slow_slave_statements; thd->variables.log_slow_filter= global_system_variables.log_slow_filter; set_slave_thread_options(thd); thd->client_capabilities = CLIENT_LOCAL_FILES; diff --git a/sql/slave.cc b/sql/slave.cc index f7d019a6c39..bb90d24b0bb 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -2922,7 +2922,7 @@ static int init_slave_thread(THD* thd, Master_info *mi, thd->security_ctx->skip_grants(); thd->slave_thread= 1; thd->connection_name= mi->connection_name; - thd->enable_slow_log= opt_log_slow_slave_statements; + thd->variables.sql_log_slow= opt_log_slow_slave_statements; thd->variables.log_slow_filter= global_system_variables.log_slow_filter; set_slave_thread_options(thd); thd->client_capabilities = CLIENT_LOCAL_FILES; diff --git a/sql/sql_class.h b/sql/sql_class.h index f3537086132..f96110e0b0f 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -567,9 +567,6 @@ typedef struct system_variables ulong log_slow_rate_limit; ulong binlog_format; ///< binlog format for this thd (see enum_binlog_format) ulong progress_report_time; - my_bool binlog_annotate_row_events; - my_bool binlog_direct_non_trans_update; - my_bool sql_log_bin; ulong completion_type; ulong query_cache_type; ulong tx_isolation; @@ -608,6 +605,10 @@ typedef struct system_variables my_bool old_passwords; my_bool big_tables; my_bool query_cache_strip_comments; + my_bool sql_log_slow; + my_bool sql_log_bin; + my_bool binlog_annotate_row_events; + my_bool binlog_direct_non_trans_update; plugin_ref table_plugin; plugin_ref tmp_table_plugin; diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index 9df4fd965a5..53ac095d1d0 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -1006,8 +1006,10 @@ int Explain_insert::print_explain(Explain_query *query, void delete_explain_query(LEX *lex) { + DBUG_ENTER("delete_explain_query"); delete lex->explain; lex->explain= NULL; + DBUG_VOID_RETURN; } diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 019fd55e3d8..1da595858b3 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1131,7 +1131,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, Commands which always take a long time are logged into the slow log only if opt_log_slow_admin_statements is set. */ - thd->enable_slow_log= TRUE; + thd->enable_slow_log= thd->variables.sql_log_slow; thd->query_plan_flags= QPLAN_INIT; thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */ @@ -1516,7 +1516,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, status_var_increment(thd->status_var.com_other); - thd->enable_slow_log= opt_log_slow_admin_statements; + thd->enable_slow_log&= opt_log_slow_admin_statements; thd->query_plan_flags|= QPLAN_ADMIN; if (check_global_access(thd, REPL_SLAVE_ACL)) break; @@ -1784,7 +1784,6 @@ 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 @@ -1795,12 +1794,10 @@ void log_slow_statement(THD *thd) /* Follow the slow log filter configuration. */ - if (!thd->enable_slow_log || + if (!thd->enable_slow_log || !global_system_variables.sql_log_slow || (thd->variables.log_slow_filter && !(thd->variables.log_slow_filter & thd->query_plan_flags))) - { goto end; - } if (((thd->server_status & SERVER_QUERY_WAS_SLOW) || ((thd->server_status & @@ -3060,7 +3057,7 @@ end_with_restore_list: and thus classify as slow administrative statements just like ALTER TABLE. */ - thd->enable_slow_log= opt_log_slow_admin_statements; + thd->enable_slow_log&= opt_log_slow_admin_statements; thd->query_plan_flags|= QPLAN_ADMIN; bzero((char*) &create_info, sizeof(create_info)); diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index ebceae70ee5..9ea496a81dc 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -3205,7 +3205,7 @@ void Prepared_statement::setup_set_params() because we want to look it up in the query cache) or not. */ if ((mysql_bin_log.is_open() && is_update_query(lex->sql_command)) || - opt_log || opt_slow_log || + opt_log || thd->variables.sql_log_slow || query_cache_is_cacheable_query(lex)) { set_params_from_vars= insert_params_from_vars_with_log; diff --git a/sql/sql_reload.cc b/sql/sql_reload.cc index bb3d5bb899a..10ff6dee31f 100644 --- a/sql/sql_reload.cc +++ b/sql/sql_reload.cc @@ -130,7 +130,7 @@ bool reload_acl_and_cache(THD *thd, unsigned long long options, result= 1; } - if ((options & REFRESH_SLOW_LOG) && opt_slow_log) + if ((options & REFRESH_SLOW_LOG) && global_system_variables.sql_log_slow) logger.flush_slow_log(); if ((options & REFRESH_GENERAL_LOG) && opt_log) diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 9495d16247d..7f7c725afc7 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -3841,7 +3841,7 @@ static void reopen_slow_log(char* name) static bool fix_slow_log_file(sys_var *self, THD *thd, enum_var_type type) { return fix_log(&opt_slow_logname, opt_log_basename, "-slow.log", - opt_slow_log, reopen_slow_log); + global_system_variables.sql_log_slow, reopen_slow_log); } static Sys_var_charptr Sys_slow_log_path( "slow_query_log_file", "Log slow queries to given log file. " @@ -3892,6 +3892,7 @@ static Sys_var_have Sys_have_symlink( READ_ONLY GLOBAL_VAR(have_symlink), NO_CMD_LINE); static bool fix_log_state(sys_var *self, THD *thd, enum_var_type type); + static Sys_var_mybool Sys_general_log( "general_log", "Log connections and queries to a table or log file. " "Defaults logging to a file 'hostname'.log or a table mysql.general_log" @@ -3905,9 +3906,9 @@ static Sys_var_mybool Sys_slow_query_log( "Log slow queries to a table or log file. Defaults logging to a file " "'hostname'-slow.log or a table mysql.slow_log if --log-output=TABLE is " "used. Must be enabled to activate other slow log options", - GLOBAL_VAR(opt_slow_log), CMD_LINE(OPT_ARG), - DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), - ON_UPDATE(fix_log_state)); + SESSION_VAR(sql_log_slow), CMD_LINE(OPT_ARG), + DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, + ON_CHECK(0), ON_UPDATE(fix_log_state)); static bool fix_log_state(sys_var *self, THD *thd, enum_var_type type) { @@ -3915,6 +3916,9 @@ static bool fix_log_state(sys_var *self, THD *thd, enum_var_type type) my_bool *UNINIT_VAR(newvalptr), newval, UNINIT_VAR(oldval); uint UNINIT_VAR(log_type); + if (type != OPT_GLOBAL) + return 0; + if (self == &Sys_general_log) { newvalptr= &opt_log; @@ -3923,7 +3927,7 @@ static bool fix_log_state(sys_var *self, THD *thd, enum_var_type type) } else if (self == &Sys_slow_query_log) { - newvalptr= &opt_slow_log; + newvalptr= &global_system_variables.sql_log_slow; oldval= logger.get_slow_log_file_handler()->is_open(); log_type= QUERY_LOG_SLOW; } |