-- source include/have_binlog_format_statement.inc
-- source include/master-slave.inc

connection master;
-- disable_warnings
DROP TABLE IF EXISTS t;
-- enable_warnings

CREATE TABLE t(id INT);

-- disable_warnings
connection slave;
START SLAVE;
-- source include/wait_for_slave_to_start.inc
-- enable_warnings

connection master;
INSERT INTO t VALUES (1);
sync_slave_with_master;

connection slave;
show variables like 'log_slow_slave_statements';
set global log_slow_slave_statements=ON;
show variables like 'log_slow_slave_statements';

connection master;
INSERT INTO t VALUES (2);
sync_slave_with_master;

connection slave;
show variables like 'log_slow_slave_statements';
set global log_slow_slave_statements=ON;
show variables like 'log_slow_slave_statements';

STOP SLAVE;
-- source include/wait_for_slave_to_stop.inc
START SLAVE;
-- source include/wait_for_slave_to_start.inc

connection slave;
show variables like 'log_slow_slave_statements';
set global log_slow_slave_statements=ON;
show variables like 'log_slow_slave_statements';

connection master;
INSERT INTO t VALUES (3);
sync_slave_with_master;

connection slave;
show variables like 'log_slow_slave_statements';
set global log_slow_slave_statements=OFF;
show variables like 'log_slow_slave_statements';

connection master;
INSERT INTO t VALUES (4);
sync_slave_with_master;

connection slave;
show variables like 'log_slow_slave_statements';

STOP SLAVE;
-- source include/wait_for_slave_to_stop.inc
START SLAVE;
-- source include/wait_for_slave_to_start.inc

connection slave;
show variables like 'log_slow_slave_statements';

connection master;
INSERT INTO t VALUES (5);
sync_slave_with_master;

connection slave;
show variables like 'log_slow_slave_statements';
set global log_slow_slave_statements=ON;
show variables like 'log_slow_slave_statements';

connection master;
INSERT INTO t VALUES (6);
sync_slave_with_master;

connection slave;
show variables like 'log_slow_slave_statements';

STOP SLAVE;
-- source include/wait_for_slave_to_stop.inc
START SLAVE;
-- source include/wait_for_slave_to_start.inc

connection slave;
show variables like 'log_slow_slave_statements';

connection master;
INSERT INTO t VALUES (7);
sync_slave_with_master;

connection master;
FLUSH LOGS;

-- echo # Analyse master slow_query_log
let $i=7;
let $k=1;
while($i)
{
    --let grep_file = $MYSQLTEST_VARDIR/mysqld.1/data/percona_log_slow_slave_statements-master.log
    --let grep_pattern = INSERT INTO t VALUES \($k\)
    --source grep.inc
    dec $i;
    inc $k;
}

connection slave;
FLUSH LOGS;

-- echo # Analyse slave slow_query_log
let $i=7;
let $k=1;
while($i)
{
    --let grep_file = $MYSQLTEST_VARDIR/mysqld.2/data/percona_log_slow_slave_statements-slave.log
    --let grep_pattern = INSERT INTO t VALUES \($k\)
    --source grep.inc
    dec $i;
    inc $k;
}
set global log_slow_slave_statements=OFF;

connection master;
DROP TABLE t;
sync_slave_with_master;

STOP SLAVE;
-- source include/wait_for_slave_to_stop.inc
