Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion mysql-test/suite/binlog/r/foreign_key.result
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
36 changes: 36 additions & 0 deletions mysql-test/suite/binlog/t/binlog_check_constraint_checks_flag.test
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;

@bnestere bnestere Apr 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, looks like check_constraint_checks was added as a part of MDEV-7563, but its addition to #define OPTIONS_WRITTEN_TO_BIN_LOG in log_event.h was missed. The option is missing from your added .result file. Can you fix that and add the option there, as well as void Format_description_log_event::deduct_options_written_to_bin_log() in log_event.cc?

This will also fix MDEV-32447 :) Please consider adding the test case from MDEV-32447 as well, to verify.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. I will make these changes and update the PR.

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;
4 changes: 2 additions & 2 deletions mysql-test/suite/rpl/r/rpl_alter_rollback.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion sql/log_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down
8 changes: 4 additions & 4 deletions sql/log_event_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down