diff --git a/mysql-test/extra/binlog_tests/binlog.test b/mysql-test/extra/binlog_tests/binlog.test index 8fe710e2ac7..f982b87aae7 100644 --- a/mysql-test/extra/binlog_tests/binlog.test +++ b/mysql-test/extra/binlog_tests/binlog.test @@ -408,4 +408,22 @@ SHOW SESSION VARIABLES LIKE "unique_checks"; DROP TABLE t1; disconnect fresh; +connection default; +--echo # +--echo # MDEV-25595 DROP part of failed CREATE OR REPLACE is not written into binary log +--echo # +reset master; +--error ER_DUP_FIELDNAME +create table t as select 1 as b, 2 as b; +create table t (old_table_field int); +--error ER_DUP_FIELDNAME +create or replace table t as select 1 as b, 2 as b; +--error ER_DUP_FIELDNAME +create or replace temporary table t as select 1 as b, 2 as b; +create table t (new_table_field int); + +--source include/show_binlog_events.inc + +# cleanup +drop table t; diff --git a/mysql-test/suite/binlog/r/binlog_row_binlog.result b/mysql-test/suite/binlog/r/binlog_row_binlog.result index 4068a80771c..948ccee58ca 100644 --- a/mysql-test/suite/binlog/r/binlog_row_binlog.result +++ b/mysql-test/suite/binlog/r/binlog_row_binlog.result @@ -1073,3 +1073,26 @@ Variable_name Value unique_checks OFF DROP TABLE t1; disconnect fresh; +connection default; +# +# MDEV-25595 DROP part of failed CREATE OR REPLACE is not written into binary log +# +reset master; +create table t as select 1 as b, 2 as b; +ERROR 42S21: Duplicate column name 'b' +create table t (old_table_field int); +create or replace table t as select 1 as b, 2 as b; +ERROR 42S21: Duplicate column name 'b' +create or replace temporary table t as select 1 as b, 2 as b; +ERROR 42S21: Duplicate column name 'b' +create table t (new_table_field int); +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; create table t (old_table_field int) +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS `test`.`t`/* Generated to handle failed CREATE OR REPLACE */ +master-bin.000001 # Query # # ROLLBACK +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; create table t (new_table_field int) +drop table t; diff --git a/mysql-test/suite/binlog/r/binlog_stm_binlog.result b/mysql-test/suite/binlog/r/binlog_stm_binlog.result index 872ba40e05f..5016ed70242 100644 --- a/mysql-test/suite/binlog/r/binlog_stm_binlog.result +++ b/mysql-test/suite/binlog/r/binlog_stm_binlog.result @@ -673,3 +673,27 @@ Variable_name Value unique_checks OFF DROP TABLE t1; disconnect fresh; +connection default; +# +# MDEV-25595 DROP part of failed CREATE OR REPLACE is not written into binary log +# +reset master; +create table t as select 1 as b, 2 as b; +ERROR 42S21: Duplicate column name 'b' +create table t (old_table_field int); +create or replace table t as select 1 as b, 2 as b; +ERROR 42S21: Duplicate column name 'b' +create or replace temporary table t as select 1 as b, 2 as b; +ERROR 42S21: Duplicate column name 'b' +create table t (new_table_field int); +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; create table t (old_table_field int) +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS `test`.`t`/* Generated to handle failed CREATE OR REPLACE */ +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # DROP TEMPORARY TABLE IF EXISTS `test`.`t`/* Generated to handle failed CREATE OR REPLACE */ +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; create table t (new_table_field int) +drop table t; diff --git a/mysql-test/suite/rpl/r/create_or_replace_mix.result b/mysql-test/suite/rpl/r/create_or_replace_mix.result index 661278aa7ef..b44b2a5c10f 100644 --- a/mysql-test/suite/rpl/r/create_or_replace_mix.result +++ b/mysql-test/suite/rpl/r/create_or_replace_mix.result @@ -100,6 +100,9 @@ include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; create table t1 (a int) +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS `test`.`t1`/* Generated to handle failed CREATE OR REPLACE */ +master-bin.000001 # Query # # ROLLBACK drop table if exists t1,t2; Warnings: Note 1051 Unknown table 'test.t1' diff --git a/mysql-test/suite/rpl/r/create_or_replace_row.result b/mysql-test/suite/rpl/r/create_or_replace_row.result index c45daefd671..16f92b5e4b6 100644 --- a/mysql-test/suite/rpl/r/create_or_replace_row.result +++ b/mysql-test/suite/rpl/r/create_or_replace_row.result @@ -128,6 +128,9 @@ include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; create table t1 (a int) +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS `test`.`t1`/* Generated to handle failed CREATE OR REPLACE */ +master-bin.000001 # Query # # ROLLBACK drop table if exists t1,t2; Warnings: Note 1051 Unknown table 'test.t1' diff --git a/mysql-test/suite/rpl/r/create_or_replace_statement.result b/mysql-test/suite/rpl/r/create_or_replace_statement.result index f95b451e5ec..4d6409b1710 100644 --- a/mysql-test/suite/rpl/r/create_or_replace_statement.result +++ b/mysql-test/suite/rpl/r/create_or_replace_statement.result @@ -103,6 +103,8 @@ include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; create table t1 (a int) +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS `test`.`t1`/* Generated to handle failed CREATE OR REPLACE */ drop table if exists t1,t2; Warnings: Note 1051 Unknown table 'test.t1' diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 90cf8782d48..51b2c84cfea 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -4386,8 +4386,18 @@ select_create::prepare(List &values, SELECT_LEX_UNIT *u) create_table, alter_info, &values, &extra_lock, hook_ptr))) + { + if (create_info->or_replace()) + { + /* Original table was deleted. We have to log it */ + log_drop_table(thd, create_table->db, create_table->db_length, + create_table->table_name, create_table->table_name_length, + thd->lex->tmp_table()); + } + /* abort() deletes table */ DBUG_RETURN(-1); + } if (create_info->tmp_table()) {