From e648b0bf22562d62e12184b0b8620fb6b96c0d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Wed, 4 Mar 2015 15:28:22 +0200 Subject: 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_slave_thread(user_thd) and thd_sql_command(user_thd) == SQLCOM_END. --- storage/innobase/handler/ha_innodb.cc | 8 +++++++- storage/xtradb/handler/ha_innodb.cc | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 3941de9e205..4415ce66683 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -6785,8 +6785,12 @@ ha_innobase::innobase_lock_autoinc(void) old style only if another transaction has already acquired the AUTOINC lock on behalf of a LOAD FILE or INSERT ... SELECT etc. type of statement. */ + + /* If this is (single/multi) row INSERTs/REPLACEs, or + slave thread executing Write_rows_log_event */ if (thd_sql_command(user_thd) == SQLCOM_INSERT - || thd_sql_command(user_thd) == SQLCOM_REPLACE) { + || thd_sql_command(user_thd) == SQLCOM_REPLACE + || (thd_slave_thread(user_thd) && thd_sql_command(user_thd) == SQLCOM_END)) { dict_table_t* ib_table = prebuilt->table; /* Acquire the AUTOINC mutex. */ @@ -6798,6 +6802,8 @@ ha_innobase::innobase_lock_autoinc(void) /* Release the mutex to avoid deadlocks. */ dict_table_autoinc_unlock(ib_table); } else { + /* Do not fall back to old style autoinc + locking */ break; } } diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index 078795786fc..4a6a6a01357 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -7342,8 +7342,12 @@ ha_innobase::innobase_lock_autoinc(void) old style only if another transaction has already acquired the AUTOINC lock on behalf of a LOAD FILE or INSERT ... SELECT etc. type of statement. */ + + /* If this is (single/multi) row INSERTs/REPLACEs, or + slave thread executing Write_rows_log_event */ if (thd_sql_command(user_thd) == SQLCOM_INSERT - || thd_sql_command(user_thd) == SQLCOM_REPLACE) { + || thd_sql_command(user_thd) == SQLCOM_REPLACE + || (thd_slave_thread(user_thd) && thd_sql_command(user_thd) == SQLCOM_END)) { dict_table_t* ib_table = prebuilt->table; /* Acquire the AUTOINC mutex. */ @@ -7355,6 +7359,8 @@ ha_innobase::innobase_lock_autoinc(void) /* Release the mutex to avoid deadlocks. */ dict_table_autoinc_unlock(ib_table); } else { + /* Do not fall back to old style autoinc + locking */ break; } } -- cgit v1.2.1