mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 13:32:33 +01:00
4dc7be62a9
Problem: When RAND() is binlogged in statement mode, the seed is binlogged too, so the replication slave generates the same sequence of random numbers. This makes replication work in many cases, but not in all cases: the order of rows is not guaranteed for, e.g., UPDATE or INSERT...SELECT statements, so the row data will be different if master and slave retrieve the rows in different orders. Fix: Mark RAND() as unsafe. It will generate a warning if binlog_format=STATEMENT and switch to row-logging if binlog_format=ROW. mysql-test/extra/rpl_tests/rpl_row_func003.test: updated test case to ignore new warnings mysql-test/suite/binlog/r/binlog_unsafe.result: updated result file mysql-test/suite/binlog/t/binlog_unsafe.test: Added test for RAND(). Also clarified some old comments. mysql-test/suite/rpl/r/rpl_misc_functions.result: updated result file mysql-test/suite/rpl/r/rpl_nondeterministic_functions.result: updated test case to ignore new warnings mysql-test/suite/rpl/r/rpl_optimize.result: updated result file mysql-test/suite/rpl/r/rpl_row_func003.result: updated result file mysql-test/suite/rpl/t/rpl_misc_functions.test: updated test case to ignore new warnings mysql-test/suite/rpl/t/rpl_nondeterministic_functions.test: updated test case to ignore new warnings mysql-test/suite/rpl/t/rpl_optimize.test: updated test case to ignore new warnings mysql-test/suite/rpl/t/rpl_trigger.test: updated test case to ignore new warnings mysql-test/suite/rpl_ndb/r/rpl_ndb_func003.result: updated result file sql/item_create.cc: Mark RAND() unsafe.
56 lines
2.1 KiB
Text
56 lines
2.1 KiB
Text
stop slave;
|
|
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
|
|
reset master;
|
|
reset slave;
|
|
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
|
|
start slave;
|
|
CALL mtr.add_suppression('Statement may not be safe to log in statement format.');
|
|
create table t1(id int, i int, r1 int, r2 int, p varchar(100));
|
|
insert into t1 values(1, connection_id(), 0, 0, "");
|
|
insert into t1 values(2, 0, rand()*1000, rand()*1000, "");
|
|
set sql_log_bin=0;
|
|
insert into t1 values(6, 0, rand(), rand(), "");
|
|
delete from t1 where id=6;
|
|
set sql_log_bin=1;
|
|
insert into t1 values(3, 0, 0, 0, password('does_this_work?'));
|
|
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;
|
|
create temporary table t2 like t1;
|
|
load data local infile 'MYSQLD_DATADIR/test/rpl_misc_functions.outfile' into table t2;
|
|
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);
|
|
id i r1 r2 p id i r1 r2 p
|
|
drop table t1;
|
|
DROP TABLE IF EXISTS t1;
|
|
CREATE TABLE t1 (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
col_a DOUBLE DEFAULT NULL);
|
|
CREATE PROCEDURE test_replication_sp1()
|
|
BEGIN
|
|
INSERT INTO t1 (col_a) VALUES (rand()), (rand());
|
|
INSERT INTO t1 (col_a) VALUES (rand());
|
|
END|
|
|
CREATE PROCEDURE test_replication_sp2()
|
|
BEGIN
|
|
CALL test_replication_sp1();
|
|
CALL test_replication_sp1();
|
|
END|
|
|
CREATE FUNCTION test_replication_sf() RETURNS DOUBLE DETERMINISTIC
|
|
BEGIN
|
|
RETURN (rand() + rand());
|
|
END|
|
|
CALL test_replication_sp1();
|
|
CALL test_replication_sp2();
|
|
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());
|
|
select * from t1 into outfile "../../tmp/t1_slave.txt";
|
|
create temporary table t1_slave select * from t1 where 1=0;
|
|
load data infile '../../tmp/t1_slave.txt' into table t1_slave;
|
|
select count(*) into @aux from t1 join t1_slave using (id)
|
|
where ABS(t1.col_a - t1_slave.col_a) < 0.0000001 ;
|
|
SELECT @aux;
|
|
@aux
|
|
12
|
|
DROP TABLE t1, t1_slave;
|
|
DROP PROCEDURE test_replication_sp1;
|
|
DROP PROCEDURE test_replication_sp2;
|
|
DROP FUNCTION test_replication_sf;
|