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
This commit is contained in:
Monty 2014-08-03 15:26:47 +03:00
parent 7375f025ee
commit e2b2bde358
21 changed files with 147 additions and 71 deletions

View File

@ -39,7 +39,7 @@
** 10 Jun 2003: SET NAMES and --no-set-names by Alexander Barkov
*/
#define DUMP_VERSION "10.15"
#define DUMP_VERSION "10.16"
#include <my_global.h>
#include <my_sys.h>
@ -111,7 +111,7 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0,
opt_slave_apply= 0,
opt_include_master_host_port= 0,
opt_events= 0, opt_comments_used= 0,
opt_alltspcs=0, opt_notspcs= 0;
opt_alltspcs=0, opt_notspcs= 0, opt_logging;
static my_bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0;
static ulong opt_max_allowed_packet, opt_net_buffer_length;
static MYSQL mysql_connection,*mysql=0;
@ -381,6 +381,8 @@ static struct my_option my_long_options[] =
{"log-error", OPT_ERROR_LOG_FILE, "Append warnings and errors to given file.",
&log_error_file, &log_error_file, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"log-queries", 0, "When restoring the dump, the server will, if logging turned on, log the queries to the general and slow query log.",
&opt_logging, &opt_logging, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"master-data", OPT_MASTER_DATA,
"This causes the binary log position and filename to be appended to the "
"output. If equal to 1, will print it as a CHANGE MASTER command; if equal"
@ -663,6 +665,10 @@ static void write_header(FILE *sql_file, char *db_name)
print_comment(sql_file, 0, "-- Server version\t%s\n",
mysql_get_server_info(&mysql_connection));
if (!opt_logging)
fprintf(sql_file,
"\n/*M!100101 SET LOCAL SQL_LOG_OFF=0, LOCAL SLOW_QUERY_LOG=0 */;");
if (opt_set_charset)
fprintf(sql_file,
"\n/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;"

View File

@ -42,6 +42,7 @@ select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
start_time user_host query_time lock_time rows_sent rows_examined db last_insert_id insert_id server_id sql_text thread_id
# Switch to connection default
set global slow_query_log= ON;
set local slow_query_log= ON;
# Switch to connection con1
set session long_query_time = @long_query_time;
select sleep(@long_query_time + 1);
@ -49,7 +50,13 @@ sleep(@long_query_time + 1)
0
select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
start_time user_host query_time lock_time rows_sent rows_examined db last_insert_id insert_id server_id sql_text thread_id
TIMESTAMP USER_HOST QUERY_TIME 00:00:00.000000 1 0 test 0 0 1 select sleep(@long_query_time + 1) THREAD_ID
set local slow_query_log= ON;
select sleep(@long_query_time + 2);
sleep(@long_query_time + 2)
0
select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
start_time user_host query_time lock_time rows_sent rows_examined db last_insert_id insert_id server_id sql_text thread_id
TIMESTAMP USER_HOST QUERY_TIME 00:00:00.000000 1 0 test 0 0 1 select sleep(@long_query_time + 2) THREAD_ID
# Switch to connection default
show global variables
where Variable_name = 'general_log' or Variable_name = 'slow_query_log';
@ -62,6 +69,7 @@ set global general_log= OFF;
set global slow_query_log= ON;
set global slow_query_log= OFF;
set global slow_query_log= OFF;
set local slow_query_log= ON;
set global general_log= ON;
truncate table mysql.general_log;
create table t1(f1 int);
@ -124,6 +132,9 @@ Variable_name Value
general_log OFF
show variables like 'slow_query_log';
Variable_name Value
slow_query_log ON
show global variables like 'slow_query_log';
Variable_name Value
slow_query_log OFF
set global general_log=ON;
set global log_output=default;

View File

@ -5290,3 +5290,13 @@ Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
#
# Test mysqldump with --disable-query-logs
#
create table t1 (a int);
insert into t1 values (1);
drop table t1;
select * from t1;
a
1
drop table t1;

View File

@ -42,10 +42,17 @@ ERROR 42000: Variable 'slow_query_log' can't be set to the value of ' '
SET @@global.slow_query_log = '';
ERROR 42000: Variable 'slow_query_log' can't be set to the value of ''
'#-------------------FN_DYNVARS_004_04----------------------------#'
SET @@session.slow_query_log = OFF;
ERROR HY000: Variable 'slow_query_log' is a GLOBAL variable and should be set with SET GLOBAL
SET @@global.slow_query_log = ON;
SET @@session.slow_query_log = ON;
SELECT @@session.slow_query_log;
ERROR HY000: Variable 'slow_query_log' is a GLOBAL variable
@@session.slow_query_log
1
SET @@session.slow_query_log = OFF;
SELECT @@session.slow_query_log;
@@session.slow_query_log
0
SET @@global.slow_query_log = OFF;
SET @@session.slow_query_log = ON;
'#----------------------FN_DYNVARS_004_05------------------------#'
SELECT IF(@@global.slow_query_log, "ON", "OFF") = VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
@ -72,12 +79,11 @@ SELECT @@global.slow_query_log;
0
'#---------------------FN_DYNVARS_004_08----------------------#'
SET @@global.slow_query_log = ON;
SET @@local.slow_query_log = OFF;
SELECT @@slow_query_log = @@global.slow_query_log;
@@slow_query_log = @@global.slow_query_log
1
0
'#---------------------FN_DYNVARS_004_09----------------------#'
SET slow_query_log = ON;
ERROR HY000: Variable 'slow_query_log' is a GLOBAL variable and should be set with SET GLOBAL
SET local.slow_query_log = OFF;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'slow_query_log = OFF' at line 1
SELECT local.slow_query_log;

View File

@ -2,7 +2,7 @@ SET @global_slow_query_log = @@global.slow_query_log;
SET @global_log_output = @@global.log_output;
SET @@session.long_query_time=1;
SET @@global.log_output = 'TABLE';
'----When slow_query_log = OFF----'
'----When global.slow_query_log = OFF----'
SET @@global.slow_query_log = OFF;
TRUNCATE mysql.slow_log;
SELECT sleep(2);
@ -11,7 +11,7 @@ sleep(2)
SELECT count(*) FROM mysql.slow_log;
count(*)
0
'----When slow_query_log = ON-----'
'----When global.slow_query_log = ON-----'
SET @@global.slow_query_log = ON;
TRUNCATE mysql.slow_log;
SELECT sleep(2);
@ -20,6 +20,16 @@ sleep(2)
SELECT count(*) > 0 FROM mysql.slow_log;
count(*) > 0
1
'----When local.slow_query_log = OFF-----'
SET @@local.slow_query_log = OFF;
TRUNCATE mysql.slow_log;
SELECT sleep(2);
sleep(2)
0
SELECT count(*) FROM mysql.slow_log;
count(*)
0
SET @@local.slow_query_log = ON;
'Bug#47905 stored procedures not logged correctly to slow query log'
TRUNCATE mysql.slow_log;
CREATE PROCEDURE p_test()

View File

@ -90,14 +90,16 @@ SET @@global.slow_query_log = '';
--echo '#-------------------FN_DYNVARS_004_04----------------------------#'
##################################################################
# Test if accessing session slow_query_log gives error #
# Test that accessing session slow_query_log dows not give #
##################################################################
--Error ER_GLOBAL_VARIABLE
SET @@session.slow_query_log = OFF;
--Error ER_INCORRECT_GLOBAL_LOCAL_VAR
SET @@global.slow_query_log = ON;
SET @@session.slow_query_log = ON;
SELECT @@session.slow_query_log;
SET @@session.slow_query_log = OFF;
SELECT @@session.slow_query_log;
SET @@global.slow_query_log = OFF;
SET @@session.slow_query_log = ON;
--echo '#----------------------FN_DYNVARS_004_05------------------------#'
##############################################################################
@ -132,18 +134,17 @@ SELECT @@global.slow_query_log;
--echo '#---------------------FN_DYNVARS_004_08----------------------#'
##############################################################################
# Check if accessing variable with SESSION,LOCAL and without SCOPE points #
# to same session variable #
# to same session variable (doesn't) #
##############################################################################
SET @@global.slow_query_log = ON;
SET @@local.slow_query_log = OFF;
SELECT @@slow_query_log = @@global.slow_query_log;
--echo '#---------------------FN_DYNVARS_004_09----------------------#'
######################################################################
# Check if slow_query_log can be accessed with and without @@ sign #
######################################################################
--Error ER_GLOBAL_VARIABLE
SET slow_query_log = ON;
--Error ER_PARSE_ERROR
SET local.slow_query_log = OFF;
--Error ER_UNKNOWN_TABLE

View File

@ -10,7 +10,7 @@ SET @@session.long_query_time=1;
SET @@global.log_output = 'TABLE';
#=========================================
--echo '----When slow_query_log = OFF----'
--echo '----When global.slow_query_log = OFF----'
#=========================================
SET @@global.slow_query_log = OFF;
@ -21,7 +21,7 @@ SELECT sleep(2);
SELECT count(*) FROM mysql.slow_log;
#=========================================
--echo '----When slow_query_log = ON-----'
--echo '----When global.slow_query_log = ON-----'
#=========================================
SET @@global.slow_query_log = ON;
@ -31,6 +31,17 @@ SELECT sleep(2);
SELECT count(*) > 0 FROM mysql.slow_log;
#=========================================
--echo '----When local.slow_query_log = OFF-----'
#=========================================
SET @@local.slow_query_log = OFF;
TRUNCATE mysql.slow_log;
# The sleep is the slow query
SELECT sleep(2);
SELECT count(*) FROM mysql.slow_log;
SET @@local.slow_query_log = ON;
#==========================================================================
--echo 'Bug#47905 stored procedures not logged correctly to slow query log'

View File

@ -52,12 +52,18 @@ select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
connection default;
set global slow_query_log= ON;
set local slow_query_log= ON;
--echo # Switch to connection con1
connection con1;
set session long_query_time = @long_query_time;
select sleep(@long_query_time + 1);
--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME 12 THREAD_ID
select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
set local slow_query_log= ON;
select sleep(@long_query_time + 2);
--replace_column 1 TIMESTAMP 2 USER_HOST 3 QUERY_TIME 12 THREAD_ID
select * from mysql.slow_log where sql_text NOT LIKE '%slow_log%';
--echo # Switch to connection default
connection default;
show global variables
@ -69,6 +75,7 @@ set global general_log= OFF;
set global slow_query_log= ON;
set global slow_query_log= OFF;
set global slow_query_log= OFF;
set local slow_query_log= ON;
set global general_log= ON;
truncate table mysql.general_log;
@ -127,6 +134,7 @@ set global general_log_file= default;
set global slow_query_log_file= default;
show variables like 'general_log';
show variables like 'slow_query_log';
show global variables like 'slow_query_log';
set global general_log=ON;
set global log_output=default;
show variables like 'log_output';

View File

@ -2473,3 +2473,18 @@ drop table t1, t2;
--exec $MYSQL_DUMP --user=foo 2>&1 > $MYSQLTEST_VARDIR/tmp/bug6056.out
--exec $MYSQL_DUMP --help > $MYSQLTEST_VARDIR/tmp/bug6056.out
--echo #
--echo # Test mysqldump with --disable-query-logs
--echo #
create table t1 (a int);
insert into t1 values (1);
--exec $MYSQL_DUMP --hex-blob --character-sets-dir=$MYSQL_SHAREDIR/charsets --tab=$MYSQLTEST_VARDIR/tmp/ test t1
--exec $MYSQL_DUMP --disable-log-queries --skip-comments test t1 >$MYSQLTEST_VARDIR/tmp/mysqldump-test.out
drop table t1;
--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/mysqldump-test.out
select * from t1;
drop table t1;
--remove_file $MYSQLTEST_VARDIR/tmp/mysqldump-test.out

View File

@ -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:

View File

@ -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
{

View File

@ -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
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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));

View File

@ -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;

View File

@ -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)

View File

@ -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;
}