summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <mats@kindahl-laptop.dnsalias.net>2007-10-31 21:09:52 +0100
committerunknown <mats@kindahl-laptop.dnsalias.net>2007-10-31 21:09:52 +0100
commitcc0e54656714fec37cd74e03fe781f7571ed194e (patch)
tree8e6ca778cac4f9a416a5cee91ed25935efd4ecc1
parentfcff3b5a8d5db3ff0c8f9b3cbfc5645c81ca4c48 (diff)
downloadmariadb-git-cc0e54656714fec37cd74e03fe781f7571ed194e.tar.gz
BUG#28086 (SBR of USER() becomes corrupted on slave):
Marking statements containing USER() or CURRENT_USER() as unsafe, causing them to switch to using row-based logging in MIXED mode and generate a warning in STATEMENT mode. mysql-test/suite/rpl/r/rpl_switch_stm_row_mixed.result: Result change. mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test: Adding test to check that USER() and CURRENT_USER() cause a switch to row-based logging. sql/sql_yacc.yy: Setting statements containing USER() or CURRENT_USER() to be unsafe.
-rw-r--r--mysql-test/suite/rpl/r/rpl_switch_stm_row_mixed.result68
-rw-r--r--mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test36
-rw-r--r--sql/sql_yacc.yy2
3 files changed, 106 insertions, 0 deletions
diff --git a/mysql-test/suite/rpl/r/rpl_switch_stm_row_mixed.result b/mysql-test/suite/rpl/r/rpl_switch_stm_row_mixed.result
index c3f0c07b92c..8ed9ff5dc2f 100644
--- a/mysql-test/suite/rpl/r/rpl_switch_stm_row_mixed.result
+++ b/mysql-test/suite/rpl/r/rpl_switch_stm_row_mixed.result
@@ -405,6 +405,26 @@ CREATE TABLE t12 (data LONG);
LOCK TABLES t12 WRITE;
INSERT INTO t12 VALUES(UUID());
UNLOCK TABLES;
+CREATE FUNCTION my_user()
+RETURNS CHAR(64)
+BEGIN
+DECLARE user CHAR(64);
+SELECT USER() INTO user;
+RETURN user;
+END $$
+CREATE FUNCTION my_current_user()
+RETURNS CHAR(64)
+BEGIN
+DECLARE user CHAR(64);
+SELECT CURRENT_USER() INTO user;
+RETURN user;
+END $$
+DROP TABLE IF EXISTS t13;
+CREATE TABLE t13 (data CHAR(64));
+INSERT INTO t13 VALUES (USER());
+INSERT INTO t13 VALUES (my_user());
+INSERT INTO t13 VALUES (CURRENT_USER());
+INSERT INTO t13 VALUES (my_current_user());
show binlog events from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # drop database if exists mysqltest1
@@ -709,6 +729,30 @@ master-bin.000001 # Query # # use `mysqltest1`; DROP TABLE IF EXISTS t12
master-bin.000001 # Query # # use `mysqltest1`; CREATE TABLE t12 (data LONG)
master-bin.000001 # Table_map # # table_id: # (mysqltest1.t12)
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
+master-bin.000001 # Query # # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` FUNCTION my_user()
+RETURNS CHAR(64)
+BEGIN
+DECLARE user CHAR(64);
+SELECT USER() INTO user;
+RETURN user;
+END
+master-bin.000001 # Query # # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` FUNCTION my_current_user()
+RETURNS CHAR(64)
+BEGIN
+DECLARE user CHAR(64);
+SELECT CURRENT_USER() INTO user;
+RETURN user;
+END
+master-bin.000001 # Query # # use `mysqltest1`; DROP TABLE IF EXISTS t13
+master-bin.000001 # Query # # use `mysqltest1`; CREATE TABLE t13 (data CHAR(64))
+master-bin.000001 # Table_map # # table_id: # (mysqltest1.t13)
+master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
+master-bin.000001 # Table_map # # table_id: # (mysqltest1.t13)
+master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
+master-bin.000001 # Table_map # # table_id: # (mysqltest1.t13)
+master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
+master-bin.000001 # Table_map # # table_id: # (mysqltest1.t13)
+master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
show binlog events from <binlog_start>;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Query # # drop database if exists mysqltest1
@@ -1013,5 +1057,29 @@ master-bin.000001 # Query # # use `mysqltest1`; DROP TABLE IF EXISTS t12
master-bin.000001 # Query # # use `mysqltest1`; CREATE TABLE t12 (data LONG)
master-bin.000001 # Table_map # # table_id: # (mysqltest1.t12)
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
+master-bin.000001 # Query # # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` FUNCTION my_user()
+RETURNS CHAR(64)
+BEGIN
+DECLARE user CHAR(64);
+SELECT USER() INTO user;
+RETURN user;
+END
+master-bin.000001 # Query # # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` FUNCTION my_current_user()
+RETURNS CHAR(64)
+BEGIN
+DECLARE user CHAR(64);
+SELECT CURRENT_USER() INTO user;
+RETURN user;
+END
+master-bin.000001 # Query # # use `mysqltest1`; DROP TABLE IF EXISTS t13
+master-bin.000001 # Query # # use `mysqltest1`; CREATE TABLE t13 (data CHAR(64))
+master-bin.000001 # Table_map # # table_id: # (mysqltest1.t13)
+master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
+master-bin.000001 # Table_map # # table_id: # (mysqltest1.t13)
+master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
+master-bin.000001 # Table_map # # table_id: # (mysqltest1.t13)
+master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
+master-bin.000001 # Table_map # # table_id: # (mysqltest1.t13)
+master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
drop database mysqltest1;
set global binlog_format =@my_binlog_format;
diff --git a/mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test b/mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test
index b0012827db8..05dcb91ca28 100644
--- a/mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test
+++ b/mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test
@@ -518,6 +518,42 @@ CREATE TABLE t12 (data LONG);
LOCK TABLES t12 WRITE;
INSERT INTO t12 VALUES(UUID());
UNLOCK TABLES;
+sync_slave_with_master;
+
+#
+# BUG#28086: SBR of USER() becomes corrupted on slave
+#
+
+connection master;
+
+# Just to get something that is non-trivial, albeit still simple, we
+# stuff the result of USER() and CURRENT_USER() into a variable.
+--delimiter $$
+CREATE FUNCTION my_user()
+ RETURNS CHAR(64)
+BEGIN
+ DECLARE user CHAR(64);
+ SELECT USER() INTO user;
+ RETURN user;
+END $$
+--delimiter ;
+
+--delimiter $$
+CREATE FUNCTION my_current_user()
+ RETURNS CHAR(64)
+BEGIN
+ DECLARE user CHAR(64);
+ SELECT CURRENT_USER() INTO user;
+ RETURN user;
+END $$
+--delimiter ;
+
+DROP TABLE IF EXISTS t13;
+CREATE TABLE t13 (data CHAR(64));
+INSERT INTO t13 VALUES (USER());
+INSERT INTO t13 VALUES (my_user());
+INSERT INTO t13 VALUES (CURRENT_USER());
+INSERT INTO t13 VALUES (my_current_user());
source include/show_binlog_events.inc;
sync_slave_with_master;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 109e8f5434f..bb25d9c4c7f 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -6745,6 +6745,7 @@ function_call_keyword:
| CURRENT_USER optional_braces
{
$$= new (YYTHD->mem_root) Item_func_current_user(Lex->current_context());
+ Lex->set_stmt_unsafe();
Lex->safe_to_cache_query= 0;
}
| DATE_SYM '(' expr ')'
@@ -6790,6 +6791,7 @@ function_call_keyword:
| USER '(' ')'
{
$$= new (YYTHD->mem_root) Item_func_user();
+ Lex->set_stmt_unsafe();
Lex->safe_to_cache_query=0;
}
| YEAR_SYM '(' expr ')'