You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
本日は、MySQL Casual Advent Calendar 2013の20日目である。というわけでカジュアルに小ネタを紹介しよう。 MVCC - Multi Version Concurrency Controlご存知の通り、InnoDBはMVCCを実装している。そのため、分離レベルがREPEATABLE READの場合には、行にロックをかけることなく、一貫した読み取りが可能になっている。 もし、あるトランザクションT1開始後に、別のトランザクションT2によって同じ行が書き換えられてしまった場合には、T1はロールバックセグメントにある古いバージョンの値を読み取ることができるので、T1内で実行したSELECTは常にT1開始時点のデータを参照することができるのである。大事なのでもう一度言うが、REPEATABLE READにおける単純なSELECTでは行ロックは必要ない。 Lost Up
MySQLのロックについて JPOUG> SET EVENTS 20140907 2014/09/07 平塚 貞夫 1 Revision 2 自己紹介 • DBエンジニアをやっています。専門はOracle DatabaseとMySQL。 • オープンソースソフトウェアの導入支援をしています。 • 仕事の割合はOracle:MySQL:PostgreSQL=1:2:7くらいです。 • Twitter:@sh2nd • はてな:sh2 • • 写真は実家で飼っているミニチュアダックスのオス、アトムです。 2 本日のお題 3 想定外のデッドロック • MySQLのInnoDBストレージエンジンに対して、2つのトランザクション を以下の順番で実行するとデッドロックが発生します。 • このデッドロックの発生メカニズムを理解するために、InnoDBのロック アーキテクチャについて確認していきます。 4
デフォルトの isolation level (トランザクション分離レベル) はREAD COMMITTEDに変更するべき 内部が不透明な既存アプリケーションを変更する場合等、クリティカルな場合を除いて、InnoDBを利用する場合はデフォルトのisolation levelをREAD COMMITTEDに変更するべきである。 根拠は MySQL (InnoDB) でデッドロック検知される条件について - QA@IT ここに解説がある。 Railsでは、 以下のページに書いてあるようなモンキーパッチでデフォルト設定の変更が可能である。 Rails 4では、トランザクションにオプションを渡すことでも変更が可能である。或いは、my.cnfで設定することも可能である。しかし、これはDBレベルの話ではなくアプリケーションレイヤーの話なので、アプリケーション側で修正するのが望ましいと僕は思う。 参照:
メモ開放。InnoDBの行ロック関連について、それぞれの項目が必ずしも並列関係にあるわけではないが、以下のようにまとめていく。 排他ロックと共有ロック SELECT ~ FOR UPDATE SELECT ~ LOCK IN SHARE MODE 排他ロックと共有ロック 読み取りを許すかどうかの違い。排他ロックは対象行を全てのクエリからロックするため、UPDATEやDELETEなどの更新クエリはもちろん、SELECTなどの読み取りクエリも通さない。共有ロックは更新クエリを通さないが、読み取りクエリは通す。 (追記:排他ロックは分離レベルによってはSELECTを通すとのこと。 公式 ) 排他ロックは全てのクエリを通さず、共有ロックは排他ロックを伴うクエリを通さない、と言い換えたほうがいいかもしれない。 公式では共有ロックは同トランザクション内のselectを許し、排他ロックは同トランザクショ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く