~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to mysql-test/suite/rpl/t/rpl_misc_functions.test

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Test of replicating some difficult functions
 
3
#
 
4
source include/master-slave.inc;
 
5
source include/not_gtid_enabled.inc;
 
6
 
 
7
CALL mtr.add_suppression('Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT');
 
8
 
 
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
 
12
# independently
 
13
# Pure rand test
 
14
--disable_warnings
 
15
insert into t1 values(2, 0, rand()*1000, rand()*1000, "");
 
16
--enable_warnings
 
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.
 
20
set sql_log_bin=0;
 
21
insert into t1 values(6, 0, rand(), rand(), "");
 
22
delete from t1 where id=6;
 
23
set sql_log_bin=1;
 
24
# Pure password test
 
25
insert into t1 values(3, 0, 0, 0, password('does_this_work?'));
 
26
# "altogether now"
 
27
--disable_warnings
 
28
insert into t1 values(4, connection_id(), rand()*1000, rand()*1000, password('does_this_still_work?'));
 
29
--enable_warnings
 
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);
 
39
 
 
40
connection master;
 
41
drop table t1;
 
42
 
 
43
# End of 4.1 tests
 
44
 
 
45
#
 
46
# BUG#25543 test calling rand() multiple times on the master in
 
47
# a stored procedure.
 
48
#
 
49
 
 
50
--disable_warnings
 
51
DROP TABLE IF EXISTS t1;
 
52
--enable_warnings
 
53
 
 
54
CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
 
55
  col_a DOUBLE DEFAULT NULL);
 
56
 
 
57
DELIMITER |;
 
58
 
 
59
# Use a SP that calls rand() multiple times
 
60
CREATE PROCEDURE test_replication_sp1()
 
61
BEGIN
 
62
 INSERT INTO t1 (col_a) VALUES (rand()), (rand());
 
63
 INSERT INTO t1 (col_a) VALUES (rand());
 
64
END|
 
65
 
 
66
# Use a SP that calls another SP to call rand() multiple times
 
67
CREATE PROCEDURE test_replication_sp2()
 
68
BEGIN
 
69
  CALL test_replication_sp1();
 
70
  CALL test_replication_sp1();
 
71
END|
 
72
 
 
73
# Use a SF that calls rand() multiple times
 
74
CREATE FUNCTION test_replication_sf() RETURNS DOUBLE DETERMINISTIC
 
75
BEGIN
 
76
 RETURN (rand() + rand());
 
77
END|
 
78
 
 
79
DELIMITER ;|
 
80
 
 
81
# Exercise the functions and procedures then compare the results on
 
82
# the master to those on the slave.
 
83
--disable_warnings
 
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());
 
89
--enable_warnings
 
90
 
 
91
--sync_slave_with_master
 
92
 
 
93
# Dump table on slave
 
94
select * from t1 into outfile "../../tmp/t1_slave.txt";
 
95
 
 
96
# Load data from slave into temp table on master
 
97
connection master;
 
98
--disable_warnings
 
99
create temporary table t1_slave select * from t1 where 1=0;
 
100
--enable_warnings
 
101
load data infile '../../tmp/t1_slave.txt' into table t1_slave;
 
102
--remove_file $MYSQLTEST_VARDIR/tmp/t1_slave.txt
 
103
 
 
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 ;
 
108
SELECT @aux;
 
109
if (`SELECT @aux <> 12 OR @aux IS NULL`)
 
110
{
 
111
   --echo # ERROR: We expected to get count(*) = 12.
 
112
   SELECT id, col_a FROM t1;
 
113
   SELECT id, col_a FROM t1_slave;
 
114
   --echo # abort
 
115
   exit;
 
116
}
 
117
 
 
118
# Cleanup
 
119
connection master;
 
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
 
126
 
 
127
 
 
128
--source include/rpl_end.inc