Skip to content

Commit 6ef3875

Browse files
author
Luis Soares
committed
Manual merge from mysql-5.1-rep+2.
2 parents 38c89b8 + 0c4b0e9 commit 6ef3875

File tree

3 files changed

+168
-4
lines changed

3 files changed

+168
-4
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
SELECT @@SESSION.binlog_format;
2+
@@SESSION.binlog_format
3+
MIXED
4+
CREATE TABLE t1 (a VARCHAR(100));
5+
CREATE TEMPORARY TABLE t2 (a VARCHAR(100));
6+
# Test allow switching @@SESSION.binlog_format from MIXED to STATEMENT
7+
# when there are open temp tables and we are logging in statement based format.
8+
SET SESSION binlog_format = STATEMENT;
9+
SELECT @@SESSION.binlog_format;
10+
@@SESSION.binlog_format
11+
STATEMENT
12+
# Test allow switching @@SESSION.binlog_format from STATEMENT to
13+
# STATEMENT when there are open temp tables.
14+
SET SESSION binlog_format = STATEMENT;
15+
SELECT @@SESSION.binlog_format;
16+
@@SESSION.binlog_format
17+
STATEMENT
18+
INSERT INTO t1 VALUES ('statement based');
19+
SELECT @@SESSION.binlog_format;
20+
@@SESSION.binlog_format
21+
STATEMENT
22+
# Test allow switching @@SESSION.binlog_format from STATEMENT to
23+
# MIXED when there are open temp tables.
24+
SET SESSION binlog_format = MIXED;
25+
SELECT @@SESSION.binlog_format;
26+
@@SESSION.binlog_format
27+
MIXED
28+
# Test allow switching @@SESSION.binlog_format from MIXED to MIXED
29+
# when there are open temp tables.
30+
SET SESSION binlog_format = MIXED;
31+
SELECT @@SESSION.binlog_format;
32+
@@SESSION.binlog_format
33+
MIXED
34+
INSERT INTO t2 VALUES (UUID());
35+
SELECT @@SESSION.binlog_format;
36+
@@SESSION.binlog_format
37+
MIXED
38+
# Test forbit switching @@SESSION.binlog_format from MIXED to STATEMENT
39+
# when there are open temp tables and we are logging in row based format.
40+
SET SESSION binlog_format = STATEMENT;
41+
ERROR HY000: Cannot switch out of the row-based binary log format when the session has open temporary tables
42+
SELECT @@SESSION.binlog_format;
43+
@@SESSION.binlog_format
44+
MIXED
45+
SET SESSION binlog_format = ROW;
46+
SELECT @@SESSION.binlog_format;
47+
@@SESSION.binlog_format
48+
ROW
49+
INSERT INTO t1 VALUES ('row based');
50+
# Test allow switching @@SESSION.binlog_format from ROW to MIXED
51+
# when there are open temp tables.
52+
SET SESSION binlog_format = MIXED;
53+
SELECT @@SESSION.binlog_format;
54+
@@SESSION.binlog_format
55+
MIXED
56+
INSERT INTO t1 VALUES ('row based');
57+
# Test allow switching @@SESSION.binlog_format from MIXED to ROW
58+
# when there are open temp tables.
59+
SET SESSION binlog_format = ROW;
60+
SELECT @@SESSION.binlog_format;
61+
@@SESSION.binlog_format
62+
ROW
63+
# Test allow switching @@SESSION.binlog_format from ROW to ROW
64+
# when there are open temp tables.
65+
SET SESSION binlog_format = ROW;
66+
SELECT @@SESSION.binlog_format;
67+
@@SESSION.binlog_format
68+
ROW
69+
INSERT INTO t1 VALUES ('row based');
70+
# Test forbit switching @@SESSION.binlog_format from ROW to STATEMENT
71+
# when there are open temp tables.
72+
SET SESSION binlog_format = STATEMENT;
73+
ERROR HY000: Cannot switch out of the row-based binary log format when the session has open temporary tables
74+
SELECT @@SESSION.binlog_format;
75+
@@SESSION.binlog_format
76+
ROW
77+
DROP TEMPORARY TABLE t2;
78+
DROP TABLE t1;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#
2+
# Bug #45855 row events in binlog after switch from binlog_fmt=mix to stmt with open tmp tbl
3+
# Bug #45856 can't switch from binlog_format=row to mix with open tmp tbl
4+
# This test verfies if the program will generate ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR
5+
# error and forbid switching @@SESSION.binlog_format from MIXED or ROW to
6+
# STATEMENT when there are open temp tables and we are logging in row format.
7+
# There is no error in any other case.
8+
#
9+
10+
source include/have_binlog_format_mixed.inc;
11+
12+
SELECT @@SESSION.binlog_format;
13+
CREATE TABLE t1 (a VARCHAR(100));
14+
CREATE TEMPORARY TABLE t2 (a VARCHAR(100));
15+
16+
--echo # Test allow switching @@SESSION.binlog_format from MIXED to STATEMENT
17+
--echo # when there are open temp tables and we are logging in statement based format.
18+
SET SESSION binlog_format = STATEMENT;
19+
SELECT @@SESSION.binlog_format;
20+
21+
--echo # Test allow switching @@SESSION.binlog_format from STATEMENT to
22+
--echo # STATEMENT when there are open temp tables.
23+
SET SESSION binlog_format = STATEMENT;
24+
SELECT @@SESSION.binlog_format;
25+
26+
INSERT INTO t1 VALUES ('statement based');
27+
SELECT @@SESSION.binlog_format;
28+
--echo # Test allow switching @@SESSION.binlog_format from STATEMENT to
29+
--echo # MIXED when there are open temp tables.
30+
SET SESSION binlog_format = MIXED;
31+
SELECT @@SESSION.binlog_format;
32+
33+
--echo # Test allow switching @@SESSION.binlog_format from MIXED to MIXED
34+
--echo # when there are open temp tables.
35+
SET SESSION binlog_format = MIXED;
36+
SELECT @@SESSION.binlog_format;
37+
38+
INSERT INTO t2 VALUES (UUID());
39+
SELECT @@SESSION.binlog_format;
40+
41+
--echo # Test forbit switching @@SESSION.binlog_format from MIXED to STATEMENT
42+
--echo # when there are open temp tables and we are logging in row based format.
43+
--ERROR ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR
44+
SET SESSION binlog_format = STATEMENT;
45+
SELECT @@SESSION.binlog_format;
46+
47+
SET SESSION binlog_format = ROW;
48+
SELECT @@SESSION.binlog_format;
49+
50+
INSERT INTO t1 VALUES ('row based');
51+
--echo # Test allow switching @@SESSION.binlog_format from ROW to MIXED
52+
--echo # when there are open temp tables.
53+
SET SESSION binlog_format = MIXED;
54+
SELECT @@SESSION.binlog_format;
55+
56+
INSERT INTO t1 VALUES ('row based');
57+
--echo # Test allow switching @@SESSION.binlog_format from MIXED to ROW
58+
--echo # when there are open temp tables.
59+
SET SESSION binlog_format = ROW;
60+
SELECT @@SESSION.binlog_format;
61+
62+
--echo # Test allow switching @@SESSION.binlog_format from ROW to ROW
63+
--echo # when there are open temp tables.
64+
SET SESSION binlog_format = ROW;
65+
SELECT @@SESSION.binlog_format;
66+
67+
INSERT INTO t1 VALUES ('row based');
68+
--echo # Test forbit switching @@SESSION.binlog_format from ROW to STATEMENT
69+
--echo # when there are open temp tables.
70+
--ERROR ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR
71+
SET SESSION binlog_format = STATEMENT;
72+
SELECT @@SESSION.binlog_format;
73+
74+
DROP TEMPORARY TABLE t2;
75+
DROP TABLE t1;
76+

