diff --git a/mysql-test/suite/binlog/r/binlog_check_constraint_checks_flag.result b/mysql-test/suite/binlog/r/binlog_check_constraint_checks_flag.result new file mode 100644 index 0000000000000..1d108335b69b1 --- /dev/null +++ b/mysql-test/suite/binlog/r/binlog_check_constraint_checks_flag.result @@ -0,0 +1,24 @@ +include/master-slave.inc +[connection master] +connection master; +create table t10( +pk int primary key, +a int, +constraint a_big check (a>10) +); +insert into t10 values (1, 20); +set check_constraint_checks=off; +update t10 set a=a-15 where pk=1; +update t10 set a=a+100 where pk=1; +set check_constraint_checks=on ; +select * from t10; +pk a +1 105 +connection slave; +select * from t10; +pk a +1 105 +connection master; +drop table t10; +connection slave; +include/rpl_end.inc diff --git a/mysql-test/suite/binlog/r/binlog_show_binlog_events_session_variables.result b/mysql-test/suite/binlog/r/binlog_show_binlog_events_session_variables.result new file mode 100644 index 0000000000000..f9ca0301d1330 --- /dev/null +++ b/mysql-test/suite/binlog/r/binlog_show_binlog_events_session_variables.result @@ -0,0 +1,9 @@ +reset master; +set foreign_key_checks= 0, sql_auto_is_null=1, check_constraint_checks=0, unique_checks=0; +create table t (a int, check(a>1), foreign key(a) references x (x)) engine=InnoDB as select 1 as a; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; set foreign_key_checks=0, sql_auto_is_null=1, unique_checks=0, check_constraint_checks=0; create table t (a int, check(a>1), foreign key(a) references x (x)) engine=InnoDB as select 1 as a +drop table t; +reset master; diff --git a/mysql-test/suite/binlog/r/foreign_key.result b/mysql-test/suite/binlog/r/foreign_key.result index 171018f22be78..d3f80779c2cd2 100644 --- a/mysql-test/suite/binlog/r/foreign_key.result +++ b/mysql-test/suite/binlog/r/foreign_key.result @@ -31,4 +31,4 @@ master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F master-bin.000001 # Xid # # COMMIT /* XID */ master-bin.000001 # Gtid # # GTID #-#-# -master-bin.000001 # Query # # use `test`; set foreign_key_checks=1; DROP TABLE `t1` /* generated by server */ +master-bin.000001 # Query # # use `test`; set foreign_key_checks=0; DROP TABLE `t1` /* generated by server */ diff --git a/mysql-test/suite/binlog/t/binlog_check_constraint_checks_flag.test b/mysql-test/suite/binlog/t/binlog_check_constraint_checks_flag.test new file mode 100644 index 0000000000000..f731557b21511 --- /dev/null +++ b/mysql-test/suite/binlog/t/binlog_check_constraint_checks_flag.test @@ -0,0 +1,36 @@ +--source include/master-slave.inc + +# References: +# +# MDEV-32447 Using check_constraint_checks=OFF can break replication +# +# check_constraint_checks was added in MDEV-7563 but its addition +# to OPTIONS_WRITTEN_TO_BINLOG was missed and therefore it was breaking +# replication in binlog formats other than ROW. + + +--connection master + +create table t10( + pk int primary key, + a int, + constraint a_big check (a>10) +); + +insert into t10 values (1, 20); +set check_constraint_checks=off; +update t10 set a=a-15 where pk=1; +update t10 set a=a+100 where pk=1; +set check_constraint_checks=on ; +select * from t10; + +--sync_slave_with_master + +# Here we are on the slave +select * from t10; +--connection master + +drop table t10; +--sync_slave_with_master + +--source include/rpl_end.inc diff --git a/mysql-test/suite/binlog/t/binlog_show_binlog_events_session_variables.test b/mysql-test/suite/binlog/t/binlog_show_binlog_events_session_variables.test new file mode 100644 index 0000000000000..9dc5aeea2cf57 --- /dev/null +++ b/mysql-test/suite/binlog/t/binlog_show_binlog_events_session_variables.test @@ -0,0 +1,25 @@ +# ==== Purpose ==== +# +# Test verifies that reading binary log by using "SHOW BINLOG EVENTS" command +# from should correctly print the values of session variables such as +# foreign_key_checks, sql_auto_is_null, unique_checks etc +# +# ==== References ==== +# +# MDEV-29804 SHOW BINLOG EVENTS produces semantically/syntactically incorrect statements + + +--source include/have_log_bin.inc +--source include/have_innodb.inc +--source include/have_binlog_format_statement.inc + +reset master; + +set foreign_key_checks= 0, sql_auto_is_null=1, check_constraint_checks=0, unique_checks=0; +create table t (a int, check(a>1), foreign key(a) references x (x)) engine=InnoDB as select 1 as a; + +source include/show_binlog_events.inc; + +# Cleanup +drop table t; +reset master; diff --git a/mysql-test/suite/rpl/r/rpl_alter_rollback.result b/mysql-test/suite/rpl/r/rpl_alter_rollback.result index 3bd91a516c45f..89b8b821f3c85 100644 --- a/mysql-test/suite/rpl/r/rpl_alter_rollback.result +++ b/mysql-test/suite/rpl/r/rpl_alter_rollback.result @@ -42,9 +42,9 @@ master-bin.000001 # Query # # use `test`; alter table t2 add constraint c1 forei master-bin.000001 # Gtid # # GTID #-#-# ROLLBACK ALTER id=# master-bin.000001 # Query # # use `test`; alter table t2 add constraint c1 foreign key (f1) references t1(f1) master-bin.000001 # Gtid # # GTID #-#-# START ALTER -master-bin.000001 # Query # # use `test`; set foreign_key_checks=1; alter table t2 add constraint c1 foreign key (f1) references t1(f1) +master-bin.000001 # Query # # use `test`; set foreign_key_checks=0; alter table t2 add constraint c1 foreign key (f1) references t1(f1) master-bin.000001 # Gtid # # GTID #-#-# ROLLBACK ALTER id=# -master-bin.000001 # Query # # use `test`; set foreign_key_checks=1; alter table t2 add constraint c1 foreign key (f1) references t1(f1) +master-bin.000001 # Query # # use `test`; set foreign_key_checks=0; alter table t2 add constraint c1 foreign key (f1) references t1(f1) connection slave; connection master; drop table t2, t1; diff --git a/sql/log_event.cc b/sql/log_event.cc index 3d7460315ed65..cc1b652806143 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -2392,7 +2392,7 @@ void Format_description_log_event::deduct_options_written_to_bin_log() { options_written_to_bin_log= OPTION_AUTO_IS_NULL | OPTION_NOT_AUTOCOMMIT | OPTION_NO_FOREIGN_KEY_CHECKS | OPTION_RELAXED_UNIQUE_CHECKS | - OPTION_INSERT_HISTORY; + OPTION_INSERT_HISTORY | OPTION_NO_CHECK_CONSTRAINT_CHECKS; if (!server_version_split.version_is_valid() || server_version_split.kind == master_version_split::KIND_MYSQL || server_version_split < Version(10,5,2)) diff --git a/sql/log_event.h b/sql/log_event.h index 0aa7c187c93ae..88b26c10a617c 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -539,7 +539,7 @@ class String; #define OPTIONS_WRITTEN_TO_BIN_LOG (OPTION_EXPLICIT_DEF_TIMESTAMP |\ OPTION_AUTO_IS_NULL | OPTION_NO_FOREIGN_KEY_CHECKS | \ OPTION_RELAXED_UNIQUE_CHECKS | OPTION_NOT_AUTOCOMMIT | OPTION_IF_EXISTS |\ - OPTION_INSERT_HISTORY) + OPTION_INSERT_HISTORY | OPTION_NO_CHECK_CONSTRAINT_CHECKS) #define CHECKSUM_CRC32_SIGNATURE_LEN 4 /** diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index a21c417fc70c0..768afc3cedf86 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -1064,13 +1064,13 @@ void Query_log_event::pack_info(Protocol *protocol) { buf.append(STRING_WITH_LEN("set ")); if (flags2 & OPTION_NO_FOREIGN_KEY_CHECKS) - buf.append(STRING_WITH_LEN("foreign_key_checks=1, ")); + buf.append(STRING_WITH_LEN("foreign_key_checks=0, ")); if (flags2 & OPTION_AUTO_IS_NULL) - buf.append(STRING_WITH_LEN("sql_auto_is_null, ")); + buf.append(STRING_WITH_LEN("sql_auto_is_null=1, ")); if (flags2 & OPTION_RELAXED_UNIQUE_CHECKS) - buf.append(STRING_WITH_LEN("unique_checks=1, ")); + buf.append(STRING_WITH_LEN("unique_checks=0, ")); if (flags2 & OPTION_NO_CHECK_CONSTRAINT_CHECKS) - buf.append(STRING_WITH_LEN("check_constraint_checks=1, ")); + buf.append(STRING_WITH_LEN("check_constraint_checks=0, ")); if (flags2 & OPTION_IF_EXISTS) buf.append(STRING_WITH_LEN("@@sql_if_exists=1, ")); if (flags2 & OPTION_INSERT_HISTORY)