Manual merge of the fix for BUG#19725 "Calls to SF in other database are not replicated

correctly in some cases", from 5.0.
In short, calls to a stored function located in another database
than the default database, may fail to replicate if the call was made
by SET, SELECT, or DO.
sp_head.cc automerged, only the test and test's result had to be hand-merged.
parent c144de06
...@@ -269,6 +269,118 @@ insert into t1 values (1); ...@@ -269,6 +269,118 @@ insert into t1 values (1);
select * from t1; select * from t1;
a a
1 1
select * from t1;
a
1
create procedure foo()
not deterministic
reads sql data
select * from t1;
call foo();
a
1
drop procedure foo;
drop function fn1;
drop database mysqltest1;
drop user "zedjzlcsjhd"@127.0.0.1;
use test;
use test;
drop function if exists f1;
create function f1() returns int reads sql data
begin
declare var integer;
declare c cursor for select a from v1;
open c;
fetch c into var;
close c;
return var;
end|
create view v1 as select 1 as a;
create table t1 (a int);
insert into t1 (a) values (f1());
select * from t1;
a
1
drop view v1;
drop function f1;
select * from t1;
a
1
DROP PROCEDURE IF EXISTS p1;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(col VARCHAR(10));
CREATE PROCEDURE p1(arg VARCHAR(10))
INSERT INTO t1 VALUES(arg);
CALL p1('test');
SELECT * FROM t1;
col
test
SELECT * FROM t1;
col
test
DROP PROCEDURE p1;
---> Test for BUG#20438
---> Preparing environment...
---> connection: master
DROP PROCEDURE IF EXISTS p1;
DROP FUNCTION IF EXISTS f1;
---> Synchronizing slave with master...
---> connection: master
---> Creating procedure...
/*!50003 CREATE PROCEDURE p1() SET @a = 1 */;
/*!50003 CREATE FUNCTION f1() RETURNS INT RETURN 0 */;
---> Checking on master...
SHOW CREATE PROCEDURE p1;
Procedure sql_mode Create Procedure
p1 CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
SET @a = 1
SHOW CREATE FUNCTION f1;
Function sql_mode Create Function
f1 CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
RETURN 0
---> Synchronizing slave with master...
---> connection: master
---> Checking on slave...
SHOW CREATE PROCEDURE p1;
Procedure sql_mode Create Procedure
p1 CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
SET @a = 1
SHOW CREATE FUNCTION f1;
Function sql_mode Create Function
f1 CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
RETURN 0
---> connection: master
---> Cleaning up...
DROP PROCEDURE p1;
DROP FUNCTION f1;
drop table t1;
drop database if exists mysqltest;
drop database if exists mysqltest2;
create database mysqltest;
create database mysqltest2;
use mysqltest2;
create table t ( t integer );
create procedure mysqltest.test() begin end;
insert into t values ( 1 );
create procedure `\\`.test() begin end;
ERROR 42000: Unknown database '\\'
create function f1 () returns int
begin
insert into t values (1);
return 0;
end|
use mysqltest;
set @a:= mysqltest2.f1();
show binlog events in 'master-bin.000001' from 102; show binlog events in 'master-bin.000001' from 102;
Log_name Pos Event_type Server_id End_log_pos Info Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query 1 # drop database if exists mysqltest1 master-bin.000001 # Query 1 # drop database if exists mysqltest1
...@@ -329,7 +441,7 @@ insert into t1 values (x); ...@@ -329,7 +441,7 @@ insert into t1 values (x);
return x+2; return x+2;
end end
master-bin.000001 # Query 1 # use `mysqltest1`; delete t1,t2 from t1,t2 master-bin.000001 # Query 1 # use `mysqltest1`; delete t1,t2 from t1,t2
master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `fn1`(20) master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `mysqltest1`.`fn1`(20)
master-bin.000001 # Query 1 # use `mysqltest1`; insert into t2 values(fn1(21)) master-bin.000001 # Query 1 # use `mysqltest1`; insert into t2 values(fn1(21))
master-bin.000001 # Query 1 # use `mysqltest1`; drop function fn1 master-bin.000001 # Query 1 # use `mysqltest1`; drop function fn1
master-bin.000001 # Query 1 # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` function fn1() master-bin.000001 # Query 1 # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` function fn1()
...@@ -362,32 +474,23 @@ begin ...@@ -362,32 +474,23 @@ begin
insert into t2 values(x),(x); insert into t2 values(x),(x);
return 10; return 10;
end end
master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `fn1`(100) master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `mysqltest1`.`fn1`(100)
master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `fn1`(20) master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `mysqltest1`.`fn1`(20)
master-bin.000001 # Query 1 # use `mysqltest1`; delete from t1 master-bin.000001 # Query 1 # use `mysqltest1`; delete from t1
master-bin.000001 # Query 1 # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` trigger trg before insert on t1 for each row set new.a= 10 master-bin.000001 # Query 1 # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` trigger trg before insert on t1 for each row set new.a= 10
master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 values (1) master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 values (1)
master-bin.000001 # Query 1 # use `mysqltest1`; delete from t1 master-bin.000001 # Query 1 # use `mysqltest1`; delete from t1
master-bin.000001 # Query 1 # use `mysqltest1`; drop trigger trg master-bin.000001 # Query 1 # use `mysqltest1`; drop trigger trg
master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 values (1) master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 values (1)
select * from t1; master-bin.000001 # Query 1 # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` procedure foo()
a
1
create procedure foo()
not deterministic not deterministic
reads sql data reads sql data
select * from t1; select * from t1
call foo(); master-bin.000001 # Query 1 # use `mysqltest1`; drop procedure foo
a master-bin.000001 # Query 1 # use `mysqltest1`; drop function fn1
1 master-bin.000001 # Query 1 # drop database mysqltest1
drop procedure foo; master-bin.000001 # Query 1 # drop user "zedjzlcsjhd"@127.0.0.1
drop function fn1; master-bin.000001 # Query 1 # use `test`; CREATE DEFINER=`root`@`localhost` function f1() returns int reads sql data
drop database mysqltest1;
drop user "zedjzlcsjhd"@127.0.0.1;
use test;
use test;
drop function if exists f1;
create function f1() returns int reads sql data
begin begin
declare var integer; declare var integer;
declare c cursor for select a from v1; declare c cursor for select a from v1;
...@@ -395,99 +498,39 @@ open c; ...@@ -395,99 +498,39 @@ open c;
fetch c into var; fetch c into var;
close c; close c;
return var; return var;
end| end
create view v1 as select 1 as a; master-bin.000001 # Query 1 # use `test`; CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 as a
create table t1 (a int); master-bin.000001 # Query 1 # use `test`; create table t1 (a int)
insert into t1 (a) values (f1()); master-bin.000001 # Query 1 # use `test`; insert into t1 (a) values (f1())
select * from t1; master-bin.000001 # Query 1 # use `test`; drop view v1
a master-bin.000001 # Query 1 # use `test`; drop function f1
1 master-bin.000001 # Query 1 # use `test`; DROP TABLE IF EXISTS t1
drop view v1; master-bin.000001 # Query 1 # use `test`; CREATE TABLE t1(col VARCHAR(10))
drop function f1; master-bin.000001 # Query 1 # use `test`; CREATE DEFINER=`root`@`localhost` PROCEDURE p1(arg VARCHAR(10))
select * from t1; INSERT INTO t1 VALUES(arg)
a master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 VALUES( NAME_CONST('arg',_latin1'test'))
1 master-bin.000001 # Query 1 # use `test`; DROP PROCEDURE p1
DROP PROCEDURE IF EXISTS p1; master-bin.000001 # Query 1 # use `test`; CREATE DEFINER=`root`@`localhost` PROCEDURE p1() SET @a = 1
DROP TABLE IF EXISTS t1; master-bin.000001 # Query 1 # use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION f1() RETURNS INT RETURN 0
CREATE TABLE t1(col VARCHAR(10)); master-bin.000001 # Query 1 # use `test`; DROP PROCEDURE p1
CREATE PROCEDURE p1(arg VARCHAR(10)) master-bin.000001 # Query 1 # use `test`; DROP FUNCTION f1
INSERT INTO t1 VALUES(arg); master-bin.000001 # Query 1 # use `test`; drop table t1
CALL p1('test'); master-bin.000001 # Query 1 # drop database if exists mysqltest
SELECT * FROM t1; master-bin.000001 # Query 1 # drop database if exists mysqltest2
col master-bin.000001 # Query 1 # create database mysqltest
test master-bin.000001 # Query 1 # create database mysqltest2
SELECT * FROM t1; master-bin.000001 # Query 1 # use `mysqltest2`; create table t ( t integer )
col master-bin.000001 # Query 1 # use `mysqltest2`; CREATE DEFINER=`root`@`localhost` procedure mysqltest.test() begin end
test master-bin.000001 # Query 1 # use `mysqltest2`; insert into t values ( 1 )
DROP PROCEDURE p1; master-bin.000001 # Query 1 # use `mysqltest2`; CREATE DEFINER=`root`@`localhost` function f1 () returns int
begin
---> Test for BUG#20438 insert into t values (1);
return 0;
---> Preparing environment... end
---> connection: master master-bin.000001 # Query 1 # use `mysqltest`; SELECT `mysqltest2`.`f1`()
DROP PROCEDURE IF EXISTS p1;
DROP FUNCTION IF EXISTS f1;
---> Synchronizing slave with master...
---> connection: master
---> Creating procedure...
/*!50003 CREATE PROCEDURE p1() SET @a = 1 */;
/*!50003 CREATE FUNCTION f1() RETURNS INT RETURN 0 */;
---> Checking on master...
SHOW CREATE PROCEDURE p1;
Procedure sql_mode Create Procedure
p1 CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
SET @a = 1
SHOW CREATE FUNCTION f1;
Function sql_mode Create Function
f1 CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
RETURN 0
---> Synchronizing slave with master...
---> connection: master
---> Checking on slave...
SHOW CREATE PROCEDURE p1;
Procedure sql_mode Create Procedure
p1 CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
SET @a = 1
SHOW CREATE FUNCTION f1;
Function sql_mode Create Function
f1 CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
RETURN 0
---> connection: master
---> Cleaning up...
DROP PROCEDURE p1;
DROP FUNCTION f1;
drop table t1;
set global log_bin_trust_function_creators=0; set global log_bin_trust_function_creators=0;
set global log_bin_trust_function_creators=0; set global log_bin_trust_function_creators=0;
End of 5.0 tests
reset master;
drop database if exists mysqltest;
drop database if exists mysqltest2;
create database mysqltest;
create database mysqltest2;
use mysqltest2;
create table t ( t integer );
create procedure mysqltest.test() begin end;
insert into t values ( 1 );
show binlog events in 'master-bin.000001' from 102;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 102 Query 1 203 drop database if exists mysqltest
master-bin.000001 203 Query 1 306 drop database if exists mysqltest2
master-bin.000001 306 Query 1 399 create database mysqltest
master-bin.000001 399 Query 1 494 create database mysqltest2
master-bin.000001 494 Query 1 591 use `mysqltest2`; create table t ( t integer )
master-bin.000001 591 Query 1 730 use `mysqltest2`; CREATE DEFINER=`root`@`localhost` procedure mysqltest.test() begin end
master-bin.000001 730 Query 1 825 use `mysqltest2`; insert into t values ( 1 )
create procedure `\\`.test() begin end;
ERROR 42000: Unknown database '\\'
drop database mysqltest; drop database mysqltest;
drop database mysqltest2; drop database mysqltest2;
End of 5.0 tests
End of 5.1 tests End of 5.1 tests
...@@ -559,7 +559,7 @@ begin ...@@ -559,7 +559,7 @@ begin
insert into t2 select x; insert into t2 select x;
return 100; return 100;
end end
master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `foo6`(_latin1'foo6_1_') master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `mysqltest1`.`foo6`(_latin1'foo6_1_')
master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t2) master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t2)
master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t2) master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t2)
...@@ -620,7 +620,7 @@ master-bin.000001 # Query 1 # use `mysqltest1`; create table t12 select * from t ...@@ -620,7 +620,7 @@ master-bin.000001 # Query 1 # use `mysqltest1`; create table t12 select * from t
master-bin.000001 # Query 1 # use `mysqltest1`; drop table t1 master-bin.000001 # Query 1 # use `mysqltest1`; drop table t1
master-bin.000001 # Query 1 # use `mysqltest1`; create table t1 (a int, b varchar(100), key(a)) master-bin.000001 # Query 1 # use `mysqltest1`; create table t1 (a int, b varchar(100), key(a))
master-bin.000001 # Intvar 1 # INSERT_ID=4 master-bin.000001 # Intvar 1 # INSERT_ID=4
master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `f`(_latin1'try_45_') master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `mysqltest1`.`f`(_latin1'try_45_')
master-bin.000001 # Query 1 # use `mysqltest1`; create table t13 select * from t1 master-bin.000001 # Query 1 # use `mysqltest1`; create table t13 select * from t1
master-bin.000001 # Query 1 # use `mysqltest1`; drop table t1 master-bin.000001 # Query 1 # use `mysqltest1`; drop table t1
master-bin.000001 # Query 1 # use `mysqltest1`; create table t1 (a int primary key auto_increment, b varchar(100)) master-bin.000001 # Query 1 # use `mysqltest1`; create table t1 (a int primary key auto_increment, b varchar(100))
...@@ -660,9 +660,9 @@ set y = (select count(*) from t2); ...@@ -660,9 +660,9 @@ set y = (select count(*) from t2);
return y; return y;
end end
master-bin.000001 # Intvar 1 # INSERT_ID=4 master-bin.000001 # Intvar 1 # INSERT_ID=4
master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `f1`(_latin1'try_53_') master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `mysqltest1`.`f1`(_latin1'try_53_')
master-bin.000001 # Intvar 1 # INSERT_ID=5 master-bin.000001 # Intvar 1 # INSERT_ID=5
master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `f2`(_latin1'try_54_') master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `mysqltest1`.`f2`(_latin1'try_54_')
master-bin.000001 # Query 1 # use `mysqltest1`; drop function f2 master-bin.000001 # Query 1 # use `mysqltest1`; drop function f2
master-bin.000001 # Query 1 # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` trigger t1_bi before insert on t1 for each row master-bin.000001 # Query 1 # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` trigger t1_bi before insert on t1 for each row
begin begin
...@@ -869,7 +869,7 @@ begin ...@@ -869,7 +869,7 @@ begin
insert into t2 select x; insert into t2 select x;
return 100; return 100;
end end
master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `foo6`(_latin1'foo6_1_') master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `mysqltest1`.`foo6`(_latin1'foo6_1_')
master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t2) master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t2)
master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t2) master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t2)
...@@ -930,7 +930,7 @@ master-bin.000001 # Query 1 # use `mysqltest1`; create table t12 select * from t ...@@ -930,7 +930,7 @@ master-bin.000001 # Query 1 # use `mysqltest1`; create table t12 select * from t
master-bin.000001 # Query 1 # use `mysqltest1`; drop table t1 master-bin.000001 # Query 1 # use `mysqltest1`; drop table t1
master-bin.000001 # Query 1 # use `mysqltest1`; create table t1 (a int, b varchar(100), key(a)) master-bin.000001 # Query 1 # use `mysqltest1`; create table t1 (a int, b varchar(100), key(a))
master-bin.000001 # Intvar 1 # INSERT_ID=4 master-bin.000001 # Intvar 1 # INSERT_ID=4
master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `f`(_latin1'try_45_') master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `mysqltest1`.`f`(_latin1'try_45_')
master-bin.000001 # Query 1 # use `mysqltest1`; create table t13 select * from t1 master-bin.000001 # Query 1 # use `mysqltest1`; create table t13 select * from t1
master-bin.000001 # Query 1 # use `mysqltest1`; drop table t1 master-bin.000001 # Query 1 # use `mysqltest1`; drop table t1
master-bin.000001 # Query 1 # use `mysqltest1`; create table t1 (a int primary key auto_increment, b varchar(100)) master-bin.000001 # Query 1 # use `mysqltest1`; create table t1 (a int primary key auto_increment, b varchar(100))
...@@ -970,9 +970,9 @@ set y = (select count(*) from t2); ...@@ -970,9 +970,9 @@ set y = (select count(*) from t2);
return y; return y;
end end
master-bin.000001 # Intvar 1 # INSERT_ID=4 master-bin.000001 # Intvar 1 # INSERT_ID=4
master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `f1`(_latin1'try_53_') master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `mysqltest1`.`f1`(_latin1'try_53_')
master-bin.000001 # Intvar 1 # INSERT_ID=5 master-bin.000001 # Intvar 1 # INSERT_ID=5
master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `f2`(_latin1'try_54_') master-bin.000001 # Query 1 # use `mysqltest1`; SELECT `mysqltest1`.`f2`(_latin1'try_54_')
master-bin.000001 # Query 1 # use `mysqltest1`; drop function f2 master-bin.000001 # Query 1 # use `mysqltest1`; drop function f2
master-bin.000001 # Query 1 # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` trigger t1_bi before insert on t1 for each row master-bin.000001 # Query 1 # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` trigger t1_bi before insert on t1 for each row
begin begin
......
...@@ -343,13 +343,13 @@ delete from t1; ...@@ -343,13 +343,13 @@ delete from t1;
drop trigger trg; drop trigger trg;
insert into t1 values (1); insert into t1 values (1);
select * from t1; select * from t1;
--replace_column 2 # 5 #
--replace_regex /table_id: [0-9]+/table_id: #/
show binlog events in 'master-bin.000001' from 102;
sync_slave_with_master; sync_slave_with_master;
select * from t1; select * from t1;
# ********************** PART 4 : RELATED FIXED BUGS ***************
# #
# Test for bug #13969 "Routines which are replicated from master can't be # Test for bug #13969 "Routines which are replicated from master can't be
# executed on slave". # executed on slave".
...@@ -522,17 +522,11 @@ connection master; ...@@ -522,17 +522,11 @@ connection master;
drop table t1; drop table t1;
sync_slave_with_master; sync_slave_with_master;
# Restore log_bin_trust_function_creators to original value
set global log_bin_trust_function_creators=0;
connection master;
set global log_bin_trust_function_creators=0;
--echo End of 5.0 tests
# #
# Bug22043: MySQL don't add "USE <DATABASE>" before "DROP PROCEDURE IF EXISTS" # Bug22043: MySQL don't add "USE <DATABASE>" before "DROP PROCEDURE IF EXISTS"
# #
connection master; connection master;
reset master;
--disable_warnings --disable_warnings
drop database if exists mysqltest; drop database if exists mysqltest;
drop database if exists mysqltest2; drop database if exists mysqltest2;
...@@ -543,12 +537,49 @@ use mysqltest2; ...@@ -543,12 +537,49 @@ use mysqltest2;
create table t ( t integer ); create table t ( t integer );
create procedure mysqltest.test() begin end; create procedure mysqltest.test() begin end;
insert into t values ( 1 ); insert into t values ( 1 );
show binlog events in 'master-bin.000001' from 102;
--error ER_BAD_DB_ERROR --error ER_BAD_DB_ERROR
create procedure `\\`.test() begin end; create procedure `\\`.test() begin end;
#
# BUG#19725: Calls to stored function in other database are not
# replicated correctly in some cases
#
connection master;
delimiter |;
create function f1 () returns int
begin
insert into t values (1);
return 0;
end|
delimiter ;|
sync_slave_with_master;
# Let us test if we don't forget to binlog the function's database
connection master;
use mysqltest;
set @a:= mysqltest2.f1();
sync_slave_with_master;
connection master;
# Final inspection which verifies how all statements of this test file
# were written to the binary log.
--replace_column 2 # 5 #
--replace_regex /table_id: [0-9]+/table_id: #/
show binlog events in 'master-bin.000001' from 102;
# Restore log_bin_trust_function_creators to its original value.
# This is a cleanup for all parts above where we tested stored
# functions and triggers.
set global log_bin_trust_function_creators=0;
connection master;
set global log_bin_trust_function_creators=0;
# Clean up # Clean up
drop database mysqltest; drop database mysqltest;
drop database mysqltest2; drop database mysqltest2;
--echo End of 5.0 tests
--echo End of 5.1 tests --echo End of 5.1 tests
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment