From c411393a844becf91a560ac8e53ab04cb4fb9219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 28 Jan 2021 15:26:53 +0200 Subject: [PATCH] MDEV-24715 Assertion !node->table->skip_alter_undo in CREATE...REPLACE SELECT In commit 3cef4f8f0fc88ae5bfae4603d8d600ec84cc70a9 (MDEV-515) we inadvertently broke CREATE TABLE...REPLACE SELECT statements by wrongly disabling row-level undo logging. select_create::prepare(): Only invoke extra(HA_EXTRA_BEGIN_ALTER_COPY) if no special treatment of duplicates is needed. --- .../suite/innodb/r/insert_into_empty.result | 15 +++++++++++++++ mysql-test/suite/innodb/t/insert_into_empty.test | 14 ++++++++++++++ sql/sql_insert.cc | 3 ++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 mysql-test/suite/innodb/r/insert_into_empty.result create mode 100644 mysql-test/suite/innodb/t/insert_into_empty.test diff --git a/mysql-test/suite/innodb/r/insert_into_empty.result b/mysql-test/suite/innodb/r/insert_into_empty.result new file mode 100644 index 00000000000..651cadd50b7 --- /dev/null +++ b/mysql-test/suite/innodb/r/insert_into_empty.result @@ -0,0 +1,15 @@ +# +# MDEV-24715 Assertion !node->table->skip_alter_undo +# +CREATE TABLE t (a INT UNIQUE) ENGINE=InnoDB +REPLACE SELECT 1 AS a, 2 AS b UNION SELECT 1 AS a, 3 AS c; +SELECT * FROM t; +a b +1 3 +DROP TABLE t; +CREATE TEMPORARY TABLE t (a INT UNIQUE) ENGINE=InnoDB +REPLACE SELECT 1 AS a, 2 AS b UNION SELECT 1 AS a, 3 AS c; +SELECT * FROM t; +a b +1 3 +DROP TEMPORARY TABLE t; diff --git a/mysql-test/suite/innodb/t/insert_into_empty.test b/mysql-test/suite/innodb/t/insert_into_empty.test new file mode 100644 index 00000000000..945f0dbd627 --- /dev/null +++ b/mysql-test/suite/innodb/t/insert_into_empty.test @@ -0,0 +1,14 @@ +--source include/have_innodb.inc + +--echo # +--echo # MDEV-24715 Assertion !node->table->skip_alter_undo +--echo # +CREATE TABLE t (a INT UNIQUE) ENGINE=InnoDB +REPLACE SELECT 1 AS a, 2 AS b UNION SELECT 1 AS a, 3 AS c; +SELECT * FROM t; +DROP TABLE t; + +CREATE TEMPORARY TABLE t (a INT UNIQUE) ENGINE=InnoDB +REPLACE SELECT 1 AS a, 2 AS b UNION SELECT 1 AS a, 3 AS c; +SELECT * FROM t; +DROP TEMPORARY TABLE t; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 05af99ede79..eb3e1ec7493 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -4746,7 +4746,8 @@ select_create::prepare(List &_values, SELECT_LEX_UNIT *u) if (thd->locked_tables_mode <= LTM_LOCK_TABLES) { table->file->ha_start_bulk_insert((ha_rows) 0); - table->file->extra(HA_EXTRA_BEGIN_ALTER_COPY); + if (thd->lex->duplicates == DUP_ERROR && !thd->lex->ignore) + table->file->extra(HA_EXTRA_BEGIN_ALTER_COPY); } thd->abort_on_warning= !info.ignore && thd->is_strict_mode(); if (check_that_all_fields_are_given_values(thd, table, table_list))