mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
BUG#11758263 50440: MARK UNORDERED UPDATE WITH AUTOINC UNSAFE
Problem: Statements that write to tables with auto_increment columns based on the selection from another table, may lead to master and slave going out of sync, as the order in which the rows are retrieved from the table may differ on master and slave. Solution: We mark writing to a table with auto_increment table based on the rows selected from another table as unsafe. This will cause the execution of such statements to throw a warning and forces the statement to be logged in ROW if the logging format is mixed. Changes: 1. All the statements that writes to a table with auto_increment column(s) based on the rows fetched from another table, will now be unsafe. 2. CREATE TABLE with SELECT will now be unsafe.
This commit is contained in:
@ -214,7 +214,8 @@ static bool auto_repair_table(THD *thd, TABLE_LIST *table_list);
|
||||
static void free_cache_entry(TABLE *entry);
|
||||
static bool
|
||||
has_write_table_with_auto_increment(TABLE_LIST *tables);
|
||||
|
||||
static bool
|
||||
has_write_table_with_auto_increment_and_select(TABLE_LIST *tables);
|
||||
|
||||
uint cached_open_tables(void)
|
||||
{
|
||||
@ -5683,6 +5684,17 @@ bool lock_tables(THD *thd, TABLE_LIST *tables, uint count,
|
||||
/* We have to emulate LOCK TABLES if we are statement needs prelocking. */
|
||||
if (thd->lex->requires_prelocking())
|
||||
{
|
||||
|
||||
/*
|
||||
DML statements that modify a table with an auto_increment column based on
|
||||
rows selected from a table are unsafe as the order in which the rows are
|
||||
fetched fron the select tables cannot be determined and may differ on
|
||||
master and slave.
|
||||
*/
|
||||
if (thd->variables.binlog_format != BINLOG_FORMAT_ROW && tables &&
|
||||
has_write_table_with_auto_increment_and_select(tables))
|
||||
thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_WRITE_AUTOINC_SELECT);
|
||||
|
||||
/*
|
||||
A query that modifies autoinc column in sub-statement can make the
|
||||
master and slave inconsistent.
|
||||
@ -9080,6 +9092,41 @@ has_write_table_with_auto_increment(TABLE_LIST *tables)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
checks if the tables have select tables in the table list and write tables
|
||||
with auto-increment column.
|
||||
|
||||
SYNOPSIS
|
||||
has_two_write_locked_tables_with_auto_increment_and_select
|
||||
tables Table list
|
||||
|
||||
RETURN VALUES
|
||||
|
||||
-true if the table list has atleast one table with auto-increment column
|
||||
|
||||
|
||||
and atleast one table to select from.
|
||||
-false otherwise
|
||||
*/
|
||||
|
||||
static bool
|
||||
has_write_table_with_auto_increment_and_select(TABLE_LIST *tables)
|
||||
{
|
||||
bool has_select= false;
|
||||
bool has_auto_increment_tables = has_write_table_with_auto_increment(tables);
|
||||
for(TABLE_LIST *table= tables; table; table= table->next_global)
|
||||
{
|
||||
if (!table->placeholder() &&
|
||||
(table->lock_type <= TL_READ_NO_INSERT))
|
||||
{
|
||||
has_select= true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return(has_select && has_auto_increment_tables);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Open and lock system tables for read.
|
||||
|
Reference in New Issue
Block a user