sql/sys_vars.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,25 @@ static bool check_has_super(sys_var *self, THD *thd, set_var *var)
241241
static bool binlog_format_check(sys_var *self, THD *thd, set_var *var)
242242
{
243243
/*
244-
If RBR and open temporary tables, their CREATE TABLE may not be in the
245-
binlog, so we can't toggle to SBR in this connection.
244+
If RBR and open temporary tables, their CREATE TABLE may not be in the
245+
binlog, so we can't toggle to SBR in this connection.
246+
247+
If binlog_format=MIXED, there are open temporary tables, and an unsafe
248+
statement is executed, then subsequent statements are logged in row
249+
format and hence changes to temporary tables may be lost. So we forbid
250+
switching @@SESSION.binlog_format from MIXED to STATEMENT when there are
251+
open temp tables and we are logging in row format.
246252
*/
247-
if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) &&
248-
thd->temporary_tables)
253+
if (thd->temporary_tables && var->type == OPT_SESSION &&
254+
var->save_result.ulonglong_value == BINLOG_FORMAT_STMT &&
255+
((thd->variables.binlog_format == BINLOG_FORMAT_MIXED &&
256+
thd->is_current_stmt_binlog_format_row()) ||
257+
thd->variables.binlog_format == BINLOG_FORMAT_ROW))
249258
{
250259
my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
251260
return true;
252261
}
262+
253263
/*
254264
if in a stored function/trigger, it's too late to change mode
255265
*/

0 commit comments

Comments
 (0)