怎么理解mysql特性semiconsistentread-創(chuàng)新互聯(lián)

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

我們擁有十余年網(wǎng)頁設(shè)計和網(wǎng)站建設(shè)經(jīng)驗,從網(wǎng)站策劃到網(wǎng)站制作,我們的網(wǎng)頁設(shè)計師為您提供的解決方案。為企業(yè)提供網(wǎng)站制作、成都網(wǎng)站設(shè)計、微信開發(fā)、微信小程序、移動網(wǎng)站建設(shè)、成都h5網(wǎng)站建設(shè)、等業(yè)務(wù)。無論您有什么樣的網(wǎng)站設(shè)計或者設(shè)計方案要求,我們都將富于創(chuàng)造性的提供專業(yè)設(shè)計服務(wù)并滿足您的需求。

先看看官方的說法:
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.


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


semi-consistent read只會發(fā)生在read committed隔離級別或以下,或者是參數(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,不會阻塞。如果先執(zhí)行UPDATE,后執(zhí)行其他非UPDATE SQL,則還是會加鎖
3、只影響有實際存在的行,不存在的行也OK
 

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

同理:如果列是有索引存在的.innodb會自動產(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í)后,相信大家對怎么理解mysql特性semi consistent read這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

名稱欄目:怎么理解mysql特性semiconsistentread-創(chuàng)新互聯(lián)
當(dāng)前網(wǎng)址:http://bm7419.com/article28/gdscp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、ChatGPT、網(wǎng)站改版、響應(yīng)式網(wǎng)站、App開發(fā)、標簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)