From c3c5cd9377d9e8305c33623f4f94cfc90ade37be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 14 Mar 2025 13:06:37 +0200 Subject: [PATCH] =?UTF-8?q?MDEV-35813=20Unnecessary=20InnoDB=20log=20write?= =?UTF-8?q?s=20in=20INSERT=E2=80=A6SELECT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ha_innobase::extra(): Conditionally avoid a log write that had been added in commit e5b9dc15368c7597a70569048eebfc5e05e98ef4 (MDEV-25910) because it may be invoked as part of select_insert::prepare_eof() and not only during DDL operations. Reviewed by: Sergei Golubchik --- sql/sql_table.cc | 2 +- storage/innobase/handler/ha_innodb.cc | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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;