From bf4d701cee0b4c96dc693eb9085a9a5d474a1afb Mon Sep 17 00:00:00 2001 From: hcduan Date: Tue, 24 May 2022 13:32:14 +0800 Subject: [PATCH] [bugfix]#842 Bug#107366 REPLICATION ERROR WITH HASH_SCAN ROW SEARCH ALGORITHM FOR FUNCTIONAL INDEXES Description ----------- HASH_SCAN builds a hash of changes, scans the target table or index, and applies any matching change for current entry. In the build phase, it uses only the before-image, and skips any after-image to avoid loose ends. However, previous implementation (since WL#1075) computed generated columns for the skipped after-image, thus causing replication error in some cases. Analysis -------- Rows_log_event::unpack_current_row() is used to unpack or skip a row event. In the latter case, computing generated columns is meaningless and sometimes harmful. Fix --- Never compute any generated columns for only-seek calls. --- .../suite/rpl/r/rpl_functional_index.result | 19 ++++++++++++++ .../suite/rpl/t/rpl_functional_index.test | 25 +++++++++++++++++++ sql/log_event.cc | 12 ++++----- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_functional_index.result b/mysql-test/suite/rpl/r/rpl_functional_index.result index 83efc20c8..87384703f 100644 --- a/mysql-test/suite/rpl/r/rpl_functional_index.result +++ b/mysql-test/suite/rpl/r/rpl_functional_index.result @@ -205,4 +205,23 @@ INSERT INTO t VALUES (1, 2); include/sync_slave_sql_with_master.inc include/diff_tables.inc [master:test.t,slave:test.t] DROP TABLE t; +# +# Bug#107366 REPLICATION ERROR WITH HASH_SCAN ROW SEARCH ALGORITHM FOR +# FUNCTIONAL INDEXES +CREATE TABLE t1 ( +id int, +c1 json NOT NULL, +c2 int, +KEY comp ((cast(c1 as unsigned array))) +) ENGINE=InnoDB; +insert into t1 values(1,'[1046, 2995]',1); +update t1 set c2=2; +select * from t1; +id c1 c2 +1 [1046, 2995] 2 +include/sync_slave_sql_with_master.inc +select * from t1; +id c1 c2 +1 [1046, 2995] 2 +DROP TABLE t1; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_functional_index.test b/mysql-test/suite/rpl/t/rpl_functional_index.test index 038955384..7425ebb2e 100644 --- a/mysql-test/suite/rpl/t/rpl_functional_index.test +++ b/mysql-test/suite/rpl/t/rpl_functional_index.test @@ -183,4 +183,29 @@ INSERT INTO t VALUES (1, 2); --connection master DROP TABLE t; +--echo # +--echo # Bug#107366 REPLICATION ERROR WITH HASH_SCAN ROW SEARCH ALGORITHM FOR +--echo # FUNCTIONAL INDEXES +--connection master + +CREATE TABLE t1 ( + id int, + c1 json NOT NULL, + c2 int, + KEY comp ((cast(c1 as unsigned array))) +) ENGINE=InnoDB; + +insert into t1 values(1,'[1046, 2995]',1); + +update t1 set c2=2; + +select * from t1; + +--source include/sync_slave_sql_with_master.inc + +select * from t1; + +--connection master +DROP TABLE t1; + --source include/rpl_end.inc diff --git a/sql/log_event.cc b/sql/log_event.cc index 64f93d089..faa0f3b03 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -8174,12 +8174,12 @@ int Rows_log_event::unpack_current_row(const Relay_log_info *const rli, updatable_columns_view.get_included_fields_bitmap())) { return thd->get_stmt_da()->mysql_errno(); /* purecov: deadcode */ } - } - if (is_after_image && - !bitmap_is_clear_all(&this->m_table->fields_for_functional_indexes)) { - if (this->update_generated_columns( - this->m_table->fields_for_functional_indexes)) - return thd->get_stmt_da()->mysql_errno(); /* purecov: deadcode */ + if (is_after_image && + !bitmap_is_clear_all(&this->m_table->fields_for_functional_indexes)) { + if (this->update_generated_columns( + this->m_table->fields_for_functional_indexes)) + return thd->get_stmt_da()->mysql_errno(); /* purecov: deadcode */ + } } } -- 2.32.0