2
# BUG#23300: Slow query log on slave does not log slow replicated statements
5
# The slave should log slow queries replicated from master when
6
# --log-slow-slave-statements is used.
8
# Test is implemented as follows:
10
# ii) On slave, set long_query_time to a small value.
11
# ii) start slave so that long_query_time variable is picked by sql thread
12
# iii) On master, do one short time query and one long time query, on slave
13
# and check that slow query is logged to slow query log but fast query
15
# iv) On slave, check that slow queries go into the slow log and fast dont,
16
# when issued through a regular client connection
17
# v) On slave, check that slow queries go into the slow log and fast dont
18
# when we use SET TIMESTAMP= 1 on a regular client connection.
19
# vi) check that when setting slow_query_log= OFF in a connection 'extra2'
20
# prevents logging slow queries in a connection 'extra'
23
# This test only runs for statement binlogging format because on row format
24
# slow queries do not get slow query logged.
25
# Note that due to the sleep() command the insert is written to the binary
28
source include/master-slave.inc;
29
source include/have_binlog_format_statement.inc;
31
CALL mtr.add_suppression("Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT");
33
# Prepare slave for different long_query_time we need to stop the slave
34
# and restart it as long_query_time variable is dynamic and, after
35
# setting it, it only takes effect on new connections.
38
# http://dev.mysql.com/doc/refman/6.0/en/set-option.html
41
source include/stop_slave.inc;
43
SET @old_log_output= @@log_output;
44
SET GLOBAL log_output= 'TABLE';
45
SET @old_long_query_time= @@long_query_time;
46
SET GLOBAL long_query_time= 2;
47
TRUNCATE mysql.slow_log;
49
source include/start_slave.inc;
52
CREATE TABLE t1 (a int, b int);
55
# check that slave logs the slow query to the slow log, but not the fast one.
57
let $slow_query= INSERT INTO t1 values(1, sleep(3));
58
let $fast_query= INSERT INTO t1 values(1, 1);
64
sync_slave_with_master;
66
let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
67
let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
69
if ($found_fast_query)
71
SELECT * FROM mysql.slow_log;
72
die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
75
if (!$found_slow_query)
77
SELECT * FROM mysql.slow_log;
78
die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
80
TRUNCATE mysql.slow_log;
82
# regular checks for slow query log (using a new connection - 'extra' - to slave)
85
# when using direct connections to the slave, check that slow query is logged
86
# but not the fast one.
88
connect(extra,127.0.0.1,root,,test,$SLAVE_MYPORT);
91
let $fast_query= SELECT 1;
92
let $slow_query= SELECT 1, sleep(3);
97
let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
98
let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
100
if ($found_fast_query)
102
SELECT * FROM mysql.slow_log;
103
die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
106
if (!$found_slow_query)
108
SELECT * FROM mysql.slow_log;
109
die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
111
TRUNCATE mysql.slow_log;
114
# when using direct connections to the slave, check that when setting timestamp to 1 the
115
# slow query is logged but the fast one is not.
117
let $fast_query= SELECT 2;
118
let $slow_query= SELECT 2, sleep(3);
124
let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
125
let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
127
if ($found_fast_query)
129
SELECT * FROM mysql.slow_log;
130
die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
133
if (!$found_slow_query)
135
SELECT * FROM mysql.slow_log;
136
die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
138
TRUNCATE mysql.slow_log;
141
# check that when setting the slow_query_log= OFF on connection 'extra2'
142
# prevents connection 'extra' from logging to slow query log.
144
let $fast_query= SELECT 3;
145
let $slow_query= SELECT 3, sleep(3);
147
connect(extra2,127.0.0.1,root,,test,$SLAVE_MYPORT);
150
SET @old_slow_query_log= @@slow_query_log;
151
SET GLOBAL slow_query_log= 'OFF';
158
let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
159
let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
161
if ($found_fast_query)
163
SELECT * FROM mysql.slow_log;
164
die "Assertion failed! Fast query FOUND in slow query log when slow_query_log= OFF. Bailing out!";
167
if ($found_slow_query)
169
SELECT * FROM mysql.slow_log;
170
die "Assertion failed! Slow query FOUND in slow query log when slow_query_log= OFF. Bailing out!";
172
TRUNCATE mysql.slow_log;
174
# clean up: drop tables, reset the variables back to the previous value,
175
# disconnect extra connections
178
SET GLOBAL slow_query_log= @old_slow_query_log;
182
sync_slave_with_master;
184
source include/stop_slave.inc;
186
SET GLOBAL long_query_time= @old_long_query_time;
187
SET GLOBAL log_output= @old_log_output;
189
source include/start_slave.inc;