2
# Test of replicating some difficult functions
4
source include/master-slave.inc;
6
create table t1(id int, i int, r1 int, r2 int, p varchar(100));
7
insert into t1 values(1, connection_id(), 0, 0, "");
8
# don't put rand and password in the same query, to see if they replicate
11
insert into t1 values(2, 0, rand()*1000, rand()*1000, "");
12
# change the rand suite on the master (we do this because otherwise password()
13
# benefits from the fact that the above rand() is well replicated :
14
# it picks the same sequence element, which hides a possible bug in password() replication.
16
insert into t1 values(6, 0, rand(), rand(), "");
17
delete from t1 where id=6;
20
insert into t1 values(3, 0, 0, 0, password('does_this_work?'));
22
insert into t1 values(4, connection_id(), rand()*1000, rand()*1000, password('does_this_still_work?'));
23
select * into outfile 'rpl_misc_functions.outfile' from t1;
24
sync_slave_with_master;
25
create table t2 like t1;
26
# read the values from the master table
27
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
28
eval load data local infile '$MYSQLTEST_VARDIR/master-data/test/rpl_misc_functions.outfile' into table t2;
29
# compare them with the replica; the SELECT below should return no row
30
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);
38
# BUG#25543 test calling rand() multiple times on the master in
43
DROP TABLE IF EXISTS t1;
46
CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
47
col_a DOUBLE DEFAULT NULL);
51
# Use a SP that calls rand() multiple times
52
CREATE PROCEDURE test_replication_sp1()
54
INSERT INTO t1 (col_a) VALUES (rand()), (rand());
55
INSERT INTO t1 (col_a) VALUES (rand());
58
# Use a SP that calls another SP to call rand() multiple times
59
CREATE PROCEDURE test_replication_sp2()
61
CALL test_replication_sp1();
62
CALL test_replication_sp1();
65
# Use a SF that calls rand() multiple times
66
CREATE FUNCTION test_replication_sf() RETURNS DOUBLE DETERMINISTIC
68
RETURN (rand() + rand());
73
# Exercise the functions and procedures then compare the results on
74
# the master to those on the slave.
75
CALL test_replication_sp1();
76
CALL test_replication_sp2();
77
INSERT INTO t1 (col_a) VALUES (test_replication_sf());
78
INSERT INTO t1 (col_a) VALUES (test_replication_sf());
79
INSERT INTO t1 (col_a) VALUES (test_replication_sf());
81
--sync_slave_with_master
84
select * from t1 into outfile "../tmp/t1_slave.txt";
86
# Load data from slave into temp table on master
88
create temporary table t1_slave select * from t1 where 1=0;
89
load data infile '../tmp/t1_slave.txt' into table t1_slave;
90
--remove_file $MYSQLTEST_VARDIR/tmp/t1_slave.txt
92
# Compare master and slave temp table, use subtraction
93
# for floating point comparison of "double"
94
select count(*) into @aux from t1 join t1_slave using (id)
95
where ABS(t1.col_a - t1_slave.col_a) < 0.0000001 ;
97
if (`SELECT @aux <> 12 OR @aux IS NULL`)
99
--echo # ERROR: We expected to get count(*) = 12.
100
SELECT id, col_a FROM t1;
101
SELECT id, col_a FROM t1_slave;
108
DROP TABLE t1, t1_slave;
109
DROP PROCEDURE test_replication_sp1;
110
DROP PROCEDURE test_replication_sp2;
111
DROP FUNCTION test_replication_sf;
112
--remove_file $MYSQLTEST_VARDIR/master-data/test/rpl_misc_functions.outfile
113
--sync_slave_with_master