summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorVlad Lesin <vlad_lesin@mail.ru>2022-03-02 21:29:53 +0300
committerVlad Lesin <vlad_lesin@mail.ru>2022-03-10 15:38:43 +0300
commit1766a18e06a056155031dabefb88ce7f201ad921 (patch)
treef3f15e182dae7e881ab6d1146990e0e18d2c6b7c /sql
parente7cf871dda59ad39c9125288149a4ec38518d41c (diff)
downloadmariadb-git-1766a18e06a056155031dabefb88ce7f201ad921.tar.gz
MDEV-19577 Replication does not work with innodb_autoinc_lock_mode=2
The first step for deprecating innodb_autoinc_lock_mode(see MDEV-27844) is: - to switch statement binlog format to ROW if binlog format is MIXED and the statement changes autoincremented fields - issue warnings if innodb_autoinc_lock_mode == 2 and binlog format is STATEMENT
Diffstat (limited to 'sql')
-rw-r--r--sql/handler.h5
-rw-r--r--sql/sql_class.cc9
-rw-r--r--sql/sql_lex.cc9
-rw-r--r--sql/sql_lex.h5
4 files changed, 27 insertions, 1 deletions
diff --git a/sql/handler.h b/sql/handler.h
index 91225982e9e..c65b7b6a8d5 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -4668,6 +4668,11 @@ public:
const uchar *pack_frm_data,
size_t pack_frm_len)
{ return HA_ERR_WRONG_COMMAND; }
+ /* @return true if it's necessary to switch current statement log format from
+ STATEMENT to ROW if binary log format is MIXED and autoincrement values
+ are changed in the statement */
+ virtual bool autoinc_lock_mode_stmt_unsafe() const
+ { return false; }
virtual int drop_partitions(const char *path)
{ return HA_ERR_WRONG_COMMAND; }
virtual int rename_partitions(const char *path)
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 7f5a6345770..c808a2c997c 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -6079,6 +6079,10 @@ int THD::decide_logging_format(TABLE_LIST *tables)
bool is_write= FALSE; // If any write tables
bool has_read_tables= FALSE; // If any read only tables
bool has_auto_increment_write_tables= FALSE; // Write with auto-increment
+ /* true if it's necessary to switch current statement log format from
+ STATEMENT to ROW if binary log format is MIXED and autoincrement values
+ are changed in the statement */
+ bool has_unsafe_stmt_autoinc_lock_mode= false;
/* If a write table that doesn't have auto increment part first */
bool has_write_table_auto_increment_not_first_in_pk= FALSE;
bool has_auto_increment_write_tables_not_first= FALSE;
@@ -6200,6 +6204,8 @@ int THD::decide_logging_format(TABLE_LIST *tables)
has_auto_increment_write_tables_not_first= found_first_not_own_table;
if (share->next_number_keypart != 0)
has_write_table_auto_increment_not_first_in_pk= true;
+ has_unsafe_stmt_autoinc_lock_mode=
+ table->file->autoinc_lock_mode_stmt_unsafe();
}
}
@@ -6268,6 +6274,9 @@ int THD::decide_logging_format(TABLE_LIST *tables)
if (has_write_tables_with_unsafe_statements)
lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
+ if (has_unsafe_stmt_autoinc_lock_mode)
+ lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_AUTOINC_LOCK_MODE);
+
/*
A query that modifies autoinc column in sub-statement can make the
master and slave inconsistent.
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 228635915a0..d51b9bd5a26 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -75,7 +75,14 @@ Query_tables_list::binlog_stmt_unsafe_errcode[BINLOG_STMT_UNSAFE_COUNT] =
ER_BINLOG_UNSAFE_CREATE_SELECT_AUTOINC,
ER_BINLOG_UNSAFE_UPDATE_IGNORE,
ER_BINLOG_UNSAFE_INSERT_TWO_KEYS,
- ER_BINLOG_UNSAFE_AUTOINC_NOT_FIRST
+ ER_BINLOG_UNSAFE_AUTOINC_NOT_FIRST,
+ /*
+ There is no need to add new error code as we plan to get rid of auto
+ increment lock mode variable, so we use existing error code below, add
+ the correspondent text to the existing error message during merging to
+ non-GA release.
+ */
+ ER_BINLOG_UNSAFE_SYSTEM_VARIABLE
};
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 69dda691e45..e1f34afa350 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1740,6 +1740,11 @@ public:
*/
BINLOG_STMT_UNSAFE_AUTOINC_NOT_FIRST,
+ /**
+ Autoincrement lock mode is incompatible with STATEMENT binlog format.
+ */
+ BINLOG_STMT_UNSAFE_AUTOINC_LOCK_MODE,
+
/* The last element of this enumeration type. */
BINLOG_STMT_UNSAFE_COUNT
};