Commit d36f5781 authored by unknown's avatar unknown
Browse files

Fix for BUG#20438: CREATE statements for views, stored routines and triggers

can be not replicable.

Now CREATE statements for writing in the binlog are created as follows:
  - the beginning of the statement is re-created;
  - the rest of the statement is copied from the original query.

The problem appears when there is a version-specific comment (produced by
mysqldump), started in the re-created part of the statement and closed in the
copied part -- there is closing comment-parenthesis, but there is no opening
one.

The proper fix could be to re-create original statement, but we can not
implement it in 5.0. So, for 5.0 the fix is just to cut closing
comment-parenthesis. This technique is also used for SHOW CREATE PROCEDURE
statement (so we are able to reuse existing code).


mysql-test/r/rpl_sp.result:
  Updated result file.
mysql-test/r/rpl_trigger.result:
  Updated result file.
mysql-test/r/rpl_view.result:
  Updated result file.
mysql-test/t/rpl_sp.test:
  Added test case for BUG#20438.
mysql-test/t/rpl_trigger.test:
  Added test case for BUG#20438.
mysql-test/t/rpl_view.test:
  Added test case for BUG#20438.
sql/sp.cc:
  Trim comments at the end.
sql/sp_head.cc:
  Moved this code to the separate function to be re-used.
sql/sql_lex.cc:
  Added a new function.
sql/sql_lex.h:
  Added a new function.
sql/sql_trigger.cc:
  Trim comments at the end.
sql/sql_view.cc:
  Trim comments at the end.
parent 3c108584
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -420,4 +420,48 @@ 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;
+47 −0
Original line number Diff line number Diff line
@@ -896,3 +896,50 @@ Tables_in_test (t_)
SHOW TRIGGERS;
Trigger	Event	Table	Statement	Timing	Created	sql_mode	Definer
RESET MASTER;
START SLAVE;

---> Test for BUG#20438

---> Preparing environment...
---> connection: master
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;

---> Synchronizing slave with master...

---> connection: master

---> Creating objects...
CREATE TABLE t1(c INT);
CREATE TABLE t2(c INT);
/*!50003 CREATE TRIGGER t1_bi BEFORE INSERT ON t1
FOR EACH ROW
INSERT INTO t2 VALUES(NEW.c * 10) */;

---> Inserting value...
INSERT INTO t1 VALUES(1);

---> Checking on master...
SELECT * FROM t1;
c
1
SELECT * FROM t2;
c
10

---> Synchronizing slave with master...
---> connection: master

---> Checking on slave...
SELECT * FROM t1;
c
1
SELECT * FROM t2;
c
10

---> connection: master

---> Cleaning up...
DROP TABLE t1;
DROP TABLE t2;
+37 −0
Original line number Diff line number Diff line
@@ -54,3 +54,40 @@ slave-bin.000001 # Query 1 # use `test`; delete from v1 where a=2
slave-bin.000001	#	Query	1	#	use `test`; ALTER ALGORITHM=UNDEFINED DEFINER=root@localhost SQL SECURITY DEFINER VIEW v1 AS select a as b from t1
slave-bin.000001	#	Query	1	#	use `test`; drop view v1
slave-bin.000001	#	Query	1	#	use `test`; drop table t1

---> Test for BUG#20438

---> Preparing environment...
---> connection: master
DROP TABLE IF EXISTS t1;
DROP VIEW IF EXISTS v1;

---> Synchronizing slave with master...

---> connection: master

---> Creating objects...
CREATE TABLE t1(c INT);
/*!50003 CREATE VIEW v1 AS SELECT * FROM t1 */;

---> Inserting value...
INSERT INTO t1 VALUES(1);

---> Checking on master...
SELECT * FROM t1;
c
1

---> Synchronizing slave with master...
---> connection: master

---> Checking on slave...
SELECT * FROM t1;
c
1

---> connection: master

---> Cleaning up...
DROP VIEW v1;
DROP TABLE t1;
+80 −0
Original line number Diff line number Diff line
@@ -435,6 +435,86 @@ connection master;

DROP PROCEDURE p1;


#
# BUG#20438: CREATE statements for views, stored routines and triggers can be
# not replicable.
#

--echo
--echo ---> Test for BUG#20438

# Prepare environment.

--echo
--echo ---> Preparing environment...
--echo ---> connection: master
--connection master

--disable_warnings
DROP PROCEDURE IF EXISTS p1;
DROP FUNCTION IF EXISTS f1;
--enable_warnings

--echo
--echo ---> Synchronizing slave with master...

--save_master_pos
--connection slave
--sync_with_master

--echo
--echo ---> connection: master
--connection master

# Test.

--echo
--echo ---> Creating procedure...

/*!50003 CREATE PROCEDURE p1() SET @a = 1 */;

/*!50003 CREATE FUNCTION f1() RETURNS INT RETURN 0 */;

--echo
--echo ---> Checking on master...

SHOW CREATE PROCEDURE p1;
SHOW CREATE FUNCTION f1;

--echo
--echo ---> Synchronizing slave with master...

--save_master_pos
--connection slave
--sync_with_master

--echo ---> connection: master

--echo
--echo ---> Checking on slave...

SHOW CREATE PROCEDURE p1;
SHOW CREATE FUNCTION f1;

# Cleanup.

--echo
--echo ---> connection: master
--connection master

--echo
--echo ---> Cleaning up...

DROP PROCEDURE p1;
DROP FUNCTION f1;

--save_master_pos
--connection slave
--sync_with_master
--connection master


# cleanup
connection master;
drop table t1;
+92 −0
Original line number Diff line number Diff line
@@ -331,6 +331,98 @@ SHOW TRIGGERS;

RESET MASTER;

# Restart slave.

connection slave;
START SLAVE;


#
# BUG#20438: CREATE statements for views, stored routines and triggers can be
# not replicable.
#

--echo
--echo ---> Test for BUG#20438

# Prepare environment.

--echo
--echo ---> Preparing environment...
--echo ---> connection: master
--connection master

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

--echo
--echo ---> Synchronizing slave with master...

--save_master_pos
--connection slave
--sync_with_master

--echo
--echo ---> connection: master
--connection master

# Test.

--echo
--echo ---> Creating objects...

CREATE TABLE t1(c INT);
CREATE TABLE t2(c INT);

/*!50003 CREATE TRIGGER t1_bi BEFORE INSERT ON t1
  FOR EACH ROW
    INSERT INTO t2 VALUES(NEW.c * 10) */;

--echo
--echo ---> Inserting value...

INSERT INTO t1 VALUES(1);

--echo
--echo ---> Checking on master...

SELECT * FROM t1;
SELECT * FROM t2;

--echo
--echo ---> Synchronizing slave with master...

--save_master_pos
--connection slave
--sync_with_master

--echo ---> connection: master

--echo
--echo ---> Checking on slave...

SELECT * FROM t1;
SELECT * FROM t2;

# Cleanup.

--echo
--echo ---> connection: master
--connection master

--echo
--echo ---> Cleaning up...

DROP TABLE t1;
DROP TABLE t2;

--save_master_pos
--connection slave
--sync_with_master
--connection master


#
# End of tests
Loading