rpl_misc_functions.test 3.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#
# Test of replicating some difficult functions
#
source include/master-slave.inc;

create table t1(id int, i int, r1 int, r2 int, p varchar(100));
insert into t1 values(1, connection_id(), 0, 0, "");
# don't put rand and password in the same query, to see if they replicate
# independently
# Pure rand test
insert into t1 values(2, 0, rand()*1000, rand()*1000, "");
# change the rand suite on the master (we do this because otherwise password()
# benefits from the fact that the above rand() is well replicated : 
# it picks the same sequence element, which hides a possible bug in password() replication.
set sql_log_bin=0;
insert into t1 values(6, 0, rand(), rand(), "");
delete from t1 where id=6;
set sql_log_bin=1;
# Pure password test
insert into t1 values(3, 0, 0, 0, password('does_this_work?'));
# "altogether now"
insert into t1 values(4, connection_id(), rand()*1000, rand()*1000, password('does_this_still_work?'));
select * into outfile 'rpl_misc_functions.outfile' from t1;
sync_slave_with_master;
create table t2 like t1; 
# read the values from the master table
27 28
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval load data local infile '$MYSQLTEST_VARDIR/master-data/test/rpl_misc_functions.outfile' into table t2;
29 30
# compare them with the replica; the SELECT below should return no row
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);
31 32 33

connection master;
drop table t1;
34 35

# End of 4.1 tests
36 37 38 39 40 41 42 43 44 45

#
# BUG#25543 test calling rand() multiple times on the master in
# a stored procedure.
#

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings

46 47
CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  col_a DOUBLE DEFAULT NULL);
48 49 50 51 52 53

DELIMITER |;

# Use a SP that calls rand() multiple times
CREATE PROCEDURE test_replication_sp1()
BEGIN
54 55
 INSERT INTO t1 (col_a) VALUES (rand()), (rand());
 INSERT INTO t1 (col_a) VALUES (rand());
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
END|

# Use a SP that calls another SP to call rand() multiple times
CREATE PROCEDURE test_replication_sp2()
BEGIN
  CALL test_replication_sp1();
  CALL test_replication_sp1();
END|

# Use a SF that calls rand() multiple times
CREATE FUNCTION test_replication_sf() RETURNS DOUBLE DETERMINISTIC
BEGIN
 RETURN (rand() + rand());
END|

DELIMITER ;|

# Exercise the functions and procedures then compare the results on
# the master to those on the slave.
CALL test_replication_sp1();
CALL test_replication_sp2();
77 78 79
INSERT INTO t1 (col_a) VALUES (test_replication_sf());
INSERT INTO t1 (col_a) VALUES (test_replication_sf());
INSERT INTO t1 (col_a) VALUES (test_replication_sf());
80 81 82

--sync_slave_with_master

83 84
# Dump table on slave
select * from t1 into outfile "../tmp/t1_slave.txt";
85

86 87 88 89 90 91 92 93
# Load data from slave into temp table on master
connection master;
create temporary table t1_slave select * from t1 where 1=0;
load data infile '../tmp/t1_slave.txt' into table t1_slave;
--remove_file $MYSQLTEST_VARDIR/tmp/t1_slave.txt

# Compare master and slave temp table, use subtraction
# for floating point comparison of "double"
94 95
select count(*) into @aux from t1 join t1_slave using (id)
where ABS(t1.col_a - t1_slave.col_a) < 0.0000001 ;
96 97 98 99
SELECT @aux;
if (`SELECT @aux <> 12 OR @aux IS NULL`)
{
   --echo # ERROR: We expected to get count(*) = 12.
100 101
   SELECT id, col_a FROM t1;
   SELECT id, col_a FROM t1_slave;
102 103 104
   --echo # abort
   exit;
}
105 106

# Cleanup
107
connection master;
108
DROP TABLE t1, t1_slave;
109 110 111
DROP PROCEDURE test_replication_sp1;
DROP PROCEDURE test_replication_sp2;
DROP FUNCTION test_replication_sf;
112
--remove_file $MYSQLTEST_VARDIR/master-data/test/rpl_misc_functions.outfile
113
--sync_slave_with_master
114

115