diff --git a/sql/binlog.cc b/sql/binlog.cc index 1073e7eb978..c82aeb8db06 100644 --- a/sql/binlog.cc +++ b/sql/binlog.cc @@ -10573,7 +10573,7 @@ has_write_table_with_auto_increment(TABLE_LIST *tables) */ static bool -has_write_table_with_auto_increment_and_select(TABLE_LIST *tables) +has_write_table_with_auto_increment_and_select(THD *thd, TABLE_LIST *tables) { bool has_select= false; bool has_auto_increment_tables = has_write_table_with_auto_increment(tables); @@ -10586,6 +10586,17 @@ has_write_table_with_auto_increment_and_select(TABLE_LIST *tables) break; } } + if (!has_select && thd->lex->sql_command == SQLCOM_INSERT_SELECT) + { + sys_var *autoinc_lock_mode= find_sys_var(thd, "innodb_autoinc_lock_mode"); + if (likely(autoinc_lock_mode)) + { + /* innodb_autoinc_lock_mode is a read only variable. */ + long mode= *reinterpret_cast( + autoinc_lock_mode->global_value_ptr_no_lock(thd, NULL)); + if (mode == 2) has_select= true; + } + } return(has_select && has_auto_increment_tables); } @@ -10863,7 +10874,7 @@ int THD::decide_logging_format(TABLE_LIST *tables) fetched fron the select tables cannot be determined and may differ on master and slave. */ - if (has_write_table_with_auto_increment_and_select(tables)) + if (has_write_table_with_auto_increment_and_select(this, tables)) lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_WRITE_AUTOINC_SELECT); if (has_write_table_auto_increment_not_first_in_pk(tables)) diff --git a/sql/set_var.cc b/sql/set_var.cc index ba6ab912e06..10e9b03fd99 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1089,3 +1089,10 @@ void set_var_collation_client::print(THD *thd, String *str) } } } + +uchar *sys_var::global_value_ptr_no_lock(THD *thd, LEX_STRING *base) +{ + /* Note: must be read only. */ + assert(is_readonly()); + return global_value_ptr(thd, base); +} diff --git a/sql/set_var.h b/sql/set_var.h index ac7df7fa1ff..d1d4224f685 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -239,6 +239,9 @@ protected: uchar *session_var_ptr(THD *thd); uchar *global_var_ptr(); + +public: + uchar *global_value_ptr_no_lock(THD *thd, LEX_STRING *base); }; class Sys_var_tracker