Skip to content

Commit d781678

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 6318d50 commit d781678

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
show binlog events;
4+
Log_name Pos Event_type Server_id End_log_pos Info
5+
master-bin.000001 4 Format_desc 1 256 Server ver: 10.6.26-MariaDB-debug-log, Binlog ver: 4
6+
master-bin.000001 256 Gtid_list 1 285 []
7+
master-bin.000001 285 Binlog_checkpoint 1 329 master-bin.000001
8+
master-bin.000001 329 Gtid 1 371 GTID 0-1-1
9+
master-bin.000001 371 Query 1 536 use `test`; set foreign_key_checks=0, sql_auto_is_null, unique_checks=0; create table t (a int, check(a>1), foreign key(a) references x (x)) engine=InnoDB as select 1 as a
10+
drop table t;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--source include/have_log_bin.inc
2+
--source include/have_innodb.inc
3+
--source include/have_binlog_format_statement.inc
4+
5+
set foreign_key_checks= 0, sql_auto_is_null=1, check_constraint_checks=0, unique_checks=0;
6+
create table t (a int, check(a>1), foreign key(a) references x (x)) engine=InnoDB as select 1 as a;
7+
8+
show binlog events;
9+
10+
# Cleanup
11+
drop table t;

sql/log_event_server.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,11 +1062,11 @@ void Query_log_event::pack_info(Protocol *protocol)
10621062
{
10631063
buf.append(STRING_WITH_LEN("set "));
10641064
if (flags2 & OPTION_NO_FOREIGN_KEY_CHECKS)
1065-
buf.append(STRING_WITH_LEN("foreign_key_checks=1, "));
1065+
buf.append(STRING_WITH_LEN("foreign_key_checks=0, "));
10661066
if (flags2 & OPTION_AUTO_IS_NULL)
10671067
buf.append(STRING_WITH_LEN("sql_auto_is_null, "));
10681068
if (flags2 & OPTION_RELAXED_UNIQUE_CHECKS)
1069-
buf.append(STRING_WITH_LEN("unique_checks=1, "));
1069+
buf.append(STRING_WITH_LEN("unique_checks=0, "));
10701070
if (flags2 & OPTION_NO_CHECK_CONSTRAINT_CHECKS)
10711071
buf.append(STRING_WITH_LEN("check_constraint_checks=1, "));
10721072
if (flags2 & OPTION_IF_EXISTS)

0 commit comments

Comments
 (0)