溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么理解mysql特性semi consistent read

發(fā)布時(shí)間:2021-11-18 16:21:18 來源:億速云 閱讀:227 作者:iii 欄目:MySQL數(shù)據(jù)庫

這篇文章主要講解了“怎么理解mysql特性semi consistent read”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么理解mysql特性semi consistent read”吧!

先看看官方的說法:
semi consistent read

A type of read operation used for UPDATE statements, that is a combination of read committed and consistent read. When an UPDATE statement examines a row that is already locked, InnoDB returns the latest committed version to MySQL so that MySQL can determine whether the row matches the WHERE condition of the UPDATE. If the row matches (must be updated), MySQL reads the row again, and this time InnoDB either locks it or waits for a lock on it. This type of read operation can only happen when the transaction has the read committed isolation level, or when the innodb_locks_unsafe_for_binlog option is enabled.


簡(jiǎn)單來說,semi-consistent read是read committed與consistent read兩者的結(jié)合。一個(gè)update語句,如果讀到一行已經(jīng)加鎖的記錄,此時(shí)InnoDB返回記錄最近提交的版本,由MySQL上層判斷此版本是否滿足update的where條件。若滿足(需要更新),則MySQL會(huì)重新發(fā)起一次讀操作,此時(shí)會(huì)讀取行的最新版本(并加鎖)。


semi-consistent read只會(huì)發(fā)生在read committed隔離級(jí)別或以下,或者是參數(shù)innodb_locks_unsafe_for_binlog被設(shè)置為true。


semi consistent read作用情形:
1、RC、RU模式下,或者 innodb_locks_unsafe_for_binlog = 1
2、先執(zhí)行非UPDATE SQL,后執(zhí)行UPDATE,不會(huì)阻塞。如果先執(zhí)行UPDATE,后執(zhí)行其他非UPDATE SQL,則還是會(huì)加鎖
3、只影響有實(shí)際存在的行,不存在的行也OK
 

我的理解:
在rc級(jí)別或以下級(jí)別(ru),或者 innodb_locks_unsafe_for_binlog = 1(RR) 這三種情況下,會(huì)發(fā)生semi_consistent_read.
因?yàn)閕nnodb是行級(jí)鎖,如果字段沒有索引,在加鎖時(shí),會(huì)上升為表鎖.此時(shí),如果s1執(zhí)行加鎖任何操作,s2執(zhí)行update操作,在s2的update條件中如果在s1中沒有行鎖,將不會(huì)堵塞s2.原理是:s2發(fā)起的update,有mysql上層根據(jù)update條件判斷是否滿足,若條件中沒有行鎖,則mysql會(huì)重新發(fā)起一次讀操作,并在update后加鎖;

同理:如果列是有索引存在的.innodb會(huì)自動(dòng)產(chǎn)生的是行鎖,所以semi_consistent_read的效能也就沒有什么意義..
所以.semi_consistent_read只發(fā)生在沒有索引的列,或者有全表鎖的情況;只要存在update的數(shù)據(jù)上有行鎖的,semi_consistent_read就失效;

感謝各位的閱讀,以上就是“怎么理解mysql特性semi consistent read”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)怎么理解mysql特性semi consistent read這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI