From 32c3d775e98696ace49fb34e434ca5963179b37e Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 31 May 2022 22:06:27 +0200 Subject: [PATCH] Online alter: set read_set early, before row reads also * don't modify write_set * backup/restore rpl_write_set --- sql/handler.cc | 9 ++++++--- sql/table.cc | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index 33b9d693894..be3816b7b60 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -7272,14 +7272,17 @@ static int binlog_log_row_online_alter(TABLE* table, trans_register_ha(thd, true, binlog_hton, 0); } - // We need to log all columns for the case if alter table changes primary key. - table->use_all_columns(); - bitmap_set_all(table->rpl_write_set); + // We need to log all columns for the case if alter table changes primary key + DBUG_ASSERT(!before_record || bitmap_is_set_all(table->read_set)); + MY_BITMAP *old_rpl_write_set= table->rpl_write_set; + table->rpl_write_set= &table->s->all_set; int error= (*log_func)(thd, table, table->s->online_alter_binlog, table->online_alter_cache, has_trans, before_record, after_record); + table->rpl_write_set= old_rpl_write_set; + return unlikely(error) ? HA_ERR_RBR_LOGGING_FAILED : 0; } #endif // HAVE_REPLICATION diff --git a/sql/table.cc b/sql/table.cc index 33d38041f5f..2078470e65c 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -7681,6 +7681,17 @@ void TABLE::mark_columns_needed_for_delete() bitmap_set_bit(write_set, s->vers.end_fieldno); need_signal= true; } +#ifdef HAVE_REPLICATION + if (s->online_alter_binlog) + { + /* + For online alter we have to read all columns, because we need PK columns + in the row event, and we don't know what columns will be in PK after ALTER + */ + bitmap_set_all(read_set); + need_signal= true; + } +#endif if (need_signal) file->column_bitmaps_signal(); @@ -7767,9 +7778,20 @@ void TABLE::mark_columns_needed_for_update() For System Versioning we have to read all columns since we store a copy of previous row with modified row_end back to a table. */ - bitmap_union(read_set, &s->all_set); + bitmap_set_all(read_set); need_signal= true; } +#ifdef HAVE_REPLICATION + if (s->online_alter_binlog) + { + /* + For online alter we have to read all columns, because we need PK columns + in the row event, and we don't know what columns will be in PK after ALTER + */ + bitmap_set_all(read_set); + need_signal= true; + } +#endif if (check_constraints) { mark_check_constraint_columns_for_read();