Skip to content

Commit a5f4c98

Browse files
committed
MDEV-29804 Fix SHOW BINLOG EVENTS displaying incorrect session variable values
Query_log_event::pack_info() was displaying inverted values for foreign_key_checks and unique_checks. The flags OPTION_NO_FOREIGN_KEY_CHECKS and OPTION_RELAXED_UNIQUE_CHECKS are set when these checks are *disabled* (i.e., when the user sets them to 0), but pack_info() was incorrectly printing them as =1. This caused SHOW BINLOG EVENTS to show foreign_key_checks=1 and unique_checks=1 when they were actually 0.
1 parent 204d8aa commit a5f4c98

5 files changed

Lines changed: 36 additions & 7 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set foreign_key_checks= 0, sql_auto_is_null=1, check_constraint_checks=0, unique_checks=0;
2+
create table t (a int, check(a>1), foreign key(a) references x (x)) engine=InnoDB as select 1 as a;
3+
include/show_binlog_events.inc
4+
Log_name Pos Event_type Server_id End_log_pos Info
5+
master-bin.000001 # Gtid # # GTID #-#-#
6+
master-bin.000001 # Query # # use `test`; set foreign_key_checks=0, sql_auto_is_null=1, unique_checks=0; create table t (a int, check(a>1), foreign key(a) references x (x)) engine=InnoDB as select 1 as a
7+
drop table t;

mysql-test/suite/binlog/r/foreign_key.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ master-bin.000001 # Table_map # # table_id: # (test.t1)
3131
master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
3232
master-bin.000001 # Xid # # COMMIT /* XID */
3333
master-bin.000001 # Gtid # # GTID #-#-#
34-
master-bin.000001 # Query # # use `test`; set foreign_key_checks=1; DROP TABLE `t1` /* generated by server */
34+
master-bin.000001 # Query # # use `test`; set foreign_key_checks=0; DROP TABLE `t1` /* generated by server */
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ==== Purpose ====
2+
#
3+
# Test verifies that reading binary log by using "SHOW BINLOG EVENTS" command
4+
# from should correctly print the values of session variables such as
5+
# foreign_key_checks, sql_auto_is_null, unique_checks etc
6+
#
7+
# ==== References ====
8+
#
9+
# MDEV-29804 SHOW BINLOG EVENTS produces semantically/syntactically incorrect statements
10+
11+
12+
--source include/have_log_bin.inc
13+
--source include/have_innodb.inc
14+
--source include/have_binlog_format_statement.inc
15+
16+
set foreign_key_checks= 0, sql_auto_is_null=1, check_constraint_checks=0, unique_checks=0;
17+
create table t (a int, check(a>1), foreign key(a) references x (x)) engine=InnoDB as select 1 as a;
18+
19+
source include/show_binlog_events.inc;
20+
21+
# Cleanup
22+
drop table t;

mysql-test/suite/rpl/r/rpl_alter_rollback.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ master-bin.000001 # Query # # use `test`; alter table t2 add constraint c1 forei
4242
master-bin.000001 # Gtid # # GTID #-#-# ROLLBACK ALTER id=#
4343
master-bin.000001 # Query # # use `test`; alter table t2 add constraint c1 foreign key (f1) references t1(f1)
4444
master-bin.000001 # Gtid # # GTID #-#-# START ALTER
45-
master-bin.000001 # Query # # use `test`; set foreign_key_checks=1; alter table t2 add constraint c1 foreign key (f1) references t1(f1)
45+
master-bin.000001 # Query # # use `test`; set foreign_key_checks=0; alter table t2 add constraint c1 foreign key (f1) references t1(f1)
4646
master-bin.000001 # Gtid # # GTID #-#-# ROLLBACK ALTER id=#
47-
master-bin.000001 # Query # # use `test`; set foreign_key_checks=1; alter table t2 add constraint c1 foreign key (f1) references t1(f1)
47+
master-bin.000001 # Query # # use `test`; set foreign_key_checks=0; alter table t2 add constraint c1 foreign key (f1) references t1(f1)
4848
connection slave;
4949
connection master;
5050
drop table t2, t1;

sql/log_event_server.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,13 +1064,13 @@ void Query_log_event::pack_info(Protocol *protocol)
10641064
{
10651065
buf.append(STRING_WITH_LEN("set "));
10661066
if (flags2 & OPTION_NO_FOREIGN_KEY_CHECKS)
1067-
buf.append(STRING_WITH_LEN("foreign_key_checks=1, "));
1067+
buf.append(STRING_WITH_LEN("foreign_key_checks=0, "));
10681068
if (flags2 & OPTION_AUTO_IS_NULL)
1069-
buf.append(STRING_WITH_LEN("sql_auto_is_null, "));
1069+
buf.append(STRING_WITH_LEN("sql_auto_is_null=1, "));
10701070
if (flags2 & OPTION_RELAXED_UNIQUE_CHECKS)
1071-
buf.append(STRING_WITH_LEN("unique_checks=1, "));
1071+
buf.append(STRING_WITH_LEN("unique_checks=0, "));
10721072
if (flags2 & OPTION_NO_CHECK_CONSTRAINT_CHECKS)
1073-
buf.append(STRING_WITH_LEN("check_constraint_checks=1, "));
1073+
buf.append(STRING_WITH_LEN("check_constraint_checks=0, "));
10741074
if (flags2 & OPTION_IF_EXISTS)
10751075
buf.append(STRING_WITH_LEN("@@sql_if_exists=1, "));
10761076
if (flags2 & OPTION_INSERT_HISTORY)

0 commit comments

Comments
 (0)