mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +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:
@ -67,6 +67,9 @@ ERROR 23000: Duplicate entry '2' for key 'PRIMARY'
|
||||
create table t1 (a int);
|
||||
create or replace table t1 (a int primary key) select a from t2;
|
||||
ERROR 23000: Duplicate entry '2' for key 'PRIMARY'
|
||||
create temporary table t9 (a int);
|
||||
create or replace temporary table t9 (a int primary key) select a from t2;
|
||||
ERROR 23000: Duplicate entry '2' for key 'PRIMARY'
|
||||
binlog from server 1
|
||||
include/show_binlog_events.inc
|
||||
Log_name Pos Event_type Server_id End_log_pos Info
|
||||
@ -79,13 +82,27 @@ master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS `t1` /* generated
|
||||
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`; create or replace table t1 (a int primary key) select a from t2
|
||||
master-bin.000001 # Query # # use `test`; DROP TABLE IF EXISTS `test`.`t1`/* Generated to handle failed CREATE OR REPLACE */
|
||||
master-bin.000001 # Gtid # # GTID #-#-#
|
||||
master-bin.000001 # Query # # use `test`; create temporary table t9 (a int)
|
||||
master-bin.000001 # Gtid # # GTID #-#-#
|
||||
master-bin.000001 # Query # # DROP TEMPORARY TABLE IF EXISTS `test`.`t9`/* Generated to handle failed CREATE OR REPLACE */
|
||||
show tables;
|
||||
Tables_in_test
|
||||
t2
|
||||
create table t1 (a int);
|
||||
create or replace table t1 (a int, a int) select * from t2;
|
||||
ERROR 42S21: Duplicate column name 'a'
|
||||
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)
|
||||
drop table if exists t1,t2;
|
||||
Warnings:
|
||||
Note 1051 Unknown table 'test.t1'
|
||||
drop temporary table if exists t9;
|
||||
Warnings:
|
||||
Note 1051 Unknown table 'test.t9'
|
||||
#
|
||||
# Ensure that CREATE are run as CREATE OR REPLACE on slave
|
||||
#
|
||||
@ -140,5 +157,39 @@ slave-bin.000001 # Query # # use `test`; create table t2 engine=myisam select *
|
||||
slave-bin.000001 # Gtid # # GTID #-#-#
|
||||
slave-bin.000001 # Query # # use `test`; create or replace table t2 engine=innodb select * from t1
|
||||
drop table t1;
|
||||
drop table t2,t3;
|
||||
#
|
||||
# Check logging of drop temporary table
|
||||
#
|
||||
drop temporary table t3;
|
||||
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);
|
||||
set binlog_format="STATEMENT";
|
||||
ERROR HY000: Cannot switch out of the row-based binary log format when the session has open temporary tables
|
||||
drop temporary table t8;
|
||||
set @@binlog_format=@org_binlog_format;
|
||||
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 temporary table t5 (a int)
|
||||
master-bin.000001 # Gtid # # GTID #-#-#
|
||||
master-bin.000001 # Query # # use `test`; DROP TEMPORARY TABLE `t5` /* generated by server */
|
||||
master-bin.000001 # Gtid # # GTID #-#-#
|
||||
master-bin.000001 # Query # # DROP TEMPORARY TABLE IF EXISTS `test`.`t6` /* generated by server */
|
||||
master-bin.000001 # Gtid # # GTID #-#-#
|
||||
master-bin.000001 # Query # # use `test`; create temporary table t7 (a int)
|
||||
master-bin.000001 # Gtid # # GTID #-#-#
|
||||
master-bin.000001 # Query # # DROP TEMPORARY TABLE IF EXISTS `test`.`t7` /* generated by server */
|
||||
master-bin.000001 # Gtid # # GTID #-#-#
|
||||
master-bin.000001 # Query # # DROP TEMPORARY TABLE IF EXISTS `test`.`t8` /* generated by server */
|
||||
drop table t2;
|
||||
include/rpl_end.inc
|
||||
|
Reference in New Issue
Block a user