diff options
Diffstat (limited to 'sql/sql_base.cc')
-rw-r--r-- | sql/sql_base.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 704cfaa86cf..0031da0c6b2 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -219,6 +219,7 @@ static bool has_write_table_with_auto_increment(TABLE_LIST *tables); static bool has_write_table_with_auto_increment_and_select(TABLE_LIST *tables); +static bool has_write_table_auto_increment_not_first_in_pk(TABLE_LIST *tables); uint cached_open_tables(void) { @@ -5752,6 +5753,12 @@ bool lock_tables(THD *thd, TABLE_LIST *tables, uint count, 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); + /* Todo: merge all has_write_table_auto_inc with decide_logging_format */ + if (thd->variables.binlog_format != BINLOG_FORMAT_ROW && tables) + { + if (has_write_table_auto_increment_not_first_in_pk(tables)) + thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_AUTOINC_NOT_FIRST); + } /* INSERT...ON DUPLICATE KEY UPDATE on a table with more than one unique keys @@ -9513,6 +9520,32 @@ has_write_table_with_auto_increment_and_select(TABLE_LIST *tables) return(has_select && has_auto_increment_tables); } +/* + Tells if there is a table whose auto_increment column is a part + of a compound primary key while is not the first column in + the table definition. + + @param tables Table list + + @return true if the table exists, fais if does not. +*/ + +static bool +has_write_table_auto_increment_not_first_in_pk(TABLE_LIST *tables) +{ + for (TABLE_LIST *table= tables; table; table= table->next_global) + { + /* we must do preliminary checks as table->table may be NULL */ + if (!table->placeholder() && + table->table->found_next_number_field && + (table->lock_type >= TL_WRITE_ALLOW_WRITE) + && table->table->s->next_number_keypart != 0) + return 1; + } + + return 0; +} + /* |