summaryrefslogtreecommitdiff
path: root/sql/sql_base.cc
diff options
context:
space:
mode:
authorRohit Kalhans <rohit.kalhans@oracle.com>2012-02-08 00:33:08 +0530
committerRohit Kalhans <rohit.kalhans@oracle.com>2012-02-08 00:33:08 +0530
commit6df5a61d2ee53ae43aafe07a697d7be3344a14d7 (patch)
treead0d8d355079009a9bed9b3d9a84fc0c55cdcb24 /sql/sql_base.cc
parentc8d8a92300edab63017a3176d5f3718e19577928 (diff)
downloadmariadb-git-6df5a61d2ee53ae43aafe07a697d7be3344a14d7.tar.gz
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 retrived from the table may differ on master and slave. Solution: We mark writing to a table with auto_increment 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.
Diffstat (limited to 'sql/sql_base.cc')
-rw-r--r--sql/sql_base.cc41
1 files changed, 40 insertions, 1 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index e0472e2c9b5..fda0ba61e63 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -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,11 @@ 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())
{
+
+ 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 +9086,39 @@ 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.