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");
34
# Prepare slave for different long_query_time we need to stop the slave
35
# and restart it as long_query_time variable is dynamic and, after
36
# setting it, it only takes effect on new connections.
39
# http://dev.mysql.com/doc/refman/6.0/en/set-option.html
42
source include/stop_slave.inc;
44
SET @old_log_output= @@log_output;
45
SET GLOBAL log_output= 'TABLE';
46
SET @old_long_query_time= @@long_query_time;
47
SET GLOBAL long_query_time= 2;
48
TRUNCATE mysql.slow_log;
50
source include/start_slave.inc;
53
CREATE TABLE t1 (a int, b int);
56
# check that slave logs the slow query to the slow log, but not the fast one.
58
let $slow_query= INSERT INTO t1 values(1, sleep(3));
59
let $fast_query= INSERT INTO t1 values(1, 1);
65
sync_slave_with_master;
67
let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
68
let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
70
if ($found_fast_query)
72
SELECT * FROM mysql.slow_log;
73
die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
76
if (!$found_slow_query)
78
SELECT * FROM mysql.slow_log;
79
die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
81
TRUNCATE mysql.slow_log;
83
# regular checks for slow query log (using a new connection - 'extra' - to slave)
86
# when using direct connections to the slave, check that slow query is logged
87
# but not the fast one.
89
connect(extra,127.0.0.1,root,,test,$SLAVE_MYPORT);
92
let $fast_query= SELECT 1;
93
let $slow_query= SELECT 1, sleep(3);
98
let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
99
let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
101
if ($found_fast_query)
103
SELECT * FROM mysql.slow_log;
104
die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
107
if (!$found_slow_query)
109
SELECT * FROM mysql.slow_log;
110
die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
112
TRUNCATE mysql.slow_log;
115
# when using direct connections to the slave, check that when setting timestamp to 1 the
116
# slow query is logged but the fast one is not.
118
let $fast_query= SELECT 2;
119
let $slow_query= SELECT 2, sleep(3);
125
let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
126
let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
128
if ($found_fast_query)
130
SELECT * FROM mysql.slow_log;
131
die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
134
if (!$found_slow_query)
136
SELECT * FROM mysql.slow_log;
137
die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
139
TRUNCATE mysql.slow_log;
142
# check that when setting the slow_query_log= OFF on connection 'extra2'
143
# prevents connection 'extra' from logging to slow query log.
145
let $fast_query= SELECT 3;
146
let $slow_query= SELECT 3, sleep(3);
148
connect(extra2,127.0.0.1,root,,test,$SLAVE_MYPORT);
151
SET @old_slow_query_log= @@slow_query_log;
152
SET GLOBAL slow_query_log= 'OFF';
159
let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
160
let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
162
if ($found_fast_query)
164
SELECT * FROM mysql.slow_log;
165
die "Assertion failed! Fast query FOUND in slow query log when slow_query_log= OFF. Bailing out!";
168
if ($found_slow_query)
170
SELECT * FROM mysql.slow_log;
171
die "Assertion failed! Slow query FOUND in slow query log when slow_query_log= OFF. Bailing out!";
173
TRUNCATE mysql.slow_log;
175
# clean up: drop tables, reset the variables back to the previous value,
176
# 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;
195
# BUG#50620: Adding an index to a table prevents slave from logging into slow log
198
-- source include/master-slave-reset.inc
201
SET @old_log_output= @@log_output;
202
SET GLOBAL log_output= 'TABLE';
203
SET GLOBAL long_query_time= 2;
204
SET @old_long_query_time= @@long_query_time;
205
SET SESSION long_query_time= 2;
206
TRUNCATE mysql.slow_log;
209
-- source include/stop_slave.inc
210
SET @old_log_output= @@log_output;
211
SET GLOBAL log_output= 'TABLE';
212
SET @old_long_query_time= @@long_query_time;
213
SET GLOBAL long_query_time= 2;
214
TRUNCATE mysql.slow_log;
215
-- source include/start_slave.inc
217
let $slow_query= INSERT INTO t1 values(1, sleep(3));
220
CREATE TABLE t1 (a int, b int);
222
-- echo ********************************************************************
223
-- echo **** INSERT one row that exceeds long_query_time
224
-- echo **** Outcome: query ends up in both master and slave slow log
225
-- echo ********************************************************************
231
let $master_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
232
-- sync_slave_with_master
233
let $slave_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
235
if (`SELECT $master_slow_query != $slave_slow_query`)
238
-- echo ***********************************************
239
-- echo ** DUMPING MASTER SLOW LOG CONTENTS
240
-- echo ***********************************************
241
SELECT * FROM mysql.slow_log;
244
-- echo ***********************************************
245
-- echo ** DUMPING SLAVE SLOW LOG CONTENTS
246
-- echo ***********************************************
247
SELECT * FROM mysql.slow_log;
249
-- die "Assertion failed! Master and slave slow log contents differ. Bailing out!"
252
if (`SELECT $master_slow_query = $slave_slow_query`)
254
-- echo ### Assertion is good. Both Master and Slave exhibit the
255
-- echo ### same number of queries in slow log: $master_slow_query
258
TRUNCATE mysql.slow_log;
260
TRUNCATE mysql.slow_log;
262
-- echo ********************************************************************
263
-- echo **** Now do inserts again, but first add an index to the table.
264
-- echo **** Outcome: Note that the slave contains the same one entry (as
265
-- echo **** the master does) whereas before the patch it did not.
266
-- echo ********************************************************************
268
ALTER TABLE t1 ADD INDEX id1(a);
274
let $master_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
275
-- sync_slave_with_master
276
let $slave_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
278
if (`SELECT $master_slow_query != $slave_slow_query`)
281
-- echo ***********************************************
282
-- echo ** DUMPING MASTER SLOW LOG CONTENTS
283
-- echo ***********************************************
284
SELECT * FROM mysql.slow_log;
287
-- echo ***********************************************
288
-- echo ** DUMPING SLAVE SLOW LOG CONTENTS
289
-- echo ***********************************************
290
SELECT * FROM mysql.slow_log;
292
-- die "Assertion failed! Master and slave slow log contents differ. Bailing out!"
295
if (`SELECT $master_slow_query = $slave_slow_query`)
297
-- echo ### Assertion is good. Both Master and Slave exhibit the
298
-- echo ### same number of queries in slow log: $master_slow_query
302
SET @@global.log_output= @old_log_output;
303
SET @@global.long_query_time= @old_long_query_time;
306
-- sync_slave_with_master
307
SET @@global.log_output= @old_log_output;
308
SET @@global.long_query_time= @old_long_query_time;