mirror of
https://github.com/MariaDB/server.git
synced 2026-04-24 09:15:30 +02: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:
parent
d1655ba6c4
commit
c4bb7cd6dc
11 changed files with 335 additions and 30 deletions
|
|
@ -3960,6 +3960,7 @@ static TABLE *create_table_from_items(THD *thd, HA_CREATE_INFO *create_info,
|
|||
*/
|
||||
DBUG_ASSERT(0);
|
||||
}
|
||||
DBUG_ASSERT(create_table->table == create_info->table);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -4247,6 +4248,8 @@ bool select_create::send_eof()
|
|||
if (!(thd->variables.option_bits & OPTION_GTID_BEGIN))
|
||||
trans_commit_implicit(thd);
|
||||
}
|
||||
else if (!thd->is_current_stmt_binlog_format_row())
|
||||
table->s->table_creation_was_logged= 1;
|
||||
|
||||
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
|
||||
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
|
||||
|
|
@ -4310,8 +4313,7 @@ void select_create::abort_result_set()
|
|||
*/
|
||||
|
||||
save_option_bits= thd->variables.option_bits;
|
||||
if (!(thd->log_current_statement))
|
||||
thd->variables.option_bits&= ~OPTION_BIN_LOG;
|
||||
thd->variables.option_bits&= ~OPTION_BIN_LOG;
|
||||
select_insert::abort_result_set();
|
||||
thd->transaction.stmt.modified_non_trans_table= FALSE;
|
||||
thd->variables.option_bits= save_option_bits;
|
||||
|
|
@ -4334,11 +4336,21 @@ void select_create::abort_result_set()
|
|||
|
||||
if (table)
|
||||
{
|
||||
bool tmp_table= table->s->tmp_table;
|
||||
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
|
||||
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
|
||||
table->auto_increment_field_not_null= FALSE;
|
||||
drop_open_table(thd, table, create_table->db, create_table->table_name);
|
||||
table=0; // Safety
|
||||
if (thd->log_current_statement)
|
||||
{
|
||||
/* Remove logging of drop, create + insert rows */
|
||||
binlog_reset_cache(thd);
|
||||
/* 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,
|
||||
tmp_table);
|
||||
}
|
||||
}
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue