diff options
-rw-r--r-- | mysql-test/r/log_slow.result | 2 | ||||
-rw-r--r-- | mysql-test/suite/rpl/r/rpl_slow_query_log.result | 15 | ||||
-rw-r--r-- | mysql-test/suite/rpl/t/rpl_slow_query_log.test | 33 | ||||
-rw-r--r-- | mysql-test/suite/sys_vars/r/log_slow_admin_statements_func.result | 46 | ||||
-rw-r--r-- | mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result | 28 | ||||
-rw-r--r-- | mysql-test/suite/sys_vars/t/log_slow_admin_statements_func.test | 61 | ||||
-rw-r--r-- | sql/log_event.cc | 9 | ||||
-rw-r--r-- | sql/mysqld.cc | 8 | ||||
-rw-r--r-- | sql/sys_vars.cc | 13 |
9 files changed, 207 insertions, 8 deletions
diff --git a/mysql-test/r/log_slow.result b/mysql-test/r/log_slow.result index f7670f3d3db..6a3f48506e3 100644 --- a/mysql-test/r/log_slow.result +++ b/mysql-test/r/log_slow.result @@ -9,8 +9,10 @@ select @@log_slow_verbosity; show variables like "log_slow%"; Variable_name Value +log_slow_admin_statements OFF log_slow_filter admin,filesort,filesort_on_disk,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk log_slow_rate_limit 1 +log_slow_slave_statements OFF log_slow_verbosity set @org_slow_query_log= @@global.slow_query_log; set @@log_slow_filter= "filesort,filesort_on_disk,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk,admin"; diff --git a/mysql-test/suite/rpl/r/rpl_slow_query_log.result b/mysql-test/suite/rpl/r/rpl_slow_query_log.result index 79b83b4ceb9..2de0f5ccd82 100644 --- a/mysql-test/suite/rpl/r/rpl_slow_query_log.result +++ b/mysql-test/suite/rpl/r/rpl_slow_query_log.result @@ -76,6 +76,21 @@ ALTER TABLE t1 ADD INDEX id1(a); INSERT INTO t1 values(1, sleep(3)); ### Assertion is good. Both Master and Slave exhibit the ### same number of queries in slow log: 1 +******************************************************************** +**** TRUNCATE the slow log then check whether runtime changes of +**** log_slow_slave_statements work without slave restart. +******************************************************************** +SET @old_log_slow_slave_statements= @@global.log_slow_slave_statements; +SET @@global.log_slow_slave_statements = off; +TRUNCATE mysql.slow_log; +INSERT INTO t1 values(1, sleep(3));; +SELECT sql_text FROM mysql.slow_log WHERE sql_text like 'INSERT INTO t1 values(1, sleep(3))'; +sql_text +SET @@global.log_slow_slave_statements = on; +INSERT INTO t1 values(1, sleep(3));; +SELECT sql_text FROM mysql.slow_log WHERE sql_text like 'INSERT INTO t1 values(1, sleep(3))'; +sql_text +INSERT INTO t1 values(1, sleep(3)) SET @@global.log_output= @old_log_output; SET @@global.long_query_time= @old_long_query_time; DROP TABLE t1; diff --git a/mysql-test/suite/rpl/t/rpl_slow_query_log.test b/mysql-test/suite/rpl/t/rpl_slow_query_log.test index faf037a9dff..3505883c58e 100644 --- a/mysql-test/suite/rpl/t/rpl_slow_query_log.test +++ b/mysql-test/suite/rpl/t/rpl_slow_query_log.test @@ -299,6 +299,39 @@ if ($master_slow_query == $slave_slow_query) -- echo ### same number of queries in slow log: $master_slow_query } +-- echo ******************************************************************** +-- echo **** TRUNCATE the slow log then check whether runtime changes of +-- echo **** log_slow_slave_statements work without slave restart. +-- echo ******************************************************************** + +SET @old_log_slow_slave_statements= @@global.log_slow_slave_statements; +SET @@global.log_slow_slave_statements = off; +TRUNCATE mysql.slow_log; + +-- connection master + +--disable_warnings +-- eval $slow_query; +--enable_warnings +sync_slave_with_master; + +-- connection slave + +eval SELECT sql_text FROM mysql.slow_log WHERE sql_text like '$slow_query'; + +SET @@global.log_slow_slave_statements = on; + +-- connection master + +--disable_warnings +-- eval $slow_query; +--enable_warnings +sync_slave_with_master; + +-- connection slave + +eval SELECT sql_text FROM mysql.slow_log WHERE sql_text like '$slow_query'; + -- connection master SET @@global.log_output= @old_log_output; SET @@global.long_query_time= @old_long_query_time; diff --git a/mysql-test/suite/sys_vars/r/log_slow_admin_statements_func.result b/mysql-test/suite/sys_vars/r/log_slow_admin_statements_func.result new file mode 100644 index 00000000000..daddc4af627 --- /dev/null +++ b/mysql-test/suite/sys_vars/r/log_slow_admin_statements_func.result @@ -0,0 +1,46 @@ +SET @old_log_output= @@global.log_output; +SET @old_slow_query_log= @@global.slow_query_log; +SET @old_long_query_time= @@session.long_query_time; +SET @old_log_slow_admin_statements= @@global.log_slow_admin_statements; +USE test; +CREATE TABLE log_slow_admin_statements ( +i INT PRIMARY KEY AUTO_INCREMENT, +j VARCHAR(255) +) ENGINE=InnoDB; +SET GLOBAL log_output = 'file,table'; +SET GLOBAL slow_query_log = on; +SET SESSION long_query_time = 0; +SET GLOBAL log_slow_admin_statements = on; +ALTER TABLE log_slow_admin_statements ADD COLUMN k INT DEFAULT 17; +CREATE PROCEDURE add_rows() +BEGIN +DECLARE count INT; +SET count = 1; +INSERT INTO log_slow_admin_statements(j) values (REPEAT('A', 255)); +WHILE count <= 15 DO +INSERT INTO log_slow_admin_statements(j) SELECT j FROM log_slow_admin_statements; +SET count = count + 1; +END WHILE; +END +$ +CALL add_rows(); +OPTIMIZE TABLE log_slow_admin_statements; +Table Op Msg_type Msg_text +test.log_slow_admin_statements optimize note Table does not support optimize, doing recreate + analyze instead +test.log_slow_admin_statements optimize status OK +CHECK TABLE log_slow_admin_statements EXTENDED; +Table Op Msg_type Msg_text +test.log_slow_admin_statements check status OK +DROP TABLE log_slow_admin_statements; +SELECT sql_text FROM mysql.slow_log WHERE sql_text LIKE '%TABLE log_slow_admin_statements%'; +sql_text +ALTER TABLE log_slow_admin_statements ADD COLUMN k INT DEFAULT 17 +OPTIMIZE TABLE log_slow_admin_statements +CHECK TABLE log_slow_admin_statements EXTENDED +DROP TABLE log_slow_admin_statements +SET @@global.log_output= @old_log_output; +SET @@global.slow_query_log= @old_slow_query_log; +SET @@session.long_query_time= @old_long_query_time; +SET @@global.log_slow_admin_statements= @old_log_slow_admin_statements; +DROP PROCEDURE add_rows; +TRUNCATE TABLE mysql.slow_log; diff --git a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result index 26e67fc2fdb..81cc32016e2 100644 --- a/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result +++ b/mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result @@ -1829,6 +1829,20 @@ NUMERIC_BLOCK_SIZE NULL ENUM_VALUE_LIST OFF,ON READ_ONLY YES COMMAND_LINE_ARGUMENT OPTIONAL +VARIABLE_NAME LOG_SLOW_ADMIN_STATEMENTS +SESSION_VALUE NULL +GLOBAL_VALUE OFF +GLOBAL_VALUE_ORIGIN COMPILE-TIME +DEFAULT_VALUE OFF +VARIABLE_SCOPE GLOBAL +VARIABLE_TYPE BOOLEAN +VARIABLE_COMMENT Log slow OPTIMIZE, ANALYZE, ALTER and other administrative statements to the slow log if it is open. +NUMERIC_MIN_VALUE NULL +NUMERIC_MAX_VALUE NULL +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST OFF,ON +READ_ONLY NO +COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME LOG_SLOW_FILTER SESSION_VALUE admin,filesort,filesort_on_disk,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk GLOBAL_VALUE admin,filesort,filesort_on_disk,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk @@ -1857,6 +1871,20 @@ NUMERIC_BLOCK_SIZE 1 ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED +VARIABLE_NAME LOG_SLOW_SLAVE_STATEMENTS +SESSION_VALUE NULL +GLOBAL_VALUE OFF +GLOBAL_VALUE_ORIGIN COMPILE-TIME +DEFAULT_VALUE OFF +VARIABLE_SCOPE GLOBAL +VARIABLE_TYPE BOOLEAN +VARIABLE_COMMENT Log slow statements executed by slave thread to the slow log if it is open. +NUMERIC_MIN_VALUE NULL +NUMERIC_MAX_VALUE NULL +NUMERIC_BLOCK_SIZE NULL +ENUM_VALUE_LIST OFF,ON +READ_ONLY NO +COMMAND_LINE_ARGUMENT OPTIONAL VARIABLE_NAME LOG_SLOW_VERBOSITY SESSION_VALUE GLOBAL_VALUE diff --git a/mysql-test/suite/sys_vars/t/log_slow_admin_statements_func.test b/mysql-test/suite/sys_vars/t/log_slow_admin_statements_func.test new file mode 100644 index 00000000000..78e4d35f69a --- /dev/null +++ b/mysql-test/suite/sys_vars/t/log_slow_admin_statements_func.test @@ -0,0 +1,61 @@ +--source include/no_valgrind_without_big.inc +-- source include/have_innodb.inc + +SET @old_log_output= @@global.log_output; +SET @old_slow_query_log= @@global.slow_query_log; +SET @old_long_query_time= @@session.long_query_time; +SET @old_log_slow_admin_statements= @@global.log_slow_admin_statements; + +USE test; +CREATE TABLE log_slow_admin_statements ( + i INT PRIMARY KEY AUTO_INCREMENT, + j VARCHAR(255) +) ENGINE=InnoDB; + +# enable slow logging to table +SET GLOBAL log_output = 'file,table'; +SET GLOBAL slow_query_log = on; +SET SESSION long_query_time = 0; +SET GLOBAL log_slow_admin_statements = on; + +# test ALTER, OPTIMIZE and CHECK against the table shown up +ALTER TABLE log_slow_admin_statements ADD COLUMN k INT DEFAULT 17; + +# add rows so OPTIMIZE and CHECK runs +DELIMITER $; + +CREATE PROCEDURE add_rows() +BEGIN + DECLARE count INT; + SET count = 1; + INSERT INTO log_slow_admin_statements(j) values (REPEAT('A', 255)); + WHILE count <= 15 DO + INSERT INTO log_slow_admin_statements(j) SELECT j FROM log_slow_admin_statements; + SET count = count + 1; + END WHILE; +END +$ + +DELIMITER ;$ + +CALL add_rows(); + +# OPTIMIZE TABLE +OPTIMIZE TABLE log_slow_admin_statements; + +# CHECK TABLE +CHECK TABLE log_slow_admin_statements EXTENDED; + +# DROP TABLE +DROP TABLE log_slow_admin_statements; + +# ALTER, OPTIMIZE, CHECK and DROP operations should be logged in slow query log. +SELECT sql_text FROM mysql.slow_log WHERE sql_text LIKE '%TABLE log_slow_admin_statements%'; + +SET @@global.log_output= @old_log_output; +SET @@global.slow_query_log= @old_slow_query_log; +SET @@session.long_query_time= @old_long_query_time; +SET @@global.log_slow_admin_statements= @old_log_slow_admin_statements; + +DROP PROCEDURE add_rows; +TRUNCATE TABLE mysql.slow_log; diff --git a/sql/log_event.cc b/sql/log_event.cc index 98165cc4797..ea0afddafbe 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -4428,6 +4428,15 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, if (thd->m_digest != NULL) thd->m_digest->reset(thd->m_token_array, max_digest_length); + if (thd->slave_thread) + { + /* + The opt_log_slow_slave_statements variable can be changed + dynamically, so we have to set the sql_log_slow respectively. + */ + thd->variables.sql_log_slow= opt_log_slow_slave_statements; + } + 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. */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index ac433853c2f..ced922536fc 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -7372,14 +7372,6 @@ struct my_option my_long_options[]= "Don't log extra information to update and slow-query logs.", &opt_short_log_format, &opt_short_log_format, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"log-slow-admin-statements", 0, - "Log slow OPTIMIZE, ANALYZE, ALTER and other administrative statements to " - "the slow log if it is open.", &opt_log_slow_admin_statements, - &opt_log_slow_admin_statements, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"log-slow-slave-statements", 0, - "Log slow statements executed by slave thread to the slow log if it is open.", - &opt_log_slow_slave_statements, &opt_log_slow_slave_statements, - 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"log-tc", 0, "Path to transaction coordinator log (used for transactions that affect " "more than one storage engine, when binary log is disabled).", diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 403b6a5bec7..e3ff327404f 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -1183,6 +1183,19 @@ static Sys_var_mybool Sys_log_queries_not_using_indexes( GLOBAL_VAR(opt_log_queries_not_using_indexes), CMD_LINE(OPT_ARG), DEFAULT(FALSE)); +static Sys_var_mybool Sys_log_slow_admin_statements( + "log_slow_admin_statements", + "Log slow OPTIMIZE, ANALYZE, ALTER and other administrative statements to " + "the slow log if it is open.", + GLOBAL_VAR(opt_log_slow_admin_statements), + CMD_LINE(OPT_ARG), DEFAULT(FALSE)); + +static Sys_var_mybool Sys_log_slow_slave_statements( + "log_slow_slave_statements", + "Log slow statements executed by slave thread to the slow log if it is open.", + GLOBAL_VAR(opt_log_slow_slave_statements), + CMD_LINE(OPT_ARG), DEFAULT(FALSE)); + static Sys_var_ulong Sys_log_warnings( "log_warnings", "Log some not critical warnings to the general log file." |