diff --git a/mysql-test/main/alter_table_online_debug.result b/mysql-test/main/alter_table_online_debug.result index 882d5ceea56..ab9417e5fc8 100644 --- a/mysql-test/main/alter_table_online_debug.result +++ b/mysql-test/main/alter_table_online_debug.result @@ -16,6 +16,8 @@ connection con2; insert into t1 values (123), (456), (789); set debug_sync= 'now SIGNAL end'; connection default; +affected rows: 4 +info: Records: 4 Duplicates: 0 Warnings: 0 select * from t1; a b 5 NULL @@ -123,6 +125,8 @@ connection con2; update t1 set b= 55 where a = 1; set debug_sync= 'now SIGNAL end'; connection default; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 select * from t1; a b c 1 55 1 diff --git a/mysql-test/main/alter_table_online_debug.test b/mysql-test/main/alter_table_online_debug.test index ee3829e089e..b486eb9fb42 100644 --- a/mysql-test/main/alter_table_online_debug.test +++ b/mysql-test/main/alter_table_online_debug.test @@ -33,7 +33,9 @@ insert into t1 values (123), (456), (789); set debug_sync= 'now SIGNAL end'; --connection default +--enable_info --reap +--disable_info select * from t1; --echo # Insert, error @@ -167,7 +169,9 @@ update t1 set b= 55 where a = 1; set debug_sync= 'now SIGNAL end'; --connection default +--enable_info --reap +--disable_info select * from t1; --echo # Update and add a column in the middle diff --git a/sql/log_event.h b/sql/log_event.h index c2bced6ef3d..17d642bebaf 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -1564,6 +1564,12 @@ public: #if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) + /** + Increase or decrease the rows inserted during ALTER TABLE based on the event + type. + */ + virtual void online_alter_update_row_count(ha_rows *) const {} + /** Apply the event to the database. @@ -4973,6 +4979,11 @@ public: #if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) uint8 get_trg_event_map() const override; + + void online_alter_update_row_count(ha_rows *rows) const override + { + *rows += m_row_count; + } #endif private: @@ -5148,6 +5159,11 @@ public: #if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) uint8 get_trg_event_map() const override; + + void online_alter_update_row_count(ha_rows *rows) const override + { + *rows -= m_row_count; + } #endif protected: diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index b6fd00b267c..00295c32196 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -5184,6 +5184,7 @@ int Rows_log_event::do_apply_event(rpl_group_info *rgi) thd->transaction->stmt.modified_non_trans_table= TRUE; if (likely(error == 0)) { + m_row_count++; error= thd->killed_errno(); if (error && !thd->is_error()) my_error(error, MYF(0)); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 6b30849a8ff..e536ccdf3fb 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -11656,7 +11656,8 @@ public: static int online_alter_read_from_binlog(THD *thd, rpl_group_info *rgi, - Cache_flip_event_log *log) + Cache_flip_event_log *log, + ha_rows *found_rows) { int error= 0; @@ -11681,8 +11682,11 @@ static int online_alter_read_from_binlog(THD *thd, rpl_group_info *rgi, ev->thd= thd; error= ev->apply_event(rgi); - if (thd->is_error()) - error= 1; + + error= error || thd->is_error(); + if(likely(!error)) + ev->online_alter_update_row_count(found_rows); + if (ev != rgi->rli->relay_log.description_event_for_exec) delete ev; thd_progress_report(thd, my_b_tell(log_file), thd->progress.max_counter); @@ -12108,7 +12112,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, mysql_unlock_tables(thd, thd->lock); thd->lock= NULL; - error= online_alter_read_from_binlog(thd, &rgi, binlog); + error= online_alter_read_from_binlog(thd, &rgi, binlog, &found_count); if (start_alter_id) { DBUG_ASSERT(thd->slave_thread); @@ -12129,7 +12133,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, if (!error) { thd_progress_next_stage(thd); - error= online_alter_read_from_binlog(thd, &rgi, binlog); + error= online_alter_read_from_binlog(thd, &rgi, binlog, &found_count); } if (error) from->s->tdc->flush_unused(1); // to free the binlog