1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Fix for MDEV-5589: "Discrepancy in binlog on half-failed CREATE OR REPLACE"

Now if CREATE OR REPLACE fails but we have deleted a table already, we will generate a DROP TABLE in the binary log.
This fixes this issue.

In addition, for a failing CREATE OR REPLACE TABLE ... SELECT we don't generate a log of all the inserted rows, only the DROP TABLE.

I added code for not logging DROP TEMPORARY TABLE for tables where the CREATE TABLE was not logged. This code will be activated in 10.1
by removing the code protected by DONT_LOG_DROP_OF_TEMPORARY_TABLES.





mysql-test/suite/rpl/r/create_or_replace_mix.result:
  More test cases
mysql-test/suite/rpl/r/create_or_replace_row.result:
  More test cases
mysql-test/suite/rpl/r/create_or_replace_statement.result:
  More test cases
mysql-test/suite/rpl/t/create_or_replace.inc:
  More test cases
sql/log.cc:
  Added binlog_reset_cache() to clear the binary log.
sql/log.h:
  Added prototype
sql/sql_insert.cc:
  If CREATE OR REPLACE TABLE ... SELECT fails:
  - Don't log anything if nothing changed
  - If table was deleted, log a DROP TABLE.
  Remember if we table creation of temporary tables was logged.
sql/sql_table.cc:
  Added log_drop_table()
  Remember if we table creation of temporary tables was logged.
  If CREATE OR REPLACE TABLE ... SELECT fails and a table was deleted, log a DROP TABLE.
sql/sql_table.h:
  Added prototype
sql/sql_truncate.cc:
  Remember if we table creation of temporary tables was logged.
sql/table.h:
  Added table_creation_was_logged
This commit is contained in:
Michael Widenius
2014-03-20 00:59:13 +02:00
parent d1655ba6c4
commit c4bb7cd6dc
11 changed files with 335 additions and 30 deletions

View File

@ -50,10 +50,15 @@ drop table if exists t1;
create or replace table t1 (a int primary key) select a from t2;
create table t1 (a int);
# This should be logged as we will delete t1
# This should as a delete as we will delete t1
--error ER_DUP_ENTRY
create or replace table t1 (a int primary key) select a from t2;
# Same with temporary table
create temporary table t9 (a int);
--error ER_DUP_ENTRY
create or replace temporary table t9 (a int primary key) select a from t2;
--echo binlog from server 1
--source include/show_binlog_events.inc
save_master_pos;
@ -62,7 +67,14 @@ sync_with_master;
show tables;
connection server_1;
--let $binlog_start=query_get_value(SHOW MASTER STATUS, Position, 1)
create table t1 (a int);
--error ER_DUP_FIELDNAME
create or replace table t1 (a int, a int) select * from t2;
--source include/show_binlog_events.inc
drop table if exists t1,t2;
drop temporary table if exists t9;
--echo #
--echo # Ensure that CREATE are run as CREATE OR REPLACE on slave
@ -131,7 +143,34 @@ sync_with_master;
connection server_1;
drop table t1;
--echo #
--echo # Check logging of drop temporary table
--echo #
drop temporary table t3;
--let $binlog_start=query_get_value(SHOW MASTER STATUS, Position, 1)
set @org_binlog_format=@@binlog_format;
set binlog_format="STATEMENT";
create temporary table t5 (a int);
drop temporary table t5;
set binlog_format="ROW";
create temporary table t6 (a int);
drop temporary table t6;
set binlog_format="STATEMENT";
create temporary table t7 (a int);
set binlog_format="ROW";
drop temporary table t7;
create temporary table t8 (a int);
--error ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR
set binlog_format="STATEMENT";
drop temporary table t8;
set @@binlog_format=@org_binlog_format;
--source include/show_binlog_events.inc
# Clean up
drop table t2,t3;
drop table t2;
--source include/rpl_end.inc