summaryrefslogtreecommitdiff
path: root/sql/sql_base.cc
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2012-06-14 20:05:31 +0200
committerSergei Golubchik <sergii@pisem.net>2012-06-14 20:05:31 +0200
commit0522307ed1b4aeef16dd94606d0b0f6e974b29a5 (patch)
treeac9829d5d4b0e676c984b931702282c446e604ea /sql/sql_base.cc
parentd2ca6d2e7ff028f6abbab52e36530046b3f84a49 (diff)
parent326b40c9c8160db414288925936449e55f4f3a0a (diff)
downloadmariadb-git-0522307ed1b4aeef16dd94606d0b0f6e974b29a5.tar.gz
mysql-5.5 merge
Diffstat (limited to 'sql/sql_base.cc')
-rw-r--r--sql/sql_base.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 688108555d6..acd330dd4d2 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)
{
@@ -5745,6 +5746,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
@@ -9506,6 +9513,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;
+}
+
/*