2
# Test of replicating some difficult functions
4
source include/master-slave.inc;
5
source include/not_gtid_enabled.inc;
7
CALL mtr.add_suppression('Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT');
9
create table t1(id int, i int, r1 int, r2 int, p varchar(100));
10
insert into t1 values(1, connection_id(), 0, 0, "");
11
# don't put rand and password in the same query, to see if they replicate
15
insert into t1 values(2, 0, rand()*1000, rand()*1000, "");
17
# change the rand suite on the master (we do this because otherwise password()
18
# benefits from the fact that the above rand() is well replicated :
19
# it picks the same sequence element, which hides a possible bug in password() replication.
21
insert into t1 values(6, 0, rand(), rand(), "");
22
delete from t1 where id=6;
25
insert into t1 values(3, 0, 0, 0, password('does_this_work?'));
28
insert into t1 values(4, connection_id(), rand()*1000, rand()*1000, password('does_this_still_work?'));
30
select * into outfile 'rpl_misc_functions.outfile' from t1;
31
let $MYSQLD_DATADIR= `select @@datadir`;
32
sync_slave_with_master;
33
create temporary table t2 like t1;
34
# read the values from the master table
35
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
36
eval load data local infile '$MYSQLD_DATADIR/test/rpl_misc_functions.outfile' into table t2;
37
# compare them with the replica; the SELECT below should return no row
38
select * from t1, t2 where (t1.id=t2.id) and not(t1.i=t2.i and t1.r1=t2.r1 and t1.r2=t2.r2 and t1.p=t2.p);
46
# BUG#25543 test calling rand() multiple times on the master in
51
DROP TABLE IF EXISTS t1;
54
CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
55
col_a DOUBLE DEFAULT NULL);
59
# Use a SP that calls rand() multiple times
60
CREATE PROCEDURE test_replication_sp1()
62
INSERT INTO t1 (col_a) VALUES (rand()), (rand());
63
INSERT INTO t1 (col_a) VALUES (rand());
66
# Use a SP that calls another SP to call rand() multiple times
67
CREATE PROCEDURE test_replication_sp2()
69
CALL test_replication_sp1();
70
CALL test_replication_sp1();
73
# Use a SF that calls rand() multiple times
74
CREATE FUNCTION test_replication_sf() RETURNS DOUBLE DETERMINISTIC
76
RETURN (rand() + rand());
81
# Exercise the functions and procedures then compare the results on
82
# the master to those on the slave.
84
CALL test_replication_sp1();
85
CALL test_replication_sp2();
86
INSERT INTO t1 (col_a) VALUES (test_replication_sf());
87
INSERT INTO t1 (col_a) VALUES (test_replication_sf());
88
INSERT INTO t1 (col_a) VALUES (test_replication_sf());
91
--sync_slave_with_master
94
select * from t1 into outfile "../../tmp/t1_slave.txt";
96
# Load data from slave into temp table on master
99
create temporary table t1_slave select * from t1 where 1=0;
101
load data infile '../../tmp/t1_slave.txt' into table t1_slave;
102
--remove_file $MYSQLTEST_VARDIR/tmp/t1_slave.txt
104
# Compare master and slave temp table, use subtraction
105
# for floating point comparison of "double"
106
select count(*) into @aux from t1 join t1_slave using (id)
107
where ABS(t1.col_a - t1_slave.col_a) < 0.0000001 ;
109
if (`SELECT @aux <> 12 OR @aux IS NULL`)
111
--echo # ERROR: We expected to get count(*) = 12.
112
SELECT id, col_a FROM t1;
113
SELECT id, col_a FROM t1_slave;
120
DROP TABLE t1, t1_slave;
121
DROP PROCEDURE test_replication_sp1;
122
DROP PROCEDURE test_replication_sp2;
123
DROP FUNCTION test_replication_sf;
124
--remove_file $MYSQLD_DATADIR/test/rpl_misc_functions.outfile
125
--sync_slave_with_master
128
--source include/rpl_end.inc