diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 9837d44adf0..bf032d3ca03 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -11135,7 +11135,7 @@ do_continue:; debug_crash_here("ddl_log_alter_after_copy"); // Use old table /* - We are new ready to use the new table. Update the state in the + We are now ready to use the new table. Update the state in the ddl log so that we recovery know that the new table is ready and in case of crash it should use the new one and log the query to the binary log. diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 1f8744465a2..f147235f669 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -15958,9 +15958,22 @@ ha_innobase::extra( break; case HA_EXTRA_END_ALTER_COPY: trx = check_trx_exists(ha_thd()); + if (!m_prebuilt->table->skip_alter_undo) { + /* This could be invoked inside INSERT...SELECT. + We do not want any extra log writes, because + they could cause a severe performance regression. */ + break; + } m_prebuilt->table->skip_alter_undo = 0; if (!m_prebuilt->table->is_temporary() && !high_level_read_only) { + /* The extra log write is necessary for + ALTER TABLE...ALGORITHM=COPY, because + a normal transaction commit would be a no-op + because no undo log records were generated. + This log write will also be unnecessarily executed + during CREATE...SELECT, which is the other caller of + handler::extra(HA_EXTRA_BEGIN_ALTER_COPY). */ log_buffer_flush_to_disk(); } break;