MySQL slave 延遲一列 外鍵檢查和自增加鎖
MySQL slave 延遲 外鍵檢查和自增加鎖
一、現(xiàn)象
延遲大,大事物。
- 表結(jié)構(gòu)

- 無IO

- SQL THREAD占用CPU 100%

二、pscak 采樣
采樣30個(gè)點(diǎn)
- 外鍵檢查 占70%

- 自增鎖獲取 占30%

三、自增鎖獲取邏輯
邏輯如下其實(shí)也是innodb_autoinc_lock_mode參數(shù)的作用
switch (lock_mode) {
case AUTOINC_NO_LOCKING://innodb_autoinc_lock_mode=2
/* Acquire only the AUTOINC mutex. */
dict_table_autoinc_lock(m_prebuilt->table);
break;
case AUTOINC_NEW_STYLE_LOCKING: // innodb_autoinc_lock_mode=1 注意這里沒有break 巧妙的完成了邏輯
/* For simple (single/multi) row INSERTs, we fallback to the
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 (thd_sql_command(m_user_thd) == SQLCOM_INSERT
|| thd_sql_command(m_user_thd) == SQLCOM_REPLACE) {
dict_table_t* ib_table = m_prebuilt->table;
/* Acquire the AUTOINC mutex. */
dict_table_autoinc_lock(ib_table);
/* We need to check that another transaction isn't
already holding the AUTOINC lock on the table. */
if (ib_table->n_waiting_or_granted_auto_inc_locks) {
/* Release the mutex to avoid deadlocks. */
dict_table_autoinc_unlock(ib_table);
} else {
break;
}
}
/* Fall through to old style locking. */
case AUTOINC_OLD_STYLE_LOCKING://innodb_autoinc_lock_mode=0 觸發(fā)
DBUG_EXECUTE_IF("die_if_autoinc_old_lock_style_used",
ut_ad(0););
error = row_lock_table_autoinc_for_mysql(m_prebuilt); //這個(gè)函數(shù)上表上的自增鎖
if (error == DB_SUCCESS) {
/* Acquire the AUTOINC mutex. */
dict_table_autoinc_lock(m_prebuilt->table);
}
break;
default:
ut_error;
}
binlog row格式,innodb_autoinc_lock_mode=1 按理說不會(huì)觸發(fā)row_lock_table_autoinc_for_mysql加自增鎖。不知道什么原因。當(dāng)前知道:
- 如果主庫語句模式,從庫innodb_autoinc_lock_mode=1 ,insert select 肯定會(huì)觸發(fā)。
- 如果從庫 innodb_autoinc_lock_mode=0 肯定會(huì)觸發(fā)。
但是都不滿足。疑惑。
四、方案
刪除外鍵
innodb_autoinc_lock_mode設(shè)置為2,從邏輯來看肯定不會(huì)做row_lock_table_autoinc_for_mysql了。
到此這篇關(guān)于MySQL slave 延遲一列 外鍵檢查和自增加鎖的文章就介紹到這了,更多相關(guān)MySQL slave 延遲 外鍵檢查和自增加鎖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SQL Server中調(diào)用C#類中的方法實(shí)例(使用.NET程序集)
這篇文章主要介紹了SQL Server中調(diào)用C#類中的方法實(shí)例(使用.NET程序集),本文實(shí)現(xiàn)了在SQL Server中調(diào)用C#寫的類及方法,需要的朋友可以參考下2014-10-10
SqlServer數(shù)據(jù)庫全角轉(zhuǎn)換成半角
SqlServer數(shù)據(jù)庫全角轉(zhuǎn)換成半角,需要的朋友可以參考一下2013-03-03
sql查詢結(jié)果列拼接成逗號(hào)分隔的字符串方法
SQL查詢時(shí)會(huì)經(jīng)常需要,把查詢的結(jié)果拼接成一個(gè)字符串。那么怎么直接把sql查詢結(jié)果列拼接成逗號(hào)分隔的字符串方法,下面就一起來了解一下2021-05-05
SSMS中出現(xiàn)兩個(gè)相同的服務(wù)器名稱的問題解決
在SSMS的【連接到服務(wù)器】頁面,有時(shí)候可能會(huì)出現(xiàn)多個(gè)相同的服務(wù)器名稱本文主要介紹了SSMS中出現(xiàn)兩個(gè)相同的服務(wù)器名稱的問題解決,感興趣的可以了解一下2024-05-05
探討Sql Server中的declare基本知識(shí)
這篇文章主要探討Sql Server中的declare基本知識(shí),實(shí)戰(zhàn)探討主要來源于觸發(fā)器的Demo,本文給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-07-07
sqlserver 中ntext字段的批量替換(updatetext的用法)
在Sql Server 中,ntext/text/image 字段不允許應(yīng)用replace函數(shù)替換內(nèi)容2009-09-09
如何監(jiān)測和優(yōu)化OLAP數(shù)據(jù)庫
微軟SQL Server分析服務(wù)(SSAS)提供了一個(gè)用來創(chuàng)建和管理數(shù)據(jù)挖掘應(yīng)用和在線分析處理系統(tǒng)的強(qiáng)大引擎,你應(yīng)該仔細(xì)的監(jiān)測和優(yōu)化OLAP數(shù)據(jù)庫和潛在的關(guān)系數(shù)據(jù)源。2015-09-09

