index.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <html> <head>
  2. <title>Two Locking War Stories</title>
  3. <style>
  4. body {
  5. background-color: #dac8c0;
  6. }
  7. .slide {
  8. font-family: Big Caslon;
  9. border: 2px solid #887777;
  10. background-color: #e7e3e0;
  11. padding: 2%;
  12. width: 94%;
  13. }
  14. h1 {
  15. text-align: center;
  16. }
  17. h2 {
  18. text-align: center;
  19. }
  20. h3 {
  21. text-align: center;
  22. }
  23. pre {
  24. border: 1px solid #664444;
  25. background-color: #fff8ea;
  26. padding: 2px;
  27. }
  28. .credit {
  29. padding: 2px;
  30. font-size: -2;
  31. text-align: right;
  32. vertical-align: bottom;
  33. }
  34. </style>
  35. <script src="scripts/jquery-1.2.3.js" type="text/javascript"></script>
  36. <script src="scripts/slideshow.js" type="text/javascript"></script>
  37. </head>
  38. <body>
  39. <div class='slide'>
  40. <h1>Two War Stories</h1>
  41. <h3>(in which Locking appears as a primary antagonist)</h3>
  42. <div><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></div>
  43. <div class="credit">John Melesky<br/>
  44. (PDX PUG, February 2012)</div>
  45. </div>
  46. <div class='slide'>
  47. <h1>Imagine, if you will...</h1>
  48. </div>
  49. <div class='slide'>
  50. <h1>The log</h1>
  51. <pre><code>SELECT * FROM definition_table WHERE defname='foobarbaz' FOR SHARE;
  52. SELECT * FROM definition_table WHERE defname='foobarbaz' FOR SHARE;
  53. SELECT * FROM definition_table WHERE defname='foobarbaz' FOR SHARE;
  54. SELECT * FROM definition_table WHERE defname='foobarbaz' FOR SHARE;
  55. SELECT * FROM definition_table WHERE defname='foobarbaz' FOR SHARE;
  56. </code></pre>
  57. </div>
  58. <div class='slide'>
  59. <h1>The problem</h1>
  60. </div>
  61. <div class='slide'>
  62. <h1>The problem</h1>
  63. <ul>
  64. <li>Even read-only locks need to write</li>
  65. </ul>
  66. </div>
  67. <div class='slide'>
  68. <h1>The problem</h1>
  69. <ul>
  70. <li>Even read-only locks need to write</li>
  71. <li>That write can have contention</li>
  72. </ul>
  73. </div>
  74. <div class='slide'>
  75. <h1>The solution</h1>
  76. </div>
  77. <div class='slide'>
  78. <h1>The conclusion</h1>
  79. </div>
  80. <div class='slide'>
  81. <h1>The conclusion</h1>
  82. <ul>
  83. <li>Concurrency is baaad, mmkay?</li>
  84. </ul>
  85. </div>
  86. <div class='slide'>
  87. <h1>The conclusion</h1>
  88. <ul>
  89. <li>Concurrency is baaad, mmkay?</li>
  90. <li>MySQL had it right all along</li>
  91. </ul>
  92. </div>
  93. <div class='slide'>
  94. <h1>Questions?</h1>
  95. </div>
  96. <div class='slide'>
  97. <h1>Now, imagine....</h1>
  98. </div>
  99. <div class='slide'>
  100. <h1>Egads! Deadlocks?</h1>
  101. </div>
  102. <div class='slide'>
  103. <h1>The culprit(s)</h1>
  104. <pre><code>SELECT * FROM sum_table WHERE sum_id = 1234
  105. AND sum_date BETWEEN '2011-01-01' AND '2011-01-10' FOR UPDATE;
  106. SELECT * FROM sum_table WHERE sum_id = 1234
  107. AND sum_date BETWEEN '2011-01-03' AND '2011-01-13' FOR UPDATE;
  108. </code></pre>
  109. </div>
  110. <div class='slide'>
  111. <h1>The problem</h1>
  112. </div>
  113. <div class='slide'>
  114. <h1>The problem</h1>
  115. <ul>
  116. <li>Lock acquisition is atomic</li>
  117. </ul>
  118. </div>
  119. <div class='slide'>
  120. <h1>The problem</h1>
  121. <ul>
  122. <li>Lock acquisition is only atomic per-lock</li>
  123. </ul>
  124. </div>
  125. <div class='slide'>
  126. <h1>The problem</h1>
  127. <ul>
  128. <li>Lock acquisition is only atomic per-lock</li>
  129. <li>Locks need to be acquired in a stable order</li>
  130. </ul>
  131. </div>
  132. <div class='slide'>
  133. <h1>The solution</h1>
  134. </div>
  135. <div class='slide'>
  136. <h1>The real problem</h1>
  137. </div>
  138. <div class='slide'>
  139. <h1>The real problem</h1>
  140. <pre><code>UPDATE sum_table SET last_update = now()
  141. WHERE sum_id = 1234
  142. AND sum_date BETWEEN '2011-01-01' and '2011-01-10';
  143. </code></pre>
  144. </div>
  145. <div class='slide'>
  146. <h1>The real solution</h1>
  147. </div>
  148. <div class='slide'>
  149. <h1>The real solution</h1>
  150. <pre><code>UPDATE sum_table SET last_update = now()
  151. WHERE sum_id = 1234
  152. AND sum_date BETWEEN '2011-01-01' and '2011-01-10'
  153. ORDER BY sum_id, sum_date;
  154. </code></pre>
  155. </div>
  156. <div class='slide'>
  157. <h1>The conclusion</h1>
  158. </div>
  159. <div class='slide'>
  160. <h1>The conclusion</h1>
  161. <ul>
  162. <li>Transactional atomicity is not the same as being deadlock-proof</li>
  163. </ul>
  164. </div>
  165. <div class='slide'>
  166. <h1>The conclusion</h1>
  167. <ul>
  168. <li>Transactional atomicity is not the same as being deadlock-proof</li>
  169. <li>MySQL had it right all along</li>
  170. </ul>
  171. </div>
  172. <div class='slide'>
  173. <h1>The conclusion</h1>
  174. <ul>
  175. <li>Transactional atomicity is not the same as being deadlock-proof</li>
  176. <li><a href="http://dev.mysql.com/doc/refman/5.5/en/update.html">MySQL had it right all along</a></li>
  177. </ul>
  178. </div>
  179. <div class='slide'>
  180. <h1>The MySQL way</h1>
  181. <pre><code>UPDATE t SET id = id + 1;
  182. </code></pre>
  183. </div>
  184. <div class='slide'>
  185. <h1>The MySQL way</h1>
  186. <pre><code>UPDATE t SET id = id + 1 ORDER BY id DESC;
  187. </code></pre>
  188. </div>
  189. <div class='slide'>
  190. <h1>Questions?</h1>
  191. </div>
  192. <div class='slide'>
  193. <h1>Thank you!</h1>
  194. </div>
  195. </body></html>