Commit f66fbe8c authored by Jan Lindström's avatar Jan Lindström

MDEV-7578 :Slave is ~10x slower to execute set of statements compared to master when using RBR

Analysis: On master when executing (single/multi) row INSERTs/REPLACEs
InnoDB fallback to old style autoinc locks (table locks)
only if another transaction has already acquired the AUTOINC lock.
Instead on slave as we are executing log_events and sql_command
is not correctly set, InnoDB does not use new style autoinc
locks when it could.

Fix: Use new style autoinc locks also when
thd_sql_command(user_thd) == SQLCOM_END i.e. this is RBR event.
parent 45b6edb1
...@@ -5104,12 +5104,15 @@ ha_innobase::innobase_lock_autoinc(void) ...@@ -5104,12 +5104,15 @@ ha_innobase::innobase_lock_autoinc(void)
break; break;
case AUTOINC_NEW_STYLE_LOCKING: case AUTOINC_NEW_STYLE_LOCKING:
/* For simple (single/multi) row INSERTs, we fallback to the /* For simple (single/multi) row INSERTs/REPLACEs and RBR
old style only if another transaction has already acquired events, we fallback to the old style only if another
the AUTOINC lock on behalf of a LOAD FILE or INSERT ... SELECT transaction has already acquired the AUTOINC lock on
etc. type of statement. */ behalf of a LOAD FILE or INSERT ... SELECT etc. type of
statement. */
if (thd_sql_command(user_thd) == SQLCOM_INSERT if (thd_sql_command(user_thd) == SQLCOM_INSERT
|| thd_sql_command(user_thd) == SQLCOM_REPLACE) { || thd_sql_command(user_thd) == SQLCOM_REPLACE
|| thd_sql_command(user_thd) == SQLCOM_END // RBR event
) {
dict_table_t* table = prebuilt->table; dict_table_t* table = prebuilt->table;
/* Acquire the AUTOINC mutex. */ /* Acquire the AUTOINC mutex. */
...@@ -5118,9 +5121,11 @@ ha_innobase::innobase_lock_autoinc(void) ...@@ -5118,9 +5121,11 @@ ha_innobase::innobase_lock_autoinc(void)
/* We need to check that another transaction isn't /* We need to check that another transaction isn't
already holding the AUTOINC lock on the table. */ already holding the AUTOINC lock on the table. */
if (table->n_waiting_or_granted_auto_inc_locks) { if (table->n_waiting_or_granted_auto_inc_locks) {
/* Release the mutex to avoid deadlocks. */ /* Release the mutex to avoid deadlocks and
fall back to old style locking. */
dict_table_autoinc_unlock(table); dict_table_autoinc_unlock(table);
} else { } else {
/* Do not fall back to old style locking. */
break; break;
} }
} }
......
...@@ -6064,12 +6064,15 @@ ha_innobase::innobase_lock_autoinc(void) ...@@ -6064,12 +6064,15 @@ ha_innobase::innobase_lock_autoinc(void)
break; break;
case AUTOINC_NEW_STYLE_LOCKING: case AUTOINC_NEW_STYLE_LOCKING:
/* For simple (single/multi) row INSERTs, we fallback to the /* For simple (single/multi) row INSERTs/REPLACEs and RBR
old style only if another transaction has already acquired events, we fallback to the old style only if another
the AUTOINC lock on behalf of a LOAD FILE or INSERT ... SELECT transaction has already acquired the AUTOINC lock on
etc. type of statement. */ behalf of a LOAD FILE or INSERT ... SELECT etc. type of
statement. */
if (thd_sql_command(user_thd) == SQLCOM_INSERT if (thd_sql_command(user_thd) == SQLCOM_INSERT
|| thd_sql_command(user_thd) == SQLCOM_REPLACE) { || thd_sql_command(user_thd) == SQLCOM_REPLACE
|| thd_sql_command(user_thd) == SQLCOM_END // RBR event
) {
dict_table_t* table = prebuilt->table; dict_table_t* table = prebuilt->table;
/* Acquire the AUTOINC mutex. */ /* Acquire the AUTOINC mutex. */
...@@ -6078,9 +6081,11 @@ ha_innobase::innobase_lock_autoinc(void) ...@@ -6078,9 +6081,11 @@ ha_innobase::innobase_lock_autoinc(void)
/* We need to check that another transaction isn't /* We need to check that another transaction isn't
already holding the AUTOINC lock on the table. */ already holding the AUTOINC lock on the table. */
if (table->n_waiting_or_granted_auto_inc_locks) { if (table->n_waiting_or_granted_auto_inc_locks) {
/* Release the mutex to avoid deadlocks. */ /* Release the mutex to avoid deadlocks and
fall back to old style locking. */
dict_table_autoinc_unlock(table); dict_table_autoinc_unlock(table);
} else { } else {
/* Do not fall back to old style locking. */
break; break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment