summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Malyavin <nikitamalyavin@gmail.com>2022-07-04 19:34:32 +0300
committerNikita Malyavin <nikitamalyavin@gmail.com>2023-04-18 00:29:50 +0300
commit6f3af28178c9d1d8d1549ff401b19ceb0d0625c9 (patch)
tree842601daaf10b7145a7be9c8e99c569f435ec1b9
parentfc74505ac188aa9ee59be0fa9738daa260cdcd2d (diff)
downloadmariadb-git-6f3af28178c9d1d8d1549ff401b19ceb0d0625c9.tar.gz
Do not ignore sql_mode when replicating
Division by zero is a good example. sql_mode is basically ignored by replication, see Bug#56662. The behavior for ONLINE should remain the same as for non-ONLINE ALTER.
-rw-r--r--mysql-test/main/alter_table_online_debug.result20
-rw-r--r--mysql-test/main/alter_table_online_debug.test28
-rw-r--r--sql/log_event_server.cc5
3 files changed, 52 insertions, 1 deletions
diff --git a/mysql-test/main/alter_table_online_debug.result b/mysql-test/main/alter_table_online_debug.result
index eca71a5d227..e5ebe1e7a1e 100644
--- a/mysql-test/main/alter_table_online_debug.result
+++ b/mysql-test/main/alter_table_online_debug.result
@@ -626,6 +626,7 @@ a
3
NULL
NULL
+set sql_mode=default;
connection default;
drop table t1;
set debug_sync= reset;
@@ -707,5 +708,24 @@ connection default;
drop table t1;
set debug_sync= reset;
#
+# Do not ignore sql_mode when replicating
+#
+create table t1 (a int);
+insert into t1 values (1);
+set debug_sync= 'now wait_for downgraded';
+connection con2;
+set sql_mode='STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO';
+set debug_sync= 'alter_table_online_downgraded signal downgraded wait_for goforit';
+alter table t1 add b int as (1/a) stored, algorithm=copy, lock=none;
+connection default;
+update t1 set a= 0 where a=1;
+set debug_sync= 'now signal goforit';
+connection con2;
+ERROR 22012: Division by 0
+set sql_mode= default;
+connection default;
+drop table t1;
+set debug_sync= reset;
+#
# End of 10.10 tests
#
diff --git a/mysql-test/main/alter_table_online_debug.test b/mysql-test/main/alter_table_online_debug.test
index c86b4a92701..e880613790f 100644
--- a/mysql-test/main/alter_table_online_debug.test
+++ b/mysql-test/main/alter_table_online_debug.test
@@ -772,6 +772,7 @@ set debug_sync= 'now signal goforit';
--reap
show create table t1;
select * from t1;
+set sql_mode=default;
--connection default
drop table t1;
set debug_sync= reset;
@@ -875,5 +876,32 @@ drop table t1;
set debug_sync= reset;
--echo #
+--echo # Do not ignore sql_mode when replicating
+--echo #
+create table t1 (a int);
+insert into t1 values (1);
+
+--send set debug_sync= 'now wait_for downgraded'
+
+--connection con2
+set sql_mode='STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO';
+set debug_sync= 'alter_table_online_downgraded signal downgraded wait_for goforit';
+--send alter table t1 add b int as (1/a) stored, algorithm=copy, lock=none
+
+--connection default
+--reap
+update t1 set a= 0 where a=1;
+set debug_sync= 'now signal goforit';
+
+--connection con2
+--error ER_DIVISION_BY_ZERO
+--reap
+
+set sql_mode= default;
+--connection default
+drop table t1;
+set debug_sync= reset;
+
+--echo #
--echo # End of 10.10 tests
--echo #
diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc
index 8c06e6140c0..8a3c46b3595 100644
--- a/sql/log_event_server.cc
+++ b/sql/log_event_server.cc
@@ -5071,9 +5071,12 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi)
extra columns on the slave. In that case, do not force
MODE_NO_AUTO_VALUE_ON_ZERO.
*/
+ Rpl_table_data rpl_data{};
+ if (rgi) rgi->get_table_data(table, &rpl_data);
sql_mode_t saved_sql_mode= thd->variables.sql_mode;
if (!is_auto_inc_in_extra_columns())
- thd->variables.sql_mode= MODE_NO_AUTO_VALUE_ON_ZERO;
+ thd->variables.sql_mode= (rpl_data.copy_fields ? saved_sql_mode : 0)
+ | MODE_NO_AUTO_VALUE_ON_ZERO;
// row processing loop