summaryrefslogtreecommitdiff
path: root/sql/sql_base.cc
diff options
context:
space:
mode:
authorAndrei Elkin <andrei.elkin@oracle.com>2012-04-21 13:24:39 +0300
committerAndrei Elkin <andrei.elkin@oracle.com>2012-04-21 13:24:39 +0300
commit14de6de946d78dc2c5674d7d1e27edc170e5de6b (patch)
tree5f529072426678936974bb7abecd548dc5af7004 /sql/sql_base.cc
parentdcb5071b1906d76b4c61d3125ddc7368f3ee8c4f (diff)
parent49e484c8cd2e362e843bbd5d756422cc7e2686d3 (diff)
downloadmariadb-git-14de6de946d78dc2c5674d7d1e27edc170e5de6b.tar.gz
merge bug11754117-45670 fixes from 5.1.
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 a411e433faf..efd9c4dfd4a 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -216,6 +216,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)
{
@@ -5690,6 +5691,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
@@ -9152,6 +9159,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;
+}
+
/